The basic idea of Java GUI program is based on JFrame

Source: Internet
Author: User

JFrame The basic idea of –java GUI program is based on JFrame, which is the object of window on screen, which can be maximized, minimized and closed.

JPanel –java Graphical user interface (GUI) Toolkit The Panel container class in swing, included in the Javax.swing package, can be nested, and functionality is a lightweight container that can be added to the JFrame form by combining components that have the same logical functionality in the form.

JLabel –jlabel objects can display text, images, or both. You can specify where the label content is aligned in the label display area by setting vertical and horizontal alignment. By default, labels are centered vertically within their display area. By default, labels that display only text are the start edge alignment, while labels that display only the image are centered horizontally.

JTextField – A lightweight component that allows you to edit a single line of text.

JPasswordField – allows us to enter a line of characters like the input box, but hide the asterisk (*) or point create password (password)

JButton an instance of the –jbutton class. Used to create "Login" in a similar instance of a button.

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}

The basic idea of Java GUI program is based on JFrame

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.