Java Example Program / Sample Source Code
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
class DetectClicks {
public static void main(String args[]) {
Frame frame = new Frame("DetectClicks");
Button button1 = new Button("A");
Panel p = new Panel();
p.add(button1);
frame.add(button1, BorderLayout.NORTH);
frame.pack();
frame.setVisible(true);
button1.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
if (evt.getClickCount() == 3) {
// Triple-click
System.out.println("Triple clicks");
} else if (evt.getClickCount() == 2) {
// double-click
System.out.println("double clicks");
}
}
});
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
} |
|
|