Faken143
Faken143

Reputation: 219

Call the JFrame from another class

i have simple JFRAME (create by Netbeans) and i want to call frame.setState(Frame.NORMAL) from another class. How to do call?

public class Myclass{

     public void Frame_normal{

       ...?
       ???frame.setState(Frame.NORMAL);

     }

}

Upvotes: 0

Views: 4568

Answers (2)

Marc
Marc

Reputation: 2639

Basicaly you create an attribute in your class and you give it the reference to your JFrame.

 public class Myclass{

      JFrame frame;

      public MyClass(JFrame aFrame){
           this.frame = aFrame;
      }

      public void Frame_normal{


           frame.setState(Frame.NORMAL);

      }

 }

 MyClass class = new Myclass(theJFrame);
 class.Frame_normal();

Upvotes: 3

Aniket Thakur
Aniket Thakur

Reputation: 69035

You can do the following

  1. Create the frame in the class where you want to call setState() function on it.
  2. Create a getter method on that class where you are actually creating the Frame. Then use this getter to get your JFrame and call your method on it.
  3. Make the JFrame public.(Not recommended)

Upvotes: 1

Related Questions