Java language Implementation Simple login interface

Source: Internet
Author: User

  1. Programming Ideas:
    Use the Math.random () method to cycle through a random integer between 6 97~122 (corresponding to the ASCII code value ' a ' ~ ' Z '), convert it to a char variable, and connect to a 6-bit string as the verification code output, prompting the user for input. The user input string matches the verification code, prompts for the pass, does not match prompts the error and generates a random verification code again.
  2. Program Flowchart:
  3. SOURCE program:
    1 ImportJava.awt.EventQueue;2 ImportJavax.swing.JFrame;3 ImportJava.awt.Color;4 ImportJavax.swing.JPanel;5 Importjava.awt.BorderLayout;6 ImportJavax.swing.JLabel;7 ImportJavax.swing.JTextField;8 ImportJavax.swing.JPasswordField;9 ImportJavax.swing.JButton;Ten Importjavax.swing.event.*; One ImportJava.awt.Font; A  Public classLoginwindow { -  -     PrivateJFrame frame; the     PrivateJPasswordField Passwordfield; -  -     /** - * Launch the application. +      */ -      Public Static voidMain (string[] args) { +Eventqueue.invokelater (NewRunnable () { A              Public voidrun () { at                 Try { -Loginwindow window =NewLoginwindow (); -Window.frame.setVisible (true); -}Catch(Exception e) { - e.printstacktrace (); -                 } in             } -         }); to     } +  -     /** the * Create the application. *      */ $      PublicLoginwindow () {Panax Notoginseng Initialize (); -     } the  +     /** A * Initialize The contents of the frame. the      */ +     Private voidInitialize () { -frame =NewJFrame (); $ Frame.setbackground (color.blue); $Frame.setbounds (100, 100, 445, 319); - frame.setdefaultcloseoperation (jframe.exit_on_close); -          theJPanel Panel =NewJPanel (); - Frame.getcontentpane (). Add (Panel, borderlayout.center);WuyiPanel.setvisible (true); thePanel.setlayout (NULL); -          WuJLabel label =NewJLabel ("\U767B\U5F55\U540D\UFF1A"); -Label.setfont (NewFont ("Microsoft Jas Black", Font.plain, 18)); AboutLabel.setbounds (85, 44, 76, 32); $ panel.add (label); -          -JLabel Label_1 =NewJLabel ("\U5BC6\U7801\UFF1A"); -Label_1.setfont (NewFont ("Microsoft Jas Black", Font.plain, 18)); ALabel_1.setbounds (85, 86, 76, 32); + Panel.add (label_1); the          -JLabel label_2 =NewJLabel ("\U9A8C\U8BC1\U7801\UFF1A"); $Label_2.setfont (NewFont ("Microsoft Jas Black", Font.plain, 18)); theLabel_2.setbounds (84, 128, 76, 30); the Panel.add (label_2); the          theJTextField TextArea =NewJTextField (); -Textarea.setborder (Javax.swing.BorderFactory.createLineBorder (NewJava.awt.Color (255,0,0))); inTextarea.setbounds (181, 44, 166, 34); the Panel.add (TextArea); the          AboutPasswordfield =NewJPasswordField (); thePasswordfield.setborder (Javax.swing.BorderFactory.createLineBorder (NewJava.awt.Color (255,0,0))); thePasswordfield.setbounds (181, 86, 166, 34); the Panel.add (Passwordfield); +          -JButton Btnnewbutton =NewJButton ("\u767b\u5f55"); theBtnnewbutton.setenabled (false);BayiBtnnewbutton.setbackground (NewColor (51, 153, 0)); the Btnnewbutton.setforeground (color.black); theBtnnewbutton.setbounds (124, 186, 181, 29); - Panel.add (Btnnewbutton); -          theJButton btnnewbutton_1 =NewJButton ("\u5feb\u901f\u6ce8\u518c"); theBtnnewbutton_1.setbackground (NewColor (255, 204, 255)); theBtnnewbutton_1.setbounds (124, 225, 181, 29); the Panel.add (btnnewbutton_1); -          the          theString result = ""; the          for(inti = 0;i < 6;i++)94         { the             intc = (int) (Math.random () * 26 + 97); theresult = result + (Char) C; the         }98JLabel Lblvalid =NewJLabel (result); AboutLblvalid.setbounds (277, 134, 70, 22); - Panel.add (lblvalid);101         102JTextField textarea_1 =NewJTextField ();103Textarea_1.getdocument (). Adddocumentlistener (NewDocumentlistener () {104              Public voidinsertupdate (documentevent e) { the                 if(Textarea_1.gettext (). Equals (Lblvalid.gettext ())) {106Btnnewbutton.setenabled (true);107                 }108                 Else{109Btnnewbutton.setenabled (false); the                 }111             } the              Public voidremoveupdate (documentevent e) {113                 if(Textarea_1.gettext (). Equals (Lblvalid.gettext ())) { theBtnnewbutton.setenabled (true); the                 } the                 Else{117Btnnewbutton.setenabled (false);118                 }119             } -              Public voidchangedupdate (documentevent e) {121                 122             }123         });124          theTextarea_1.setborder (Javax.swing.BorderFactory.createLineBorder (NewJava.awt.Color (255,0,0)));126Textarea_1.setbounds (180, 128, 76, 32);127 Panel.add (textarea_1); -     }129}

  4. To achieve a result diagram:

  5. Experiment Summary:

Resources:

Http://www.yiibai.com/swing/home.html

Https://zhidao.baidu.com/question/554112250.html

Java language Implementation Simple login 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.