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