Simple programming (28) Form creation is designed as follows GUI interface

Source: Internet
Author: User

The GUI interface is designed as follows: (When the user clicks the "Done" button, the name, gender, interest and other information displayed in the text area, click on the "Cancel" button, all components revert to the original state)

<span style= "FONT-SIZE:14PX;" ><strong>import Java.awt.button;import Java.awt.container;import Java.awt.dimension;import Java.awt.flowlayout;import Java.awt.gridlayout;import Java.awt.textarea;import Java.awt.Toolkit;import Java.awt.event.actionevent;import Java.awt.event.actionlistener;import Java.awt.event.keyevent;import Java.awt.event.keylistener;import Java.awt.event.textevent;import Java.awt.event.windowevent;import Java.awt.event.windowstatelistener;import Javax.swing.borderfactory;import Javax.swing.buttongroup;import Javax.swing.icon;import Javax.swing.imageicon;import Javax.swing.jbutton;import Javax.swing.JCheckBox;import Javax.swing.jframe;import Javax.swing.jlabel;import Javax.swing.joptionpane;import Javax.swing.JPanel;import Javax.swing.jpasswordfield;import Javax.swing.jradiobutton;import Javax.swing.jscrollpane;import Javax.swing.jtextarea;import javax.swing.jtextfield;class Denglu extends Jframe{private JLabel UserJLabel,pwdJLabel, Danxuan;private JTextField Text;private JPasswordField password;private JButton buttn,quxiao;private JPanel pan;private jcheckbox jcb1=new Jcheckbox ("Listen to the song");p rivate jcheckbox jcb2=new jcheckbox ("Roller skating");p rivate jcheckbox jcb3=new jcheckbox ("Hip Hop");p rivate Jcheckbox jcb4=new jcheckbox ("Computer");p rivate Jradiobutton xuanzeyes=new Jradiobutton ("male");p rivate JRadioButton Xuanzeno=new Jradiobutton ("female");p rivate jtextarea textarea;private String name;public Denglu () {textarea=new JTextArea ( (+); Textarea.setlinewrap (true); JScrollPane jscrollpane=new JScrollPane (TextArea); Container Container1=this.getcontentpane (); Toolkit Toolkit=toolkit.getdefaulttoolkit ();D imension dimension=toolkit.getscreensize (); SetSize (dimension.width/ 3,DIMENSION.HEIGHT/3); Settitle ("Basic Information Entry Form"); Setdefaultcloseoperation (jframe.exit_on_close); setresizable (true); Container Container=this.getcontentpane (); FlowLayout flowlayout=new FlowLayout (); Container.setlayout (FlowLayout); Userjlabel=new JLabel ("User name:"); Icon icon=new ImageIcon ("Img/water lilies. JPG "); Userjlabel. SetIcon (icon), Text=new JTextField (;d anxuan=new JLabel ("Gender:"); Buttongroup bu=new Buttongroup () bu.add (This.xuanzeyes) bu.add (This.xuanzeno);p an=new JPanel ();p An.setborder ( Borderfactory.createtitledborder ("interest"));p An.setlayout (New GridLayout (1, 4));p An.add (JCB1);p an.add (JCB2);p An.add ( JCB3);p An.add (JCB4); Buttn=new JButton ("Completed (L)"); Buttn.setmnemonic (' J '); Quxiao=new JButton ("Cancellation (C)"); Quxiao.setmnemonic (' C '); setvisible (true); Container.add (Userjlabel); Container.add (text); Container.add (Danxuan); Container.add (Xuanzeyes); Container.add (Xuanzeno); Container.add (pan); Container.add (BUTTN); Container.add (Quxiao) ; Container.add (TextArea); Myactionlistener listener=new Myactionlistener (); Buttn.addactionlistener (listener); Quxiao.addactionlistener ( listener);} Class Myactionlistener implements Actionlistener{public void actionperformed (ActionEvent arg0) {if (arg0.getsource () = = BUTTN) {String s= "name:"; S+=text.gettext (); s+= "\ n sex:"; s+=xuanzeyes.isselected ()? " Male ":" female "; s+=" \ n "hobby:"; if (jcb2.isselected () ==true) {s+= "Roller skating";} if (jcb3.isselected () ==true) {s+= "street Dance";} if (jcb4.isselected () ==true) {s+= "Computer";} if (jcb1.isselected () ==true) {s+= "Listen to the song";} Textarea.settext (s);} Else{textarea.settext (null); jcb1.setselected (false); jcb2.setselected (false); jcb3.setselected (false); Jcb4.setselected (false); xuanzeyes.setselected (false); xuanzeno.setselected (false); Text.settext (null);}}} public class FG {public static void main (string[] args) {Denglu dl=new Denglu ();}} </strong></span>

Simple programming (28) Form creation is designed as follows GUI interface

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.