Este artigo compartilha o código de implementação específico da interface de login Java para sua referência. O conteúdo específico é o seguinte
1. Login.java
pacote wzb; importar java.awt.color; importar java.awt.font; importar java.awt.Graphics; importar java.awt.panel; importar java.awt.event.actionEvent; import.KeevA.Awt.Event.ActionListener; importar Java.awt.event; importação; importação; importação; importação; importação; javax.swing.imageicon; importar javax.swing.jbutton; importar javax.swing.jframe; importar javax.swing.jlabel; importar javax.swing.JOptionPane; importar javax.swing.jpasswordfield; import javax.swing.jtextfield; classe pública Login estende o jframe implementa o ActionListener {string userName; Senha da string; String captcha; Public Static String Randomcaptcha; public Jlabel Logolabel, Usernamelabel, PasswordLabel, Captchalabel; public jtextfield userNameInput, captchainput; public jpasswordfield passwordInput; Login público de jbutton, logout, alteração; painel público; public Login () {Settitle ("µç de ½ °"); SetSize (400, 300); setLocationRelativeTo (NULL); init (); setvisible (true); setDefaultCloseoperation (jframe.exit_on_close); setResizable (false); } public void init () {setLayout (null); // logolabel = new jlabel (); // logolabel.seticon (novo imageicon ("e: //eclipse//student3//welcome.gif")); logolabel = new jlabel (new imageicon ("welcome.gif")); logolabel.setbounds (125, 10, 150, 70); add (logolabel); UserNameLabel = New Jlabel ("Ó Ó» §ã: "); Usernamelabel.setbounds (90, 90, 60, 40); add (Usernamelabel); userNameInput = new JTextField (); UserNameInput.setBounds (150, 100, 150, 20); add (userNameInput); passwordLabel = new jlabel ("ãü¡ ¡ë:"); PasswordLabel.setBounds (90, 120, 60, 40); add (senhaLabel); senhaNput = new JPasswordField (); PasswordInput.setBounds (150, 130, 150, 20); add (passwordInput); captchalabel = novo Jlabel ("ñéö¤âs:"); captchalabel.setbounds (90, 150, 60, 40); add (captchalabel); captChainput = new jtextfield (); captChainput.setbounds (150, 160, 70, 20); add (captchainput); Painel = new PanelDemo (); painel.setbounds (220, 160, 80, 20); add (painel); mudança = novo jbutton ("» »» »» »» "); Change.setbounds (300, 160, 80, 20); alteração.SetContentArabiled (false); change.setBorderPainted (false); add (altere); login = novo jbutton ("µç £ ¨l ©", novo imageicon ("login.gif")); login.setbounds (70, 200, 120, 30); login.setMnemonic (keyevent.vk_l); add (login); logout = new jbutton ("Íë³ö ¨x £ ©", novo imageicon ("exit.gif")); logout.setbounds (210, 200, 120, 30); logout.setMnemonic (keyevent.vk_x); add (logout); UserNameInput.addactionListener (isto); PasswordInput.addactionListener (this); captChainput.addactionListener (isto); login.addactionListener (this); logout.addactionListener (this); alteração.AddactionListener (isto); } public void ActionPerformed (ActionEvent e) {nome de usuário = userNameInput.getText (); senha = new String (PasswordInput.getPassword ()); captcha = captChainput.getText (); if (e.getSource () == alteração) {pain.repaint (); } if (e.getsource () == login) {if ((userName.equals ("w")) && (senha.equals ("w"))) {if (captcha.equals (aleatomcaptcha)) {joptionpane.showmessagedialog (isto, "» § µµ! } else {JoptionPane.showMessagedialog (isto, "ñéöntos. painel.Repaint (); } } else { JOptionPane.showMessageDialog(this, "Óû§Ãû»òÃÜÂë´íÎó!"); }} if (e.getSource () == logout) {JoptionPane.ShowMessAgedialog (isto, "» § `Óï'îôùà´ £ ¡"); //System.exit(0); descarte (); }} public static void main (string [] args) {new Login (); }} classe PanelDemo estende o painel {public void Paint (gráficos g) {int width = 80; int altura = 20; g.setColor (color.light_gray); G.FillRect (0, 0, largura, altura); g.setColor (color.black); G.Drawrect (0, 0, largura, altura); RD RD = novo aleatório (); for (int i = 0; i <100; i ++) {int x = rd.nextint (largura) - 2; int y = rd.nextint (altura) - 2; g.setColor (color.red); G.Drawoval (X, Y, 2, 2); } g.setFont (nova fonte ("ºúìå", font.BOLD, 20)); g.setColor (color.blue); char [] c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789" .toCharArray (); StringBuffer sb = new StringBuffer (); for (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 (). Replaceall ("", ""); Login.randomcaptcha = str; }}2. Capture.png
O exposto acima é tudo sobre este artigo, espero que seja útil para todos aprenderem a programação Java.