Studyon Minte9.com
Java SE




Button Listener




package testexample; import java.awt.*; import java.awt.event.*; import javax.swing.*; 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() { JButton startButton = new JButton("Start"); startButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "Button Clicked!"); } }); JPanel panel = new JPanel(); panel.add(startButton); setLayout(new FlowLayout()); add(panel); } }
 


http://stackoverflow.com/questions/7300135/java-action-listener