Java study Note 3-Java User Logon Interface

Source: Internet
Author: User

I haven't summarized my study this month for a long time. I am nagging a few words, and this month's work is a mess. Quarrel with the boss and resign. Today is the last three days of submitting a resignation application.

Java users log on to this Part and learn the new classes:

1. Border layout: borderlayout. It is mainly divided into five la S, which are the default layout of jframe (top-level container) and jdialog (class for creating dialog box windows. Its maximum capacity is 5 components, and more than 5 components must be used. The setting method is borderlayout. North; borderlayout. South; borderlayout. Center; borderlayout. Center; borderlayout. Left; borderlayout. Right.

2. Stream layout: flowlayout. The layout is from left to right, from top to bottom. Is the default panel layout of jpanel (lightweight container.

3. grid layout: gridlayout. The layout is a network composed of rows and columns. Layout Method: setlayout (New gridlayout (3,2, 3,3). The strong and double digits indicate three rows and two columns, and the last two digits indicate that the spacing between rows is 3, the spacing between a column and a column is 3.

Then, you can access the jpanel. Jpanel is a non-top-level container. Therefore, a single interface can only be composed of one jframe, but multiple jpanel components can exist. The default Layout mode is streaming layout. In jpanel, I learned the design of the User Logon interface. To access the other three components: Text Box component: jtextfield; Password box component: jpasswordfield; label component: jlabel; check box component: jcheckbox; Single Component: jradiobutton; button component jbutton.

Based on the above components and layout, I tried to do the following:Code:

1. User Logon interface:

The Code is as follows:

1 import javax. swing. *; 2 3 Import Java. AWT. *; // import the necessary package 4 5 public class denglu extends jframe {6 jtextfield; // define the text box component 7 jpasswordfield; // define the Password box component 8 jlabel jlabel1, jlabel2; 9 jpanel jp1, JP2, jp3; 10 jbutton jb1, jb2; // create button 11 Public denglu () {12 jtextfield = new jtextfield (12 ); 13 jpasswordfield = new jpasswordfield (13); 14 jlabel1 = new jlabel ("username"); 15 jlabel2 = new jlabel ("password "); 16 jb1 = new jbutton ("OK"); 17 jb2 = new jbutton ("cancel"); 18 jp1 = new jpanel (); 19 JP2 = new jpanel (); 20 jp3 = new jpanel (); 21 22 // set layout 23 This. setlayout (New gridlayout (3, 1); 24 25 jp1.add (jlabel1); 26 jp1.add (jtextfield); // Add the username and text box 27 28 jp2.add (jlabel2) on the first panel ); 29 jp2.add (jpasswordfield); // on the second panel, add the password and password in the input box 30 31 jp3.add (jb1); 32 jp3.add (jb2 ); // The third panel is added to confirm and cancel 33 34 // jp3.setlayout (New flowlayout (); // you can cancel this code because the default layout of jpanel is flowlayout. 35 This. add (jp1); 36 This. add (JP2); 37 this. add (jp3); // Add the three panels to the login box 38 // set to display 39 This. setsize (300,200); 40 // This. pack (); 41 This. setdefaclocloseoperation (jframe. exit_on_close); 42 this. setvisible (true); 43 this. settitle ("login"); 44 45} 46 public static void main (string [] ARGs) {47 new denglu (); 48} 49}

2. Based on the check box components and other components, the user survey interface is also written:

Code:

1 import javax. swing. buttongroup; 2 Import javax. swing. jcheckbox; 3 Import javax. swing. jframe; 4 Import javax. swing. jlabel; 5 import javax. swing. jpanel; 6 Import javax. swing. jradiobutton; 7 8 Import Java. AWT. *; 9 10 public class diaocha extends jframe {11 jcheckbox jcb1, jcb2, jcb3; 12 jradiobutton jrb2; 13 jlabel jlabel1, jlabel2; 14 jpanel jp1, JP2; 15 public diaocha () {16 jcb1 = new jcheckbox ("huashang daily "); 17 jcb2 = new jcheckbox ("sanqin Metropolis Daily"); 18 jcb3 = new jcheckbox ("Xi'an Evening News"); 19 jrb1 = new jradiobutton ("male "); 20 jrb2 = new jradiobutton ("female"); 21 jlabel1 = new jlabel ("the newspaper you read most often"); 22 jlabel2 = new jlabel ("your gender "); 23 jp1 = new jpanel (); 24 JP2 = new jpanel (); 25 // set layout 26 This. setlayout (New gridlayout (2, 1); 27 // Add component 28 jp1.add (jlabel1); 29 jp1.add (jcb1); 30 jp1.add (jcb2); 31 jp1.add (jcb3 ); 32 jp2.add (jlabel2); 33 // now In the end, all gender choices will be made. Therefore, the button object is added, and the single-choice button in the same group is awakened to the group 34 buttongroup Bgroup = new buttongroup (); 35 Bgroup. add (jrb1.); 36 Bgroup. add (jrb2); 37 jp2.add (jrb1); 38 jp2.add (jrb2); 39 This. add (jp1); 40 this. add (JP2); 41 42 // set the Display Panel 43 this. setvisible (true); 44 This. setdefaclocloseoperation (jframe. exit_on_close); 45 this. setsize (200,200); 46} 47 Public static void main (string [] ARGs) {48 new diaocha (); 49} 50}

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.