Final Display effect
① Label control, text box, Password box (button)
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/82/C3/wKiom1dgQNShu9R4AAAlkt5q7RE215.png "title=" 1.png " alt= "Wkiom1dgqnshu9r4aaalkt5q7re215.png"/>
② check box, Radio box (the radio button needs to be placed in a "Buttongroup")
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/82/C2/wKioL1dgQhWgHnBdAAA0h_XFUnw794.png "title=" 2.png " alt= "Wkiol1dgqhwghnbdaaa0h_xfunw794.png"/>
③ drop-down box, list box, scroll list box
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/82/C2/wKioL1dgQi6QZXaQAAAqSYLW1qs753.png "title=" 3.png " alt= "Wkiol1dgqi6qzxaqaaaqsylw1qs753.png"/>
① uses text boxes to mark hints, use text boxes to accept input information, and use a password box to hide character information entered by the user.
/* * small case, to achieve a landing interface. * using a grid layout, place three JPanel in JFrame, and use a grid layout to split the interface into 3 levels. * * introduced three new components * tags, text boxes, password boxes. */package part_2;import java.awt.*;import javax.swing.*;p ublic class e31_2 extends JFrame{ // Defining class Variables JPanel jp1, JP2, JP3;    JLABEL JL1, JL2;    JBUTTON JB1, jb2; JTextField jtf1; JPasswordField jpf1; public static void main (String[] args) { e31_2 _e31_2 = new e31_2 (); } // Constructors public E31_2 () { // Creating Components jp1 = new jpanel (); jp2 = new jpanel (); jp3 = new jpanel (); jl1 = new jlabel ("User name"); jl2 = new jlabel ("password"); jb1 = new jbutton ("Confirm"); jb2 = New jbutton ("Cancel"); jtf1 = new jtextfield (10 ); jpf1 = new jpasswordfield (Ten); // Add Components jp1.add (JL1); jp1.add (JTF1) ; jp2.add (JL2); jp2.add (JPF1); jp3.add (JB1); jp3.add (JB2); this.add (JP1); this.add (JP2); this.add (JP3); // set up layout manager this.setlayout (New gridlayout (3, 1)); // Set Form Properties this.settitle ("Landing"); this.setsize (260, this.setlocation (130, 130); this. Setdefaultcloseoperation (Jframe.exit_on_close); // Show Forms This.setvisible (true); }}
② check box to limit the input, the radio box to achieve a unique input, you need to put aunique set of information "Buttongroup", add components, respectively, to achieve the final effect.
/* * */package part_2;import java.awt.*;import javax.swing.*;p Ublic class e31_3 extends JFrame{ // Defining class Variables JPanel Jp1, jp2, jp3; jlabel jl1, jl2; jbutton jb1, jb2; JCheckBox jcb1, jcb2, jcb3; jradiobutton jrb_11, jrb_12; buttongroup jbg1; public static void main (String[] args) { e31_3 _e31_3 = new e31_3 (); } // Constructor public e31_3 () { // Creating Components jp1 = new jpanel (); &nbSp; jp2 = new jpanel (); jp3 = new jpanel (); jl1 = new jlabel ("Favorite Sport"); jl2 = new JLabel ("gender"); jb1 = new jbutton ("Registered user"); jb2 = new jbutton ("de-registration"); jcb1 = new jcheckbox ("Football"); jcb2 = new jcheckbox ("basketball"); jcb3 = new jcheckbox ("Tennis"); jrb_11 = new Jradiobutton ("male"); jrb_12 = new jradiobutton ("female") );     &NBsp; jbg1 = new buttongroup (); // Adding components jbg1.add (Jrb_11); jbg1.add (Jrb_12); jp1.add (JL1); jp1.add (JCB1); jp1.add (JCB2); jp1.add (JCB3); Jp2.add (JL2); jp2.add (Jrb_11); jp2.add (Jrb_12); jp3.add (JB1); jp3.add (JB2); this.add (JP1) ; &nBsp; this.add (JP2); this.add (JP3); // set up layout manager this.setlayout (New gridlayout (3, 1)); // Set Form Properties this.settitle ("User registration"); This.setdefaultcloseoperation (Jframe.exit_on_close); This.setsize (400, 157); // Display Form this.setvisible (true); }}
③ list Box
/* * drop-down box JComboBox * list box JList * Scroll window jscrollpane */package part_2;import java.awt.*;import javax.swing.*;p ublic class e31_4 extends jframe{ // Defining class Variables JComboBox jcb1; &NBSP;JLIST&NBSP;JL1;&NBSP;&NBSP;&NBSP;&NBSP;JSCROLLPANE&NBSP;JSP1;&NBSP;&NBSP;&NBSP;&NBSP;JPANEL&NBSP;JP1, jp2; JLabel jl1, jl2; Public static void main (String[] args) { e31_4 _e31_4 = new e31_4 (); } // Constructor public e31_4 () { // Create Component jl1 = new jlabel ("drop-down box") ; string[] tmp4jcb1 = {"Tang Sanzang", "Monkey King", "Pig Awareness can", "Sand Wu Jing"}; jcb1 = new JComboBox<> (TMP4JCB1); jl2 = new jlabel ("list box"); string[] tmp4jl1 = {"孙红蕾", "Chow Yun-Fat", "Stephen Chow Chi", "Andy Lau"}; jL1 = new JList<> (TMP4JL1); jl1.setvisiblerowcount (1); jsp1 = new jscrollpane (jL1); jp1 = new jpanel (); jp2 = new jpanel (); // Add Component jp1.add (JL1); jp2.add (JL2); Jp1.add (JCB1);// jp2.add (jL1); jp2.add (JSP1); this.add (JP1); this.add (JP2); // set up layout manager this.setlayout (New gridlayout (3, 1)); // Set Form Properties thIs.settitle ("list box ..."); this.setdefaultcloseoperation ( Jframe.exit_on_close); this.setsize (400, 360); // Show Forms this.setvisible (true); }}
Using 57 lines, block 56 rows.
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/82/C3/wKiom1dgP9jTTmJMAABm6P93Pb8792.jpg "title=" Sunnybay.51blog.jpg "alt=" Wkiom1dgp9jttmjmaabm6p93pb8792.jpg "/>
This article from "Little Cui's experimental notes" blog, declined to reprint!
Common Controls 1