Saturday, 26 May 2012

GUI Example in JAVA


import javax.swing.*;


public class Ass139 extends JFrame implements ActionListener
{
JLabel l1;
JButton b1,b2,b3;
JTextField t1;

Ass139()
{
l1=new JLabel("OUTPUT");
b1=new JButton("BUTTON 1");
b2=new JButton("BUTTON 2");
b3=new JButton("BUTTON 3");
t1=new JTextField(10);

add(l1);
add(t1);
add(b1);
add(b2);
add(b3);

b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);

setSize(200,200);
setLayout(new FlowLayout());
setTitle("Assignment 139");
}

public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
{
t1.setText("Button 1 is pressed");

}
if(ae.getSource()==b2)
{
t1.setText("Button 2 is pressed");

}
if(ae.getSource()==b3)
{
t1.setText("Button 3 is pressed");

}

}

public static void main(String args[])
{
Ass139 a=new Ass139();
a.setVisible(true);
a.setLocation(200,200);

}

}

1 comment:

  1. I have read your blog its very attractive and impressive. I like it your blog.

    Java Online Training Java EE Online Training Java EE Online Training Java 8 online training Core Java 8 online training

    Java Online Training from India Java Online Training from India Core Java Training Online Core Java Training Online Java Training InstitutesJava Training Institutes

    ReplyDelete