Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

Pgm 6 || Section B || Program which creates a frame with two buttons father and mother. When we click the father button the name of the father, his age and designation must appear. When we click mother button similar details of mother also appear

 import java.awt.*;

import java.awt.event.*;

public class Pgm6 implements ActionListener

{

Label info;

Button b1,b2,b3;

Pgm6()

{

Frame f=new Frame("ActionListener Example");

info=new Label();

info.setBounds(50,50, 250,20);

b1=new Button("Father");

b2=new Button("Mother");

b3=new Button("Exit");

b1.setBounds(50,100,60,30);

b2.setBounds(150,100,60,30);

b3.setBounds(230,100,60,30);

b1.addActionListener(this);

b2.addActionListener(this);

b3.addActionListener(this);

f.add(b1);

f.add(b2);

f.add(b3);


f.add(info);

f.setSize(400,400);

f.setLayout(null);


f.setVisible(true);

}


public void actionPerformed(ActionEvent e)

{

if (e.getSource() == b1)

{

info.setText("Name:ABCD,AGE:60,Design:MANAGER");

}


if (e.getSource() == b2)

{

info.setText("Name:XYZ,AGE:50,Design:House Wife");

}


if (e.getSource() == b3)

{

System.exit(0);

}

}


public static void main(String[] args)

{

new Pgm6();

}


}

Post a Comment

0 Comments