-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCatResign.java
More file actions
149 lines (130 loc) · 4.37 KB
/
Copy pathCatResign.java
File metadata and controls
149 lines (130 loc) · 4.37 KB
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
package cat.login;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import cat.util.CatUtil;
public class CatResign extends JFrame {
private JPanel contentPane;
private JTextField textField;
private JPasswordField passwordField;
private JPasswordField passwordField_1;
private JLabel lblNewLabel;
public CatResign() {
setTitle("Registered cat chat room\n");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(350, 250, 450, 300);
contentPane = new JPanel() {
private static final long serialVersionUID = 1L;
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(new ImageIcon("images\\\u6CE8\u518C\u754C\u9762.jpg").getImage(), 0,0, getWidth(), getHeight(), null);
}
};
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
textField = new JTextField();
textField.setBounds(150, 42, 104, 21);
textField.setOpaque(false);
contentPane.add(textField);
textField.setColumns(10);
passwordField = new JPasswordField();
passwordField.setEchoChar('*');
passwordField.setOpaque(false);
passwordField.setBounds(190, 98, 104, 21);
contentPane.add(passwordField);
passwordField_1 = new JPasswordField();
passwordField_1.setBounds(192, 152, 104, 21);
passwordField_1.setOpaque(false);
contentPane.add(passwordField_1);
//注册按钮
final JButton btnNewButton_1 = new JButton();
btnNewButton_1.setIcon(new ImageIcon("images\\注册1.jpg"));
btnNewButton_1.setBounds(320, 198, 80, 40);
getRootPane().setDefaultButton(btnNewButton_1);
contentPane.add(btnNewButton_1);
//返回按钮
final JButton btnNewButton = new JButton("");
btnNewButton.setIcon(new ImageIcon("images\\返回.jpg"));
btnNewButton.setBounds(230, 198, 80, 40);
contentPane.add(btnNewButton);
//提示信息
lblNewLabel = new JLabel();
lblNewLabel.setBounds(55, 218, 185, 20);
lblNewLabel.setForeground(Color.red);
contentPane.add(lblNewLabel);
//返回按钮监听
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btnNewButton.setEnabled(false);
//返回登陆界面
CatLogin frame = new CatLogin();
frame.setVisible(true);
setVisible(false);
}
});
//注册按钮监听
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Properties userPro = new Properties();
File file = new File("Users.properties");
CatUtil.loadPro(userPro, file);
String u_name = textField.getText();
String u_pwd = new String(passwordField.getPassword());
String u_pwd_ag = new String(passwordField_1.getPassword());
// 判断用户名是否在普通用户中已存在
if (u_name.length() != 0) {
if (userPro.containsKey(u_name)) {
lblNewLabel.setText("用户名已存在!");
} else {
isPassword(userPro, file, u_name, u_pwd, u_pwd_ag);
}
} else {
lblNewLabel.setText("用户名不能为空!");
}
}
private void isPassword(Properties userPro,
File file, String u_name, String u_pwd, String u_pwd_ag) {
if (u_pwd.equals(u_pwd_ag)) {
if (u_pwd.length() != 0) {
userPro.setProperty(u_name, u_pwd_ag);
try {
userPro.store(new FileOutputStream(file),
"Copyright (c) Boxcode Studio");
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
btnNewButton_1.setEnabled(false);
//返回登陆界面
CatLogin frame = new CatLogin();
frame.setVisible(true);
setVisible(false);
} else {
lblNewLabel.setText("密码为空!");
}
} else {
lblNewLabel.setText("密码不一致!");
}
}
});
}
}