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