Dieser Artikel teilt den spezifischen Implementierungscode der Java -Anmeldestelle für Ihre Referenz. Der spezifische Inhalt ist wie folgt
1. Login.java
Paket WZB; Import Java.awt.Color; Import Java.awt.font; Import Java.awt.graphics; Import Java.awt.panel; Import Java.awt.event.ActionEvent; Import Java.awt.Event.ActionListen; javax.swing.imageicon; import javax.swing.jbutton; import javax.swing.jframe; import Javax.swing.jlabel; import Javax.swing.joptionpane; import Javax.swing.jpasswordfield; Import Javax.swing.jtextfield; öffentliche Klasse Login erweitert JFrame implementiert ActionListener {String Benutzername; String -Passwort; String Captcha; öffentliche statische String RandomCaptcha; Public Jlabel Logolabel, usernamelabel, passwordlabel, captchalabel; public JTextfield BenutzernameInput, Captchainput; public JPasswordfield PassageInput; Public Jbutton Login, Logout, Veränderung; öffentliches Gremium; public login () {settitle ("µçâ¼ ½ ½çãæ"); SetSize (400, 300); setLocationRelativeto (null); init (); setvisible (wahr); setDefaultCloseOperation (jframe.exit_on_close); setResizable (falsch); } public void init () {setLayout (null); // logolabel = new JLabel (); // logolabel.seticon (neues Imageicon ("e: //eclipse//student3//welcome.gif")); logolabel = new JLabel (neues Imageicon ("Welcome.gif")); logolabel.setBounds (125, 10, 150, 70); add (logolabel); usernamelabel = new Jlabel ("Óã» §ãû: "); usustamelabel.setBounds (90, 90, 60, 40); add (ustamelabel); userernameInput = new JTextField (); userernameInput.setBounds (150, 100, 150, 20); add (userernameInput); passwordLabel = new JLabel ("ãü¡ ¡âë:"); PassageLabel.SetBounds (90, 120, 60, 40); add (PasswordLabel); PassageInput = new Jpasswordfield (); PassageInput.SetBounds (150, 130, 150, 20); add (passingInput); captchalabel = new Jlabel ("ñéö are:"); Captchalabel.Setbounds (90, 150, 60, 40); add (captchalabel); captChainput = new JTextField (); CaptChainput.SetBounds (150, 160, 70, 20); add (captChainput); Panel = neuer PanelDemo (); Panel.Setbounds (220, 160, 80, 20); add (panel); Änderung = neuer Jbutton ("» ò »» »» "); Änderung.Setbounds (300, 160, 80, 20); Änderung.SetContentareAtedestilliert (falsch); Änderung.SetBorderPainted (falsch); add (wechseln); Login = neuer Jbutton ("µçâ¼ £ ¨l £ ©", New Imageicon ("Login.gif"); Login.Setbounds (70, 200, 120, 30); login.setMnemonic (keyEvent.vk_l); add (login); logout = new Jbutton ("íë³ö £ ¨x £ ©", New Imageicon ("exit.gif"); logout.Setbounds (210, 200, 120, 30); logout.setMnemonic (keyEvent.vk_x); add (logout); userernameInput.addactionListener (this); PassageInput.AddactionListener (this); captChainput.addactionListener (this); login.addactionListener (this); logout.AddactionListener (this); Change.AddactionListener (this); } public void actionPerformed (actionEvent e) {userername = userernameInput.getText (); password = new String (passwordput.getPassword ()); captcha = captChainput.getText (); if (e.getSource () == Änderung) {panel.Repaint (); } if (e.getSource () == login) {if ((userername.equals ("w")) && (password.equals ("w")) {if (captcha.equals (randomcaptcha)) {joptionpane.showmessagedialog (this »¶ógrada ½!"); } else {joptionpane.showMessagedialog (this, "ñéö ëëíîó!"); panel.Repaint (); }} else {joptionpane.showMessagedialog (this, "Óã» §ãû »òãüëëíîó!"); }} if (e.getSource () == logout) {joptionpane.showMessagedialog (this, "» ¶óïâ´îôùà´ £ ¡"); //System.exit(0); dispose (); }} public static void main (String [] args) {new Login (); }} Klasse PanelDemo erweitert das Panel {public void paint (Graphics g) {int width = 80; int Höhe = 20; g.setColor (color.light_gray); G.FillRect (0, 0, Breite, Höhe); g.setColor (color.black); G.Drawrect (0, 0, Breite, Höhe); Random Rd = new random (); für (int i = 0; i <100; i ++) {int x = rd.Nextint (Breite) - 2; int y = rd.nextint (Höhe) - 2; G.SetColor (color.red); G.Drawoval (x, y, 2, 2); } g.setfont (neue Schriftart ("ºúìå", font.bold, 20)); G.SetColor (color.Blue); char [] c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789" .toCharArray (); StringBuffer sb = new StringBuffer (); für (int i = 0; i <4; i ++) {int index = rd.Nextint (C.Length); sb.Append (c [index] + ""); } g.drawstring (sb.toString (), 0, 18); String str = sb.toString (). Ersatz ("", ""); Login.randomcaptcha = str; }}2. Capture.png
Das obige dreht sich alles um diesen Artikel. Ich hoffe, dass es für alle hilfreich sein wird, Java -Programme zu lernen.