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);

}

}

3 comments:

  1. I was recommended this web site by means of my cousin. I am now not certain whether this post is written through him as nobody else recognise such precise about my difficulty. You're amazing! Thank you!
    python interview questions and answers
    python tutorials
    python course institute in electronic city

    ReplyDelete
  2. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
    AWS Training in Bangalore
    AWS training in sholinganallur
    AWS training in Tambaram
    AWS training in Velachery

    ReplyDelete