Repository navigation
Expand file tree
/
Copy pathRegistrationScreen.java
More file actions
146 lines (117 loc) · 4.5 KB
/
Copy pathRegistrationScreen.java
File metadata and controls
146 lines (117 loc) · 4.5 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
package Lab6Part2;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.FileWriter;
import java.io.IOException;
public class RegistrationScreen extends Frame implements ActionListener, WindowListener {
private TextField nameTextField;
private TextField surnameTexField;
private TextField emailTextField;
private TextField passwordTextField;
private List genderList;
private TextArea aboutYourselfTextArea;
private Button button;
public RegistrationScreen() {
super("Регистрация пользователя");
setLayout(null);
setSize(400, 600);
addWindowListener(this);
Label mainLabel = new Label("Регистрация");
mainLabel.setBounds(160, 30, 100, 20);
nameTextField = new TextField();
surnameTexField = new TextField();
passwordTextField = new TextField();
emailTextField = new TextField();
configureTextField(nameTextField, 60, "Имя");
configureTextField(surnameTexField, 100, "Фамилия");
configureTextField(passwordTextField, 140, "Пароль");
configureTextField(emailTextField, 180, "Email");
configureGenderList();
configureTextArea();
configureButton();
add(mainLabel);
}
private void configureButton() {
button = new Button("Зарегистрироваться");
button.setBounds(125, 440, 140, 20);
button.addActionListener(this);
add(button);
}
private void configureGenderList() {
Label genderLabel = new Label("Пол: ");
genderLabel.setBounds(10, 220, 35, 20);
add(genderLabel);
genderList = new List(2);
genderList.setBounds(72, 220, 80, 40);
genderList.add("Жен.");
genderList.add("Муж.");
add(genderList);
}
private void configureTextArea() {
Label aboutYourselfLabel = new Label("о себе");
aboutYourselfLabel.setBounds(176, 285, 60, 20);
add(aboutYourselfLabel);
aboutYourselfTextArea = new TextArea();
aboutYourselfTextArea.setBounds(50, 315, 300, 100);
add(aboutYourselfTextArea);
}
private void configureTextField(TextField textField, int y, String text) {
textField.setBounds(72, y, 300, 20);
Label label = new Label(text);
label.setBounds(10, y, 60, 20);
add(textField);
add(label);
}
private void writeDataInFile() {
String name = nameTextField.getText();
String surname = surnameTexField.getText();
String email = emailTextField.getText();
String gender = genderList.getSelectedItem();
try(FileWriter file = new FileWriter("file.txt", true)) {
file.write("name: " + name +
" surname " + surname +
" email " + email +
" gender " + gender);
if (!(aboutYourselfTextArea.getText().trim().isEmpty())) {
String aboutYourself = aboutYourselfTextArea.getText();
file.write(" aboutYourself: " + aboutYourself + '\n');
} else {
file.append('\n');
}
} catch(IOException ex) {
System.out.println(ex);
}
}
@Override
public void actionPerformed(ActionEvent actionEvent) {
if (!(nameTextField.getText().trim().isEmpty()) && !(surnameTexField.getText().trim().isEmpty()) &&
!(emailTextField.getText().trim().isEmpty()) && !(passwordTextField.getText().trim().isEmpty()) &&
genderList.getSelectedItem() != null) {
writeDataInFile();
dispose();
} else {
MyDialog myDialog = new MyDialog(this, "Ошибка", true, "Данные заполнены некорректно");
myDialog.setVisible(true);
}
}
@Override
public void windowOpened(WindowEvent windowEvent) {
}
@Override
public void windowClosing(WindowEvent windowEvent) {
dispose();
}
@Override
public void windowClosed(WindowEvent windowEvent) { }
@Override
public void windowIconified(WindowEvent windowEvent) { }
@Override
public void windowDeiconified(WindowEvent windowEvent) { }
@Override
public void windowActivated(WindowEvent windowEvent) { }
@Override
public void windowDeactivated(WindowEvent windowEvent) { }
}