I have created a menu. Whenever a menu item is selected, the previous displayed components will be set invisible, and the new components will be set visible.
Suppose I have a menu button called, "Add". It has two menu items---"A Book" and "A CD".
First I selected "A Book", then selected "A CD". Those displays are good. However, when I selected "A Book" again, its components display is in a mess. Why?
The following is part of my code:
=================================
.......
addBook.addActionListener(new AddBookListener(this, c));
addCD.addActionListener(new AddCDListener(this, c));
.......
class AddBookListener implements ActionListener
{
private Exer3 myApplet=null;
private Container myContainer = null;
//Constructor
public AddBookListener(Exer3 app, Container c){
myApplet = app;
myContainer = c;
}
//Define actionPerformed()
public void actionPerformed(ActionEvent e){
//Clear the pane by calling a helper method--invisibleAll()
helperClass help= new helperClass(myApplet);
/*=====Set Invisible======*/
help.setInvisibleForAddCD();
/*=====Set visible========*/
help.setVisibleForAddBook();
//Design the layout of the pane
designLayout();
//Ensures that the Container has a valid layout
myApplet.validate();
....
....
(AddCDListener did the same thing)
}//End of actionPerformed()
.....
.....
class helperClass{
Exer3 myApplet= null;
public helperClass(Exer3 app)
{
myApplet = app;
}
/*===========Set Visible====================*/
public void setVisibleForAddBook()
{
myApplet.lblHead1.setVisible(true);
myApplet.lblCata1.setVisible(true);
......
......
public void setVisibleForAddCD()
{
myApplet.lblHead2.setVisible(true);
myApplet.lblCata2.setVisible(true);
......
......
public void setInvisibleForAddBook()
{
myApplet.lblHead1.setVisible(false);
myApplet.lblCata1.setVisible(false);
......
......
public void setInvisibleForAddCD()
{
myApplet.lblHead2.setVisible(false);
myApplet.lblCata2.setVisible(false);
.....
......
Please help me to solve the problem.
Thank you for your help!