blob: 846748c49b893c449c3f53fd083419de24b6443b (
plain)
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
|
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* @author Andreas Spirka, Sven Eisenhauer
* Klasse zum Anlegen der Benutzer
*
*/
public class AdminDlg extends AbstractMyJDlg {
Container c;
JPanel pTop = new JPanel();
JPanel pCenter = new JPanel();
JPanel pBottom = new JPanel();
JLabel l = new JLabel("login");
JLabel pw1 = new JLabel ("password");
JLabel pw2 = new JLabel ("password Best�tigung");
JTextField tf = new JTextField(12);
JTextField pf1 = new JTextField(12);
JTextField pf2 = new JTextField(12);
JLabel labName = new JLabel ("Name");
JTextField fullName = new JTextField(24);
JLabel labRolle = new JLabel ("Rolle");
JComboBox rolle = new JComboBox(User.sRole);
JButton okB = new JButton("OK");
JButton abbrB = new JButton("Abbrechen");
UserCon userCon = new UserCon();
String fName = new String ("user.dat");
/**
* Konstruktor
*/
public AdminDlg() {
setSize(250,165);
setModal(true);
c = getContentPane();
getRootPane().setDefaultButton(okB);
c.setLayout( new GridLayout(6, 0,1,1 ) );
ButtonListener2 bl = new ButtonListener2(this);
okB.addActionListener(bl);
okB.setActionCommand("submitUser");
abbrB.addActionListener(bl);
abbrB.setActionCommand("abbrechen");
c.add(l);
c.add(tf);
c.add(pw1);
c.add(pf1);
c.add(pw2);
c.add(pf2);
c.add(labName);
c.add(fullName);
c.add(labRolle);
c.add(rolle);
c.add(okB);
c.add(abbrB);
setTitle("Neuen Benutzer anlegen");
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = getSize();
setLocation((screenSize.width/2)-(frameSize.width/2),(screenSize.height/2)-(frameSize.height/2));
setVisible(true);
}
public void buttonActionPerformed( ActionEvent e )
{
if (e.getActionCommand().equals("abbrechen"))
{
this.dispose();
}
if (e.getActionCommand().equals("submitUser"))
{
if (pf1.getText().equals(pf2.getText()))
{
File myFile = new File(fName);
if(myFile.exists())
{
try {
FileInputStream fis = new FileInputStream(fName);
ObjectInputStream ois = new ObjectInputStream(fis);
userCon = (UserCon) ois.readObject();
ois.close();
fis.close();
} catch (Exception exception) { exception.printStackTrace(); }
}
else
userCon = new UserCon();
User newUser = new User(tf.getText(),
pf1.getText(),
fullName.getText(),
userCon.size(),
rolle.getSelectedIndex());
userCon.addUser(newUser);
try {
FileOutputStream fos = new FileOutputStream(fName);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(userCon);
oos.close();
fos.close();
} catch (Exception exception) { exception.printStackTrace(); }
}
this.dispose();
}//end if0 get.source
}//buttonActionPerformed
}//end class AdminDlg
|