/* File Name: UserCreation.java */ package explorer.server.gui; import javax.swing.*; import explorer.server.User; /** * GUI for new user creation, contains fields to get the user attributes such as * User Name * Password * Description * Client IP Address */ public class UserCreation extends JFrame { public UserCreation() { initComponents(); AdminLogin login=new AdminLogin(this); login.setModal(true); login.setVisible(true); if(!login.authendicated) System.exit(0); this.setBounds(150,150,400,400); } private void initComponents() { lblHead = new JLabel(); lblUserName = new JLabel(); lblPass1 = new JLabel(); lblPass2 = new JLabel(); lblIP = new JLabel(); lblDes = new JLabel(); txtUserID = new JTextField(); txtDescription = new JTextField(); txtIPAddress = new JTextField(); txtPassword1 = new JPasswordField(); txtPassword2 = new JPasswordField(); cmdOK = new JButton(); cmdCancel = new JButton(); getContentPane().setLayout(null); setTitle("UserName and Password"); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { exitForm(evt); } }); lblHead.setHorizontalAlignment(SwingConstants.CENTER); lblHead.setText("New User Creation"); getContentPane().add(lblHead); lblHead.setBounds(70, 30, 270, 16); lblUserName.setText("User Name"); getContentPane().add(lblUserName); lblUserName.setBounds(50, 90, 63, 16); lblPass1.setText("Password"); getContentPane().add(lblPass1); lblPass1.setBounds(50, 170, 58, 16); lblPass2.setText("ReEnter Password"); getContentPane().add(lblPass2); lblPass2.setBounds(50, 210, 106, 16); lblIP.setText("IPAddress"); getContentPane().add(lblIP); lblIP.setBounds(50, 250, 110, 16); lblDes.setText("Description"); getContentPane().add(lblDes); lblDes.setBounds(50, 130, 65, 20); txtUserID.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmdOKActionPerformed(evt); } }); getContentPane().add(txtUserID); txtUserID.setBounds(210, 90, 140, 20); txtDescription.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmdOKActionPerformed(evt); } }); getContentPane().add(txtDescription); txtDescription.setBounds(210, 130, 140, 20); txtIPAddress.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmdOKActionPerformed(evt); } }); getContentPane().add(txtIPAddress); txtIPAddress.setBounds(210, 250, 140, 20); txtPassword1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmdOKActionPerformed(evt); } }); getContentPane().add(txtPassword1); txtPassword1.setBounds(210, 170, 140, 20); txtPassword2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmdOKActionPerformed(evt); } }); getContentPane().add(txtPassword2); txtPassword2.setBounds(210, 210, 140, 20); cmdOK.setText("OK"); cmdOK.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmdOKActionPerformed(evt); } }); getContentPane().add(cmdOK); cmdOK.setBounds(110, 320, 51, 26); cmdCancel.setText("Cancel"); cmdCancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmdCancelActionPerformed(evt); } }); getContentPane().add(cmdCancel); cmdCancel.setBounds(230, 320, 73, 26); pack(); } private void cmdCancelActionPerformed(java.awt.event.ActionEvent evt) { System.exit(0); } private void cmdOKActionPerformed(java.awt.event.ActionEvent evt) { if(!txtPassword1.getText().equals(txtPassword2.getText())) { JOptionPane.showMessageDialog(this,"Enter the correct Password"); return; } try { User usr=new User(txtUserID.getText(), txtDescription.getText(), txtIPAddress.getText()); usr.setPassword(txtPassword1.getText()); if(User.createUser(usr)) { int status = JOptionPane.showConfirmDialog(this, "New User is Created\n"+ "Do you want create another User?", "Another User", JOptionPane.YES_NO_OPTION); if(status==JOptionPane.YES_OPTION) { txtUserID.setText(""); txtDescription.setText(""); txtPassword1.setText(""); txtPassword2.setText(""); txtIPAddress.setText(""); } else { System.exit(0); } } } catch(Exception e) { JOptionPane.showMessageDialog(this,e.getMessage()); } } private void exitForm(java.awt.event.WindowEvent evt) { System.exit(0); } public static void main(String args[]) { new UserCreation().setVisible(true); } private JLabel lblUserName; private JPasswordField txtPassword1; private JLabel lblHead; private JButton cmdOK; private JLabel lblDes; private JTextField txtUserID; private JLabel lblIP; private JTextField txtIPAddress; private JButton cmdCancel; private JLabel lblPass2; private JTextField txtDescription; private JLabel lblPass1; private JPasswordField txtPassword2; }