import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; /** * @author Andreas Spirka, Sven Eisenhauer * Benutzerauthentifizierungsdialog */ public class PwDialog extends AbstractMyJDlg { Container c; JPanel pTop = new JPanel(); JPanel pCenter = new JPanel(); JPanel pBottom = new JPanel(); JLabel l = new JLabel("login"); JLabel pw = new JLabel ("password"); JTextField tf = new JTextField(12); JPasswordField pf = new JPasswordField(12); JButton okB = new JButton("OK"); JButton abbrB = new JButton("Abbrechen"); User authUser = new User("gast","gast","Gast",1024,User.ROLE_GUEST);; String fName = new String ("user.dat"); /** * Konstruktor * @param owner * @param title * @param modal */ public PwDialog(Frame owner, String title, boolean modal) { setSize(240,110); this.setResizable(false); setModal(modal); c = getContentPane(); getRootPane().setDefaultButton(okB); //mit Eingabetaste bestätigen c.setLayout( new GridLayout(3, 2,6,3 ) ); ButtonListener2 bl = new ButtonListener2(this); okB.addActionListener(bl); okB.setActionCommand("submitPW"); abbrB.addActionListener(bl); abbrB.setActionCommand("abbrechen"); c.add(l); c.add(tf); c.add(pw); c.add(pf); c.add(okB); c.add(abbrB); setTitle(title); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = getSize(); setLocation((screenSize.width/2)-(frameSize.width/2),(screenSize.height/2)-(frameSize.height/2)); setVisible(true); } /* (non-Javadoc) * @see AbstractMyJDlg#buttonActionPerformed(java.awt.event.ActionEvent) */ public void buttonActionPerformed( ActionEvent e ) { if (e.getActionCommand().equals("abbrechen")) { this.dispose(); } if (e.getActionCommand().equals("submitPW")) { String name= new String(tf.getText()); String pw= new String(pf.getPassword()); UserCon userCon; File myFile = new File(fName); if(!myFile.exists()) { userCon = new UserCon(); userCon.addUser(new User("adm","adm","Administrator",0,3)); try { FileOutputStream fos = new FileOutputStream(fName); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(userCon); oos.close(); fos.close(); } catch (Exception exception) { exception.printStackTrace(); } } try { FileInputStream fis = new FileInputStream(fName); ObjectInputStream ois = new ObjectInputStream(fis); userCon = (UserCon) ois.readObject(); ois.close(); fis.close(); for (int i=0;i