0
votes

I have 2 classes,one of them extends from JPanel and another one extends from JFrame now I add class which extends from JPanel,to other class and I wanna to setVisible of JFrame false from JPanel class,how should I do it?

public class test extends JPanel{
...
}

public class test2 extends JFrame{
   test t;
   public test2(){
   t = new test();
   }
}

I wanna to invisble test2 from test,how should I do it???

1
where is the main method? Are you creating the instance of JFrame class from the JPanel class?Logan
I found the way, set test2 obj into test method,then inivisble itMoein Hosseini
Classnames usually start with a capital: Test, Test2.extraneon

1 Answers

4
votes

You will have to past a refrence of your JFrame to the JPanel so that it can call setVisible(false);.

Although this sounds like a poor design because having each class reference each other is tight coupling and is discouraged. I would suggest having a third "Controller" type class that receives requests from both items and makes changes to the GUI.