Login dialog box (form program)--java Basics

Source: Internet
Author: User

1, the use of the JFrame (frame) class object (Here JFrame class object is a frame) methods are:Frame.add (); Add components to frame frameframe.setvisible (); Sets whether the frame is visibleframe.setlayout (); Set the frame layout type, which is the flow layout type by defaultFrame.pack (); Determine the optimal frame size based on the layout of the window and the Preferedsize (priority size) of the component2. The TextField (text field) class object used is: (PW is set to the object of the TextField class)Pw.setechochar (' * '); hides the input password content, only the number of digits of the input password is visible3, the code is as follows:
1  Packagecn.nxl123.www;2 3 Importjava.awt.GridLayout;4 ImportJava.awt.TextField;5 6 ImportJavax.swing.JButton;7 ImportJavax.swing.JFrame;8 ImportJavax.swing.JLabel;9 Ten  Public classLogindialog { One      Public Static voidMain (string[] args) { AJFrame frame=NewJFrame ("Login dialog box");//Set title bar text -TextField id=NewTextField (15);//Set the text field for user name Input -TextField pw=NewTextField (15);//set a text field to enter with a password theJButton loginbutton=NewJButton ("login");//Instantiate button Object Set Login button -JButton cancelbutton=NewJButton ("Cancel");//Instantiate button Object Set Cancel button -Pw.setechochar (' * ');//Hide input Password can only see the number of digits of the input password -Frame.setlayout (NewGridLayout (3,2));//setlayout () method set form layout format +         //here's how to add individual components at once -Frame.add (NewJLabel ("User name:", Jlabel.center)); + Frame.add (ID); AFrame.add (NewJLabel ("Password:", Jlabel.center)); at Frame.add (PW); - Frame.add (Loginbutton); - Frame.add (CancelButton); -Frame.pack ();//frame.pack () The function of this method is to determine the optimal frame size based on the layout of the window and the preferedsize of the component (priority size) . -Frame.setvisible (true);//JFrame is no size, not visible after instantiation. So, to set to true is visible - } in}

Effect Picture:

Disclaimer: Article author original reprint Please specify the source, thank you for your cooperation!

Login dialog box (form program)--java Basics

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.