import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MouseListenerDemo {
public static void main(String[] args) {
final JFrame frame = new JFrame("Demo");
JLabel label = new JLabel("Click anywhere");
Container c = frame.getContentPane();
c.setLayout(new FlowLayout());
c.add(label);
c.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
JOptionPane.showMessageDialog(frame, "You clicked me!");
}
});
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
> Could someone help me write the code for the
> following simple command? I still have no clue how to
> do it after reading some tutorials
>
> When a person clicks the mouse, initiate this method
There are plenty samples of this code out there, and we could write more, but to what purpose? The bigger question and the one you need to clarify is this: Exactly what part of the mouseListener code samples confuse you?