-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUIKontoInformation.java
executable file
·181 lines (146 loc) · 6.53 KB
/
GUIKontoInformation.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.*;
import java.io.*;
/*
* Version 2.0
* Matthias Guenther
* speichert Infos ueber die Benutzer ab
*/
public class GUIKontoInformation extends GUIMain implements ActionListener {
private JPanel complete, emailadress, username, uservalidationname,
userpass, postentrance, postexit, check;
public JTextField portin, postex;
public JTextField emailadressinput = new JTextField(25);
public JTextField usernameinput = new JTextField(25);
public JTextField uservalidationnameinput = new JTextField(25);
public JTextField userpassinput = new JTextField(25);
public JTextField postentranceinput = new JTextField(25);
public JTextField postexitinput = new JTextField(25);
private JCheckBox save;
private JButton ok, abort;
private JFrame kontoInformationFame;
public String informations;
private boolean saveInformation = false;
// constructor to get login-information
public void GUIKontoInformationCreate() {
// create the main frame
kontoInformationFame = new JFrame("Email-Client");
// to exit the frame when the x is pressed
kontoInformationFame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
kontoInformationFame.setSize(500, 450);
emailadress = new JPanel(new FlowLayout(FlowLayout.LEFT));
emailadress.add(new JLabel("email Adresse"));
emailadress.add(emailadressinput);
username = new JPanel(new FlowLayout(FlowLayout.LEFT));
username.add(new JLabel("Name:"));
username.add(usernameinput);
uservalidationname = new JPanel(new FlowLayout(FlowLayout.LEFT));
uservalidationname.add(new JLabel("Benutzererkennung:"));
uservalidationname.add(uservalidationnameinput);
userpass = new JPanel(new FlowLayout(FlowLayout.LEFT));
save = new JCheckBox("Passwort speichern");
save.addItemListener(new CheckBoxListener());
userpass.add(new JLabel("Passwort:"));
userpass.add(userpassinput);
userpass.add(save);
postentrance = new JPanel(new FlowLayout(FlowLayout.LEFT));
portin = new JTextField(6);
portin.setText("110");
postentrance.add(new JLabel("Posteingang:"));
postentrance.add(postentranceinput);
postentrance.add(new JLabel("Port:"));
postentrance.add(portin);
postexit = new JPanel(new FlowLayout(FlowLayout.LEFT));
postexit.add(new JLabel("Postausgang:"));
postex = new JTextField(6);
postex.setText("10");
postexit.add(postexitinput);
postexit.add(new JLabel("Port:"));
postexit.add(postex);
// create the buttons for ok and abort
check = new JPanel(new FlowLayout(FlowLayout.CENTER));
ok = new JButton("Ok");
ok.addActionListener(this);
abort = new JButton("Abbrechen");
abort.addActionListener(this);
check.add(ok);
check.add(abort);
// create a great panel complete which contain all other panels
complete = new JPanel(new GridLayout(8, 1));
complete.add(new JLabel("Benutzerdaten eingeben: "));
complete.add(emailadress);
complete.add(username);
complete.add(uservalidationname);
complete.add(userpass);
complete.add(postentrance);
complete.add(postexit);
complete.add(check);
// add the great panel complete to the frame
kontoInformationFame.add(complete);
kontoInformationFame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
Object obj = e.getSource();
if (obj == ok) {
if (saveInformation == true) {
saveUserInfo();
writeUserInfo();
kontoInformationFame.setVisible(false);
} else {
writeUserInfo();
kontoInformationFame.setVisible(false);
}
}
if (obj == abort) {
kontoInformationFame.setVisible(false);
}
}
// action listener if the Account Infos should be saved permanetly
class CheckBoxListener implements ItemListener {
public void itemStateChanged(ItemEvent evt) {
saveInformation = save.isSelected();
}
}
// write the user infos in the global array
public void writeUserInfo() {
String emailadressin = emailadressinput.getText();
String usernamein = usernameinput.getText();
String uservalidationnamein = uservalidationnameinput.getText();
String userpassin = userpassinput.getText();
String postentrancein = postentranceinput.getText();
String postinprt = portin.getText();
String postexitin = postexitinput.getText();
String postexitprt = postex.getText();
informations = emailadressin + "#######" + usernamein + "#######" + uservalidationnamein + "#######" + userpassin + "#######" + postentrancein + "#######" + postinprt + "#######" + postexitin + "#######" + postexitprt;
userInfos = informations.split("#######");
}
public void saveUserInfo() {
File userName = new File(userInfos[1]);
userName.mkdir();
String emailadressin = emailadressinput.getText();
String usernamein = usernameinput.getText();
String uservalidationnamein = uservalidationnameinput.getText();
String userpassin = userpassinput.getText();
String postentrancein = postentranceinput.getText();
String postinprt = portin.getText();
String postexitin = postexitinput.getText();
String postexitprt = postex.getText();
String tmp = "";
tmp = emailadressin + "#######" + usernamein + "#######" + uservalidationnamein + "#######" + userpassin + "#######" + postentrancein + "#######" + postinprt + "#######" + postexitin + "#######" + postexitprt;
try {
FileWriter fw = new FileWriter(usernameinput.getText() + " kontoinfos.kondat");
fw.write(tmp);
fw.close();
} catch (IOException msg) {
System.err.println("Cannot create file");
}
}
public static void main(String[] args) {
GUIKontoInformation test = new GUIKontoInformation();
test.GUIKontoInformationCreate();
}
}