Hello Members,
I have two classes(A and B) which extend from a JPanel. These two JPanels are then added to a JFrame in a third class. I would like the program to be such that when I click a certain button in A, A becomes invisible and B becomes visible and when I click a button in B, B becomes invisible and A becomes visible and so on....back and forth.
Following is the code I tried. The program below works only once for the toggle. After that, the program does not proceed further at all. Kindly let me know of my errors.
Thank you!!
public class A extends JPanel
{
private B hello;
public A()
{
button.addActionListerner (new ActionListener() {
public void actionPeformed(ActionEvent e)
{
setVisible (false);
B.setVisible(true);
}
}
);
}
}
public class B extends JPanel
{
private A hello;
public B()
{
button.addActionListerner (new ActionListener() {
public void actionPeformed(ActionEvent e)
{
setVisible (false);
A.setVisible(true);
}
}
);
}
}