-
problem on button
if i click majesty button
it should disply 4 more buttons
1)animations 2)visual effects 3)multimedia 4)server based
but not showing
my code is
Code:
import java.io.*;
import java.awt.*;
import java.awt.event.*;
class Demoframe extends Frame implements ActionListener
{
Button b1,b2,b3,b4,cb1,cb2,cb3,ad1,ad2,ad3,m1,m2,m3,m4;
Panel p,p2,p3,p4,p5,p6,p7,p8;
Demoframe(String title)
{
super(title);
p=new Panel();
p2=new Panel();
p3=new Panel();
p4=new Panel();
p5=new Panel();
p6=new Panel();
p7=new Panel();
p8=new Panel();
b1=new Button("Home");
b2=new Button("Courses");
b3=new Button("Exit");
b4=new Button("Login");
cb1=new Button("Majesty");
cb2=new Button("Excellency");
cb3=new Button("Merit");
ad1=new Button("councellor");
ad2=new Button("accountant");
ad3=new Button("Manager");
m2=new Button("Visula effects");
m3=new Button("Multi media");
m1=new Button("Animations");
m4=new Button("Server based technology");
p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
add(p,BorderLayout.NORTH);
b1.addActionListener(this);
b3.addActionListener(this);
b2.addActionListener(this);
b4.addActionListener(this);
setSize(400,400);
setVisible(true);
}
public static void main(String args[])
{
new Demoframe("Hapl 1.0 v");
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
setBackground(Color.white);
p3.removeAll();
p4.removeAll();
}
if(e.getSource()==b2)
{
setBackground(Color.white);
p4.removeAll();
p3.add(cb1);
p3.add(cb2);
p3.add(cb3);
setVisible(true);
add(p3,BorderLayout.SOUTH);
cb1.addActionListener(this);
cb2.addActionListener(this);
cb3.addActionListener(this);
if(e.getSource()==cb1)
{
p3.add(m1);
p3.add(m2);
p3.add(m3);
p3.add(m4);
setVisible(true);
setBackground(Color.white);
m1.addActionListener(this);
m2.addActionListener(this);
m3.addActionListener(this);
add(p3,BorderLayout.SOUTH);
}
}
if(e.getSource()==b3)
{
System.exit(0);
}
if(e.getSource()==b4)
{
setBackground(Color.white);
p4.add(ad1);
p4.add(ad2);
p4.add(ad3);
p3.removeAll();
setVisible(true);
add(p4,BorderLayout.WEST);
ad1.addActionListener(this);
ad2.addActionListener(this);
ad3.addActionListener(this);
}
}
}
-
After you change the contents of a container, you need to tell the container to redo the display of its contents. I think validate() does that.