kkk
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
///////////////////
// FourthJava.java
//
//
// This program shows how to handle
// button events
// button events are handled through
// a. anonymous inner class
// b. by creating a seperate class
//
// javac FourthJava.java
//
// produces FourthJava.class
//
// To execute
// ----------
// java FourthJava
//
//
class Buttoneventhandler implements ActionListener{
public void actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(null, "CLicked me");
}
}
public class FourthJava
{
private JFrame mainFrame;
private JLabel headerLabel;
private JLabel statusLabel;
private JPanel controlPanel;
private JButton submit;
private void prepareGUI(){
mainFrame = new JFrame("Sandeep's Window");
mainFrame.setSize(400,400);
submit = new JButton(" Press Me");
//submit.addActionListener(
// new ActionListener() {
// public void actionPerformed(ActionEvent e)
// {
// JOptionPane.showMessageDialog(mainFrame, "A basic JOptionPane message dialog");
// }
// });
submit.addActionListener(new Buttoneventhandler ());
mainFrame.add(submit);
mainFrame.setVisible(true);
}
public static void main(String[] args){
FourthJava sv = new FourthJava();
sv.prepareGUI();
}
}
No comments:
Post a Comment