简体   繁体   中英

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);

     }

}

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();

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM