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();
}
}
Friday, 26 January 2018
Related Posts:
Stars in java //import javax.swing.*;public class StarPrint{ public static voi… Read More
Jframe example in java import java.awt.*;import java.awt.event.*;import javax.swing.*;import … Read More
Star .java public class Star{ public static void main(String argu[]){ … Read More
Exceptional handling example in java import java.io.*;public class ExceptionalExample { &n… Read More
0 comments: