import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class mahi1 implements ActionListener
{
JFrame f;
Label l1,l2;
JButton b1,b2,b3;
Panel p;
mahi1()
{
f=new JFrame("MaHi");
f.setSize(400,400);
f.setLayout(new GridLayout(3, 1));
f.setVisible(true);
l1=new Label();
l1.setText("Press Any Key");
l1.setAlignment(l1.CENTER);
f.add(l1);
p = new Panel();
p.setLayout(new FlowLayout());
b1=new JButton("Ok");
b2=new JButton("Submit");
b3=new JButton("Cancel");
b1.setActionCommand("OK");
b2.setActionCommand("Submit");
b3.setActionCommand("Cancel");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
p.add(b1);
p.add(b2);
p.add(b3);
f.add(p);
l2 = new Label();
l2.setAlignment(Label.CENTER);
l2.setSize(350,100);
f.add(l2);
}
public void actionPerformed(ActionEvent e)
{
String command = e.getActionCommand();
if( command.equals( "OK" ))
{
l2.setText("Ok Button clicked.");
}
else if( command.equals( "Submit" ) )
{
l2.setText("Submit Button clicked.");
}
else
{
l2.setText("Cancel Button clicked.");
}
}
public static void main(String surat[])
{
new mahi1();
}
}
Output:
No comments:
Post a Comment