Swing is a Java-designed GUI toolkit

Source: Internet
Author: User

Swing is a GUI toolkit designed for Java.

Swing is part of the Java Foundation Class.

Swing includes graphical user interface (GUI) devices such as text boxes, buttons, splitter panes, and tables.

Swing offers many better screen display elements than AWT. They are written in plain Java, so they can run across platforms as well as Java itself, unlike AWT.

They are part of the JFC.

They support replaceable panels and themes (specific themes that are the default for various operating systems), but instead of actually using the devices provided by the native platform, they mimic them only on the surface.

This means that you can use any panel supported by Java on any platform.

The disadvantage of lightweight components is that execution is slow, and the advantage is that uniform behavior can be applied across all platforms.

1  Packagecom.myswing;2 ImportJavax.swing.JButton;3 ImportJavax.swing.JFrame;4 ImportJavax.swing.JLabel;5 ImportJavax.swing.JPanel;6 ImportJavax.swing.JPasswordField;7 ImportJavax.swing.JTextField;8  Public classtwoswing {9       Public Static voidMain (string[] args) {Ten             //Creating an JFrame instance OneJFrame frame =NewJFrame ("Login Example"); A             //Setting the width and height of frame -Frame.setsize (350, 200); - frame.setdefaultcloseoperation (jframe.exit_on_close); the  -             /*Create a panel, a div tag similar to HTML - * We can create multiple panels and specify locations in JFrame - * We can add text fields, buttons and other components in the panel.  +              */ -JPanel Panel =NewJPanel ();  +             //Add Panel A Frame.add (panel); at             /*  - * Call user-defined methods and add components to the panel -              */ - placecomponents (panel); -  -             //The settings interface is visible inFrame.setvisible (true); -         } to  +      Private Static voidplacecomponents (JPanel panel) { -  the             /*Layout section We don't have much to introduce here. * * This way set the layout to null $              */Panax NotoginsengPanel.setlayout (NULL); -  the             //Create JLabel +JLabel Userlabel =NewJLabel ("User:"); A             /*This method defines the location of the component.  the * SetBounds (x, y, width, height) + * x and y specify a new position in the upper-left corner, and the new size is specified by width and height.  -              */ $Userlabel.setbounds (10,20,80,25); $ Panel.add (Userlabel); -  -             /*  the * Create text fields for user input -              */WuyiJTextField Usertext =NewJTextField (20); theUsertext.setbounds (100,20,165,25); - Panel.add (usertext); Wu  -             //Enter a text field for the password AboutJLabel Passwordlabel =NewJLabel ("Password:"); $Passwordlabel.setbounds (10,50,80,25); - Panel.add (Passwordlabel); -  -             /*  A * This is similar to the text field for input + * But the information entered is replaced with a dot, which is used to contain the security of the password the              */ -JPasswordField Passwordtext =NewJPasswordField (20); $Passwordtext.setbounds (100,50,165,25); the Panel.add (passwordtext); the  the             //Create Login button theJButton Loginbutton =NewJButton ("Login"); -Loginbutton.setbounds (10, 80, 80, 25); in Panel.add (Loginbutton); the         } the}

Swing is a Java-designed GUI toolkit

Related Article

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.