Windows and frames for the Java user interface

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.