import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class ButtonActionSample implements ActionListener{
JButton button;
public ButtonActionSample()
{
JFrame frame = new JFrame("Button Sample");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container contentPane = frame.getContentPane();
button = new JButton("Select Me");
button.addActionListener(this);
contentPane.add(button, BorderLayout.SOUTH);
frame.setSize(300, 100);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
if(ae.getSource()==button)
{
JOptionPane.showMessageDialog(null,"Hello this Button");
}
}
public static void main(String args[]) {
ButtonActionSample bas = new ButtonActionSample();
}
}
0 comments: