이 기사에서는 참조 용 Java 로그인 인터페이스의 특정 구현 코드를 공유합니다. 특정 내용은 다음과 같습니다
1. 로그인 .java
패키지 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.actionListener; import java.awt.event.keyevent; import java.random; 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; 공개 클래스 로그인은 JFrame 구현 ActionListener {String username; 문자열 비밀번호; 문자열 보안 문자; 공개 정적 문자열 randomcaptcha; Public Jlabel Logolabel, Usernamelabel, PasswordLabel, Captchalabel; 공개 jtextfield usernameinput, Captchainput; Public Jpasswordfield PasswordInput; 공개 JBUTTON 로그인, 로그 아웃, 변경; 공개 패널 패널; public login () {settitle ( "µçâ¼½çãæ"); 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 (new imageicon ( "e : //eclipse//student3//welcome.gif")); logolabel = new Jlabel (New ImageIcon ( "Welcome.gif")); logolabel.setbounds (125, 10, 150, 70); 추가 (logolabel); usernamelabel = new Jlabel ( "Óã»§ãû :"); usernamelabel.setbounds (90, 90, 60, 40); 추가 (usernamelabel); usernameInput = 새로운 jtextfield (); usernameInput.setBounds (150, 100, 150, 20); 추가 (usernameInput); PasswordLabel = New Jlabel ( "Âü¡ ¡ Âë :"); PasswordLabel.setBounds (90, 120, 60, 40); 추가 (passwordLabel); passwordInput = 새로운 jpasswordfield (); passwordInput.setBounds (150, 130, 150, 20); 추가 (passwordInput); Captchalabel = New Jlabel ( "ñéö¤âë :"); Captchalabel.SetBounds (90, 150, 60, 40); 추가 (Captchalabel); CaptChainput = New Jtextfield (); Captchainput.setBounds (150, 160, 70, 20); 추가 (Captchainput); PANIL = NEW PANELDEMO (); PANIL.SETBOUNDS (220, 160, 80, 20); 추가 (패널); change = new Jbutton ( "»»ò»»»"); change.setbounds (300, 160, 80, 20); change.setContentAreafled (false); change.setborderPainted (false); 추가 (변경); login = new Jbutton ( "µçâ¼ £ ¨l £ ©", New ImageIcon ( "login.gif")); login.setbounds (70, 200, 120, 30); login.setmnemonic (keyevent.vk_l); 추가 (로그인); 로그 아웃 = New Jbutton ( "íë³ö £ ¨x £ ©", New ImageIcon ( "exit.gif")); 로그 아웃. 세트 바운드 (210, 200, 120, 30); logout.setmnemonic (keyevent.vk_x); 추가 (로그 아웃); usernameinput.addactionListener (this); passwordinput.addactionListener (this); Captchainput.addactionListener (this); login.addactionListener (this); logout.addactionListener (this); change.addactionListener (this); } public void ActionPerformed (ActionEvent e) {username = usernameInput.getText (); password = new String (passwordInput.getPassword ()); Captcha = captchainput.getText (); if (e.getSource () == change) {panel.repaint (); } if (e.getSource () == login) {if ((username.equals ( "w")) && (password.equals ( "w"))) {if (captcha.equals (randomcaptcha)) {joptionpane.showmessagedialog (whowmessagedialog (»»»»»»»»»); } else {joptionpane.showmessagedialog (this, "ñéö¤âë´íîó!"); PALEN.REPAINT (); }} else {joptionpane.showmessagedialog (this, "Óã»§ãû»òãüâë´íîó!"); }} if (e.getSource () == logout) {joptionpane.showMessagedIalog (this, "»»x¶óïâ´î 접종 £ ¡"); //system.exit(0); 처리 (); }} public static void main (String [] args) {new login (); }} Class PanelDemo 확장 패널 {public void Paint (그래픽 g) {int width = 80; int 높이 = 20; g.setcolor (color.light_gray); G.FillRect (0, 0, 너비, 높이); g.setcolor (color.black); G.DrawRect (0, 0, 너비, 높이); 랜덤 rd = 새로운 랜덤 (); for (int i = 0; i <100; i ++) {int x = rd.nextint (width) -2; int y = rd.nextint (높이) -2; g.setcolor (color.red); g.sudoval (x, y, 2, 2); } g.setfont (새 글꼴 ( "ºúìå", 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); 문자열 str = sb.tostring (). replaceall ( "", ""); login.randomcaptcha = str; }}2. capture.png
위의 내용은이 기사에 관한 모든 것입니다. 모든 사람들이 Java 프로그래밍을 배우는 것이 도움이되기를 바랍니다.