Those years, learn together Java 8-4

Source: Internet
Author: User
Tags event listener

Import java.awt.borderlayout;import java.awt.checkbox;import java.awt.checkboxgroup;import  java.awt.Container;import java.awt.Font;import java.awt.event.ActionEvent;import  java.awt.event.actionlistener;import java.awt.event.itemevent;import java.awt.event.itemlistener; import javax.swing.jbutton;import javax.swing.jframe;import javax.swing.jlabel;import  Javax.swing.jpanel;import javax.swing.jtextfield;public class ttl extends jframe  implements actionlistener{public ttl () {//Construction method   //Interface Display problem setsize (320, 300); SetVisible (TRUE); Container content = getcontentpane (); Jpanel jp1 = new jpanel ();  //Create a panel Jlabel label = new jlabel (" Welcome to the Student Information Management System ");       //Welcome Statement Jp1.add (label);             //add a label to the panel JP1 jpanel jp2 = new&nbsp JPanel ();          //Create a panel to display labels that prompt for various functions jlabel label1 =  new jlabel ("Please enter the student's details:");    //enter the language of the prompt input:jlabel label2 = new  JLabel ("Learning   students   studies   Number:");      //prompts for labels for various input contents jtextfield field1=new  JTextField (ten);        //10 for the length of the study, you can set your own jlabel label3 = new  jlabel ("Learning   Health   surname   Name:")      //prompt to enter a label for the student's name Jtextfield field2=new  jtextfield (ten);        //10 is the name length and can be set by itself jlabel label4 =  New jlabel ("Learning   health   sex  : ")      //prompt to enter the label of the student's gender checkboxgroup  group1 = new checkboxgroup ();      //Create a check box to select a feature checkbox  check11 = new checkbox ("Male", true,group1);     // Add an option to the check box in Check11.additemlistener (New checkhAndler (1));     //Add Event Listener Checkbox check12 = new checkbox ("female") to the corresponding check box, FALSE,GROUP1)   //Add the option to the check box Check12.additemlistener (New checkhandler (2));    // Add an event listener to the appropriate checkbox Jlabel label5 = new jlabel ("    day   period:");      //prompt to enter the date of birth label Jtextfield field3=new jtextfield ("1994", 3);       //3 is the name length, can be set Jlabel label51 = new jlabel ("year"); Jtextfield field4=new jtextfield ("", 2);       //2 is the name length and can be set by itself JLabel  label52 = new jlabel ("month"); Jtextfield field5=new jtextfield ("Ten", 2);       //2 is the name length and can be set by itself JLabel  label53 = new jlabel ("Day"); Jlabel label6 = new jlabel ("Joint Culture:");        // Tips for selecting a joint culture or not label Checkboxgroup group2 = new checkboxgroup ();       //Create a check box to select a feature Checkbox check21 = new checkbox ("Yes", true,group2);     //Add an option to the check box Check21.additemlistener (New checkhandler (1));     // Add Event Listener Checkbox check22 = new checkbox ("No", false,group2) to the corresponding check box;   // Add an option to the check box Check22.additemlistener (New checkhandler (2));    //add an event listener to the corresponding check box   // Add components to the Panel container Jp2.add (Label1); Jp2.add (Label2); Jp2.add (field1); Jp2.add (LABEL3); Jp2.add (field2); Jp2.add (LABEL4); Jp2.add (CHECK11); Jp2.add (check12); Jp2.add (Label5); Jp2.add (field3); Jp2.add (label51); Jp2.add (FIELD4); Jp2.add ( LABEL52); Jp2.add (FIELD5); Jp2.add (label53); Jp2.add (LABEL6); Jp2.add (check21); Jp2.add (check22); Content.add (JP1,  borderlayout.north);  //add panels to the container Content.add (jp2, borderlayout.center),  //add panels to the container respectively} class checkhandler implements itemlistener     //Event Response class for check box key {private  int sel; Checkhandler (int select) {sel&Nbsp;= select;} Public void itemstatechanged (itemevent e) {switch (SEL) {case 1:method1 ();break;      //invokes the method of choosing the corresponding function case 2:method2 (); break;   //invokes the method of the selected function}}private  VOID METHOD1 ()            //Event Response Method {}private  VOID METHOD2 ()        //     Incident Response Method {}}public  Static void main (String[] args) {Ttl ui = new ttl (); ui.setVisible (true);} @Overridepublic  void actionperformed (actionevent e) {// todo auto-generated  Method stub}}


This article is from the "hacker" blog, make sure to keep this source http://anglecode.blog.51cto.com/5628271/1619873

Those years, learn together Java 8-4

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.