//B4. NEP Java 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 similar details of mother also appear.
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class FM extends JFrame implements ActionListener
{
// Declaration of object for
JButton class.
JButton b1, b2;
// Constructor of FM class
FM()
{
// Setting layout as null
for JFrame.
this.setLayout(null);
// Initialization of
objects for "JButton" class.
b1 = new
JButton("Father");
b2 = new
JButton("Mother");
// Setting Bounds for
JButtons.
b1.setBounds(100, 05, 80,
50);
b2.setBounds(200, 05, 80,
50);
// Adding JButton on
JFrame.
this.add(b1);
this.add(b2);
// Adding Listener to
JButton.
b1.addActionListener(this);
b2.addActionListener(this);
}
public void
actionPerformed(ActionEvent ae)
{
if (ae.getSource() == b1)
{
// Code To popup
Dialog.
JOptionPane.showMessageDialog(this, "Name of the Father:
abc\nAge:50\nDesignation:Engineer");
}
if(ae.getSource() == b2)
{
// Code To popup
Dialog.
JOptionPane.showMessageDialog(this, "Name of the Mother:
xyz\nAge:48\nDesignation:Lawyer");;
}
}
}
class Progb4
{
public static void main(String
args[])
{
// Creating Object for FM
class.
FM obj = new FM();
// Setting Bounds for a
Frame.
obj.setBounds(200, 200,
400, 300);
// Set Resizable status of
frame as false
obj.setResizable(false);
// Set Visible status of
frame as true.
obj.setVisible(true);
}
}