Studyon Minte9.com
Java SE




Mouse Listener




package testexample; import java.awt.*; import java.awt.event.*; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; public class Test extends JFrame { public static void main(String[] args) { JFrame frame = new Test(); frame.setBounds(200, 200, 300, 200); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.setVisible(true); } public Test() { JLabel label = new JLabel("Hello"); label.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { JOptionPane.showMessageDialog(null, "Label Clicked!"); } // Alerts: Label Clicked! }); JPanel panel = new JPanel(); panel.add(label); setLayout(new FlowLayout()); add(panel); } }
 


http://stackoverflow.com/questions/2668718/java-mouselistener