Copy Code code as follows:
Import java.awt.event.WindowEvent;
Import Java.awt.event.WindowStateListener;
Import Javax.swing.JFrame;
public class WinFrame extends JFrame {
Public WinFrame () {
This.setname ("window state");
This.setsize (300,300);
This.setdefaultcloseoperation (Jframe.exit_on_close);
This.addwindowstatelistener (New Windowstatelistener () {
public void windowstatechanged (WindowEvent state) {
if (state.getnewstate () = 1 | | state.getnewstate () = 7) {
System.out.println ("window minimized");
}else if (state.getnewstate () = 0) {
System.out.println ("window back to initial state");
}else if (state.getnewstate () = 6) {
System.out.println ("Window maximization");
}
}
});
This.setvisible (TRUE);
}
public static void Main (string[] args) {
New WinFrame ();
}
}
Another small example of creating a form using JFrame
Windows created with JFrame contain a title, a minimized button, a Maximize button, and a close button
Copy Code code as follows:
public class Test () {
public static void Main (string[] args) {
JFrame frame = new JFrame ();
JPanel panel = new JPanel ();
JTextArea TextArea = new JTextArea ();
Panel.setlayout (New GridLayout ());
Textarea.settext ("test");
Generate scroll bars when content in textarea is too long
Panel.add (New JScrollPane (TextArea));
Frame.add (panel);
Frame.setsize (200,200);
Frame.setvisible (TRUE);
}
}