Tuesday 24 June 2014

Program to show Panels and Buttons

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class addingpanelonpanel extends Applet implements ActionListener{
Panel p1,p2;
Button b1,b2;

public void init()
{
setLayout(null);
b1= new Button("open panel 2");
b2= new Button("open panel 1");
b1.setBounds(130,130,160,20);
b2.setBounds(450,130,160,20);
p1=new Panel();
p2=new Panel();
p1.setBounds(120,120,220,120);
p2.setBounds(420,120,220,120);
p1.setBackground(Color.red);
p2.setBackground(Color.PINK);
b1.addActionListener(this);
b2.addActionListener(this);
p1.setVisible(true);
p2.setVisible(false);
add(p1);
add(p2);
p1.add(b1);
p2.add(b2);
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==b1)
{
p2.setVisible(true);
p1.setVisible(false);
}
else
{
p1.setVisible(true);
p2.setVisible(false);
}
}

}

output:

No comments:

Post a Comment

SAY HELLO!!