Use of basic components

Source: Internet
Author: User

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:

 

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.