My Java practice code

xiaoxiao2021-04-09  419

My Java practice code

Author: MATOKU

Import javax.swing. *;

Import java.awt.dimension; import java.awt.rectangle; import java.awt.font; import java.awt.Toolkit; import java.awt.event. *;

Public class yahooframe extends jframe {

Thread Tr; Boolean [] Pass = New Boolean [4];

JPANEL ContentPane; Font Font = New Font ("Arial", Font.Bold, 12); JLabel Jlbltop = New Jlabel (); Jlabel Jlblimages = New Jlabel (); JLabel Jlblid = New Jlabel (); Jlabel Jlblpswd = New Jlabel ( ); JLabel jlblRepswd = new JLabel (); JLabel jlblfn = new JLabel (); JLabel jlblln = new JLabel (); JLabel jlblgd = new JLabel (); JLabel jlblbd = new JLabel (); JLabel jlblcr = new JLabel (); JLabel jlbls = new JLabel (); JTextField jtxtid = new JTextField (); JPasswordField jtxtpswd = new JPasswordField (); JPasswordField jtxtRepswd = new JPasswordField (); JTextField jtxtfn = new JTextField (); JTextField jtxtln = new JTextField (); JRadioButton jrbm = new JRadioButton (); JRadioButton jrbf = new JRadioButton (); JLabel jlblmail = new JLabel (); ButtonGroup bgsex = new ButtonGroup (); JComboBox jcbm = new JComboBox (); JTextField jtxtd = new JTextField (); JTextField jtxty = new JTextField (); jlabel jlblmdy = new jlabel (); JCOMBOX JCBCR = New JComboBox (); JComboBox jcbs = new JComboBox (); JButton jbtok = new JButton (); JButton jbtexit = new JButton (); public YahooFrame () {try {setDefaultCloseOperation (EXIT_ON_CLOSE); implmentsFrame ();} catch (Exception Exception) {exception.printStackTrace ();}}

private void implmentsFrame () throws Exception {contentPane = (JPanel) getContentPane (); contentPane.setLayout (null); setSize (new Dimension (500, 460)); setTitle ( "Yahoo"); jlblTop.setFont (new java.awt .Font ("Arial", Font.Bold, 20); Jlbltop.Settext ("Registration Form"); Jlbltop.setBounds (New Rectangle (162, 13, 178, 36)); Jlblimages.SetVerticalAlignment (SwingConstants.Center) Jlblimages.SethorizontalaLAlignment (SwingConstants.center); Tr = new thread () {// advert Combolic rotation PUBLIC VOID Run () {string [] photo = new string [7]; photo [0] = new string ("yahoo_news"); photo [1] = new string ("yahoo_ent"); photo [2] = new string; photo [3] = new string ("yahoo_jobs"); photo [4] = New string ("yahoo_main"); photo [5] = new string ("yahoo_mess"); photo [6] = new string ("Yahoo_SPTS"); while (true) { Jlblimages.Seticon ("imageic () (" imageic () * 7)] ".gif"); try {thread.sleep (2000);} catch (InterruptedException EX) ) {}}

}}); Tr.Start ();

Jlblimages.SetBounds (New Rectangle (3, 40, 492, 50); jlblid.setfont (font); jlblid.settext ("Yahoo ID:"); jlblid.setbounds (New Rectangle (22, 91, 57, 29) ); Jlblpswd.settex; jlblpswd.settext ("Password:"); jlblpswd.setbounds (New Rectangle (21, 123, 67, 28)); jlblrepswd.setFont (font); jlblrepswd.setText ("Retype Password : "); Jlblrepswd.setBounds (New Rectangle (21, 156, 108, 27); jlblfn.setfont; jlblfn.settext (" first name: "); jlblfn.setbounds (New Rectangle (21, 194, 66, 18)); jlblln.setfont (font); jlblln.settext ("Last Name:"); jlblln.setbounds (New Rectangle (21, 224, 69, 22)); jlblgd.setfont (font); jlblgd. Settext ("Gender:"); Jlblgd.SetBounds (New Rectangle (21, 255, 47, 24); jlblbd.setfont (font); jlblbd.settext ("Birthday:"); jlblbd.setbounds (New Rectangle (21 , 292, 54, 21); jlblcr.setfont (font); Jlblcr.Settext ("Country / Region: "); Jlblcr.SetBounds (New Rectangle (21, 323, 92, 22); jlbls.setfont (font); Jlbls.Settext (" State: "); Jlbls.setBounds (New Rectangle (21, 355, 40, 20)); JTXTID.SetBounds (New Rectangle (162, 96, 115, 20)); jtxtid.addkeyListener (new keyadapter () {// Check if the ID of the ID is a letter Public void keyreleased (keyevent e) {string s = jtxtid .getText (); if (s! = "&& s.Length ()> 0) {Pass [0] = true; if (! character.isletter (s.charat (0))) {JOPANE.SHOWCONFIRMDIALOG (NULL "ID first should be letters", "warning", JOPANE.YES_OPTION);

JTXTID.SETTEXT (""); pass [0] = false;}}}}); jtxtpswd.setbounds (New Rectangle (162, 126, 115, 20)); JTXTrepswd.setBounds (New Rectangle (162, 156, 115 20));

Class PswickkeyAdapter Extends Keyadapter {// Check if the password is 8 digits

JPasswordfield JPswd; Boolean B;

Public PswdKeyAdapter (JPasswordfield JPswd) {this (jpswd, false);

Public pswdkeyadapter (jpasswordfield jpswd, boolean b) {this.jpswd = jpswd; this.b = b;}

Public void keyreleased (keyevent e) {string temp = new string (""); char [] s = jpswd.getpassword (); int J = 0;

IF (S.Length> 8) {j = 8;} else {j = s.Length;} for (int i = 0; i

IF (s.Length> 8) {jpswd.settext (temp);}

IF (b == true) {pass [1] = true; if (jtxtpswd.getpassword (). Length == Temp.Length ()) {char [] txt; string txt2;

TXT = jtxtpswd.getPassword (); txt2 = string.copyValueof (txt);

IF (! txt2.equals (temp)) {JOPANE.SHOWCONFIRMDIROG (NULL, "Password is inconsistent", "Warning", JOPANE.YES_OPTION; Pass [1] = false;}} else} (jtxtpswd.getpassword (). Length

JTXTFN.SetBounds (New Rectangle (162, 190, 115, 20); JTXTLN.SetBounds (New Rectangle (162, 226, 115, 20); JRBM.SetFont (font); JRBM.Settext ("Male"); JRBM.SetBounds (New Rectangle (162, 254, 54, 25); JRBM.SetSelected (TRUE); JCBM.SetFont (Font); JCBM.Additem ("Jan"); JCBM.AddItem ("Feb"); JCBM .additem ("mar"); JCBM.Additem ("APR"); JCBM.Additem ("May"); JCBM.Additem ("jun"); jcbm.additem ("jul"); jcbm.additem ("AUG "); JCBM.Additem (" SEP "); JCBM.Additem (" OCT "); JCBM.Additem (" NOV "); JCBM.Additem (" DEC "); JCBM.SetBounds (New Rectangle (162, 288, 69, 20)); JTXTD.SetBounds (New Rectangle (230, 288, 72, 20));

JTXTD.AddKeylistener (new keyadapter () {// checks the date number if the date number is legal public void keyreleased (keyevent e) {pass [2] = true; if (! character.isdigit (E.GetKeychar ()) || jtxtd.gettext ) .lergeth ()> 2 | INTEGER.PARSEINT (). toString ())> 31) {jtxtd.settext (""); pass [2] = false;}}}); jtxty.setbounds (New Rectangle (301, 288, 72, 20);

JTXTY.AddKeylistener (new keyadapter () {// checks if the date month is legal public void keyreleased (keyevent e) {pass [3] = true; if (! character.isdigit () || jtxtychar ()) || jtxty.gettext ) .length ()> 4 | INTEGER.PARSEINT (). TOSTRING ())> 2006) {jtxty.setText (""); pass [3] = false;}});

Jlblmdy.SetFont (font); Jlblmdy.Settext ("(Month, DD, YYYY)); Jlblmdy.setBounds (New Rectangle (380, 289, 90, 19)); JCBcr.SetFont (font); JCBcr.setBounds New Rectangle (162, 321, 146, 20); jcbcr.additem (""); JCBS.Additem ("New South Wales"); JCBS.Additem ("Northern Territory); JCBS.AddItem (" "Queensland"); JCBS.Additem ("SOUTH AUSTRALIA"); JCBS.Additem ("Tasmania"); JCBS.Additem ("Wastern Australia); JCBS.SetFont (font); JCBS.SetBounds (New Rectangle (162, 355, 146, 20)); JBTOK.SETBOUNDS (New Rectangle (149, 403, 74, 20)); JBTOK.SETFONT (FONT); JBTOK.SETTEXT ("OK");

JBTOK.ADDACTIONLISTENER (NEW ActionListener () {/ {// Determines if the data is legal public void actionPerformed (ActionEvent E) {INT I; Boolean Exit = true;

For (i = 0; i <3; i ) {IF (Pass [i] == false) {EXIT = False; Break;}}

IF (exit == true) {joptionpane.showconfirmdialog (NULL, "Successful / N Thank you" JTXTID.GETTEXT () "/ n Password is" String.copyValueof (jtxTrepswd.getPassword ()), "Congratulations", JOPTIONPANE.YES_OPTION; system.exit (0);} else {JOPANE.SHOWCONFIRMDIALOG (NULL, "Registration Fail", "Fail", JOPTIONPANE.YES_OPTION;}}});

JBTexit.SetBounds (New Rectangle (251, 403, 74, 20); JBTexit.SetFont (font); JBTEXIT.SETTEXT ("EXIT");

JBTexit.AddActionListener (NEW ActionListener () {// Exit Register Public Void ActionPerformed (ActionEvent E) {System.exit (0);}}); bgsex.add (jrbm); jrbf.setfont (font); jrbf.setText "Female"); Jrbf.SetBounds (New Rectangle (248, 255, 67, 24); bgsex.add (jrbf); jlblmail.setfont (font); jlblmail.settext ("@ yahoo.com"); jlblmail. SetBounds (New Rectangle (294, 96, 75, 18); contentpane.add (jlblmail); contentpane.add (jlblid); contentpane.add (jtxt); contentpane.add (jtxtpswd); contentPane.add (jlblRepswd); contentPane.add (jlblfn); contentPane.add (jlblpswd); contentPane.add (jlblln); contentPane.add (jtxtRepswd); contentPane.add (jtxtfn); contentPane.add (jtxtln); contentPane .add (jlblgd); ContentPane.Add (JRBM); ContentPane.Add (JRBF); ContentPane.Add (jlblcr); ContentPane.Add (jlblbd Contentpane.Add (jlbltop); ContentPane.Add (JCBM); ContentPane.Add (JTXTD); ContentPane.Add (JTXTY); ContentPane.Add (JLBLMDY); ContentPane.Add (JCBS); ContentPane.Add (JCBS) ContentPane.Add (jbtexit); ContentPane.Add (JBTOK); ContentPane.Add (jlblimages);} public static void main (String [] args) {yahooframe frame = new Yahooframe ();

转载请注明原文地址:https://www.9cbs.com/read-133122.html

New Post(0)