This example demonstrates the usage of basic components such as jtextfield, jtextarea, jpasswordfield, jcheckbox (check box button), jradiobutton (drop-down list box component), and jlabel.
Note that if multiple jradiobutton objects need to be grouped into a group, you need to add these jradiobutton objects to the buttongroup using the add () method.
Import Java. AWT. *; import Java. AWT. event. *; import javax. swing. *; public class testregister extends jframe {Private Static final long serialversionuid = 1l; jlabel uname, passwd, confpasswd, sex, utype, like, introduce; jpasswordfield pf1, pf2; jbutton submit, reset; jtextfield TF; jtextarea intro; jcheckbox reading, writing, chatting; jradiobutton M, F; jcombobox CB; testregister (string name) {super (name); this. setvisible (true); this. setbounds (400,300,400,400); this. setlayout (New gridlayout (8, 2); this. addwindowlistener (New windowadapter () {public void windowclosing (invalid wevent e) {system. exit (0) ;}}) ;}public void Init () {uname = new jlabel ("username"); passwd = new jlabel ("password "); confpasswd = new jlabel ("Confirm Password"); Sex = new jlabel ("gender"); utype = new jlabel ("user category "); like = new jlabel ("hobbies"); Introduce = new jlabel ("Introduction"); pf1 = new jpasswordfield (10); pf2 = new jpasswordfield (10 ); submit = new jbutton ("Submit"); reset = new jbutton ("reset"); TF = new jtextfield (10); intro = new jtextarea (3, 10 ); reading = new jcheckbox ("reading"); writing = new jcheckbox ("writing"); chatting = new jcheckbox ("chatting"); M = new jradiobutton ("male "); F = new jradiobutton (""); Cb = new jcombobox (); CB. additem ("Administrator"); CB. additem ("member"); CB. additem ("Tourist"); buttongroup BG = new buttongroup (); BG. add (m); BG. add (f); jpanel p1 = new jpanel (); p1.add (m); p1.add (f); jpanel P2 = new jpanel (); p2.add (reading ); p2.add (writing); p2.add (chatting); jpanel P3 = new jpanel (); jpanel P4 = new jpanel (); p3.add (submit); p4.add (reset); this. add (uname); this. add (TF); this. add (passwd); this. add (pf1); this. add (confpasswd); this. add (pf2); this. add (sex); this. add (P1); this. add (utype); this. add (CB); this. add (like); this. add (P2); this. add (introduce); this. add (intro); this. add (P3); this. add (P4); this. pack ();} public static void main (string [] ARGs) {New testregister ("user register "). init ();}}
Running result: