一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服務器之家 - 編程語言 - JAVA教程 - java語言圖形用戶登錄界面代碼

java語言圖形用戶登錄界面代碼

2020-05-18 11:59壞蛋好人 JAVA教程

這篇文章主要為大家詳細介紹了java語言圖形用戶登錄界面代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了java登錄界面的具體實現代碼,供大家參考,具體內容如下

1. Login.java

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package 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.util.Random;
 
import 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;
 
public class Login extends JFrame implements ActionListener {
 String userName;
 String password;
 String captcha;
 public static String randomcaptcha;
 
 public JLabel logoLabel, userNameLabel, passwordLabel, captchaLabel;
 public JTextField userNameInput, captchaInput;
 public JPasswordField passwordInput;
 public JButton login, logout,change;
 public Panel panel;
 
 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);
  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(passwordLabel);
  passwordInput = new JPasswordField();
  passwordInput.setBounds(150, 130, 150, 20);
  add(passwordInput);
 
  captchaLabel = new JLabel("ÑéÖ¤Âë:");
  captchaLabel.setBounds(90, 150, 60, 40);
  add(captchaLabel);
  captchaInput = new JTextField();
  captchaInput.setBounds(150, 160, 70, 20);
  add(captchaInput);
 
  panel = new PanelDemo();
  panel.setBounds(220, 160, 80, 20);
  add(panel);
   
   
  change = new JButton("»»Ò»»»");
  change.setBounds(300, 160, 80, 20);
  change.setContentAreaFilled(false);
  change.setBorderPainted(false);
  add(change);
 
  login = new 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);
 
  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(this, "»¶Ó­µÇ½!");
    } 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();
 }
}
class PanelDemo extends Panel {
 
 public void paint(Graphics g) {
  int width = 80;
  int height = 20;
  g.setColor(Color.LIGHT_GRAY);
  g.fillRect(0, 0, width, height);
  g.setColor(Color.BLACK);
  g.drawRect(0, 0, width, height);
  Random rd = new Random();
  for (int i = 0; i < 100; i++) {
   int x = rd.nextInt(width) - 2;
   int y = rd.nextInt(height) - 2;
   g.setColor(Color.RED);
   g.drawOval(x, y, 2, 2);
  }
  g.setFont(new Font("ºÚÌå", 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. 捕獲.PNG   

java語言圖形用戶登錄界面代碼

以上就是本文的全部內容,希望對大家學習java程序設計有所幫助。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 成年人免费看的视频 | 亚洲国产精品无码中文在线 | 丝袜兔女郎被啪在线观看91 | 国产精品久久久久不卡绿巨人 | 亚洲精品福利在线 | 久久精品麻豆国产天美传媒果冻 | 免费看国产一级特黄aa大片 | 美女1819xxxx| 日韩免费 | 精品一区二区三区五区六区 | 亚洲精品精品一区 | 日韩在线 中文字幕 | 精品一卡2卡3卡4卡5卡亚洲 | 精品在线一区 | 99热这里只有精品国产免费 | 日韩欧美综合在线二区三区 | 波多野结衣教师未删减版 | 天天久久综合网站 | 非洲黑人gay巨大 | 午夜免费体验30分 | 欧美精品一区二区在线观看播放 | 国产欧美日韩不卡 | 男人天堂a | 久久re热在线视频精6 | 关晓彤被调教出奶水的视频 | 四虎影院永久网站 | 国产黄频在线观看高清免费 | 色一情 | 深夜成人 | 免费一看一级欧美 | 99re7在线精品免费视频 | 欧美一区二区福利视频 | 把美女屁股眼扒开图片 | 四虎影院久久久 | 久久艹综合 | 国产欧美一区二区三区免费 | 欧美在线观看网址 | 亚洲欧洲日产v特级毛片 | 国产一区二区三区免费在线视频 | 国产精品视频免费一区二区三区 | china中国小帅gayxnxx |