Windows and frames are containers that can be displayed in the user interface and accommodate other components, each using the JWindow and JFrame classes in swing to create
Windows : A simple container, unlike regular graphical user interfaces, with headings and buttons at the top;
Framework : Contains all the common window features that users want to see when they run the software, such as the Close button, maximize and Minimize buttons, and so on.
When you create a frame, you must do several things in the box-cut constructor:
1. Call the constructor of the parent class JFrame;
---super ();
2. Set the title of the frame;
---super ("title") or Settitle ("title");
3. Set the frame size;
---setSize (350, 125);
4. Set the appearance of the frame;
---call the Uimanager.setlookandfeel () method
--set Nimbus to appearance uimanager.setlookandfeel ("Com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
5. Define what actions should be taken when a user closes a frame
---setdefaultcloseoperation (jframe.exit_on_close); Exit program when Button is clicked
---setdefaultcloseoperation (jframe.dispose_on_close), close the frame and destroy the frame object, but the application continues to run
---setdefaultcloseoperation (jframe.do_nothing_on_close); Let the frame open and continue running
---setdefaultcloseoperation (jframe.hide_on_close), close the frame and continue running
6. Display Frame
---setvisible (true);
Demo:
1 PackageCom.swingdemo.demo;2 3 ImportJavax.swing.JFrame;4 ImportJavax.swing.UIManager;5 6 Public classSalutonframeextendsJFrame {7 8 Private Static Final LongSerialversionuid = 1L;9 Ten PublicSalutonframe () { One A Super("Saluton mondo!"); - Setlookandfeel (); -SetSize (350, 100); the setdefaultcloseoperation (jframe.exit_on_close); -SetVisible (true); - - } + - /** + * Specify Nimbus as the appearance of the frame A * Uimanager.setlookandfeel () method to set the appearance of the GUI at */ - Private voidSetlookandfeel () { - - Try{ -Uimanager.setlookandfeel ("Com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); -}Catch(Exception e) { in e.printstacktrace (); - } to + } - the Public Static voidMain (string[] args) { * $Salutonframe sal =Newsalutonframe ();Panax Notoginseng - } the +}
View Code
Windows and frames for the Java user interface