private void btnSaveActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnSaveActionPerformed // TODO add your handling code here: if (TxtUn.getText().trim().equals("")) { JOptionPane.showMessageDialog(this, "UserName is required"); TxtUn.grabFocus(); } else if (new String(TxtPass.getPassword()).trim().equals("")) { JOptionPane.showMessageDialog(this, "Password is required"); TxtPass.grabFocus(); } else if (TxtName.getText().trim().equals("")) { JOptionPane.showMessageDialog(this, "Name is required"); TxtName.grabFocus(); } else if (TxtNumber.getText().trim().equals("")) { JOptionPane.showMessageDialog(this, "Contact is required"); TxtNumber.grabFocus(); } else if (TxtEmail.getText().trim().equals("")) { JOptionPane.showMessageDialog(this, "Email is required"); TxtEmail.grabFocus(); } else { String result = ""; Loginbean objBean = new Loginbean(); objBean.setUserID(Integer.parseInt(TxtUserId.getText())); objBean.setUserName(TxtUn.getText()); objBean.setPassword(new String(TxtPass.getPassword())); objBean.setName(TxtName.getText()); objBean.setContact(TxtNumber.getText()); objBean.setEmail(TxtEmail.getText()); objBean.setUserType(ddlUserType.getSelectedItem().toString()); objBean.setUserStatus(ddlUserStatus.getSelectedItem().toString()); if (addUpdateFlag.equalsIgnoreCase("add")) { result = objDB.addUser(objBean); } else if (addUpdateFlag.equalsIgnoreCase("Update")) { result = objDB.updateUser(objBean); } if (result.equalsIgnoreCase("added")) { JOptionPane.showMessageDialog(this, "Record added successfuly"); lst = objDB.getAllUsers(); count = lst.size() - 1; showRecord(lst.get(count)); disable(false); disableButton(true); } else if (result.equalsIgnoreCase("updated")) { JOptionPane.showMessageDialog(this, "Record updated successfuly"); lst = objDB.getAllUsers(); count = lst.size() - 1; showRecord(lst.get(count)); disable(false); disableButton(true); } else if (result.equalsIgnoreCase("exists")) { JOptionPane.showMessageDialog(this, "Record already exists"); } else { JOptionPane.showMessageDialog(this, "Operation failed"); } } } // GEN-LAST:event_btnSaveActionPerformed
public void Clear() { TxtUn.setText(""); TxtPass.setText(""); TxtName.setText(""); TxtNumber.setText(""); TxtEmail.setText(""); ddlUserType.setSelectedIndex(0); ddlUserStatus.setSelectedIndex(0); }
public void disable(boolean value) { TxtUn.setEditable(value); TxtPass.setEditable(value); TxtName.setEditable(value); TxtNumber.setEditable(value); TxtEmail.setEditable(value); ddlUserType.setEnabled(value); ddlUserStatus.setEnabled(value); }
public void showRecord(Loginbean objBean) { TxtUserId.setText(String.valueOf(objBean.getUserID())); TxtUn.setText(objBean.getUserName()); TxtPass.setText(objBean.getPassword()); TxtName.setText(objBean.getName()); TxtNumber.setText(objBean.getContact()); TxtEmail.setText(objBean.getEmail()); ddlUserType.setSelectedItem(objBean.getUserType()); ddlUserStatus.setSelectedItem(objBean.getUserStatus()); }
/** * This method is called from within the constructor to initialize the form. WARNING: Do NOT * modify this code. The content of this method is always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel3 = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); jLabel10 = new javax.swing.JLabel(); TxtUserId = new javax.swing.JTextField(); TxtUn = new javax.swing.JTextField(); TxtPass = new javax.swing.JPasswordField(); ddlUserType = new javax.swing.JComboBox(); ddlUserStatus = new javax.swing.JComboBox(); TxtName = new javax.swing.JTextField(); TxtNumber = new javax.swing.JTextField(); TxtEmail = new javax.swing.JTextField(); btnFirst = new javax.swing.JButton(); btnPrev = new javax.swing.JButton(); btnNxt = new javax.swing.JButton(); btnLast = new javax.swing.JButton(); btnAdd = new javax.swing.JButton(); btnUpdate = new javax.swing.JButton(); btnSave = new javax.swing.JButton(); btnCancel = new javax.swing.JButton(); jLabel3.setText("jLabel3"); jLabel1.setText("User Detail"); jLabel2.setText("User ID"); jLabel4.setText("Username"); jLabel5.setText("Password"); jLabel6.setText("User Type"); jLabel7.setText("User Status"); jLabel8.setText("Name"); jLabel9.setText("Contact Number"); jLabel10.setText("Email"); TxtUserId.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { TxtUserIdActionPerformed(evt); } }); TxtUn.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { TxtUnActionPerformed(evt); } }); TxtPass.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { TxtPassActionPerformed(evt); } }); ddlUserType.setModel( new javax.swing.DefaultComboBoxModel(new String[] {"Adminstrator", "Operator"})); ddlUserType.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ddlUserTypeActionPerformed(evt); } }); ddlUserStatus.setModel( new javax.swing.DefaultComboBoxModel(new String[] {"Active", "Inactive"})); ddlUserStatus.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ddlUserStatusActionPerformed(evt); } }); TxtNumber.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { TxtNumberActionPerformed(evt); } }); TxtEmail.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { TxtEmailActionPerformed(evt); } }); btnFirst.setText("First"); btnFirst.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnFirstActionPerformed(evt); } }); btnPrev.setText("Previous"); btnPrev.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnPrevActionPerformed(evt); } }); btnNxt.setText("Next"); btnNxt.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnNxtActionPerformed(evt); } }); btnLast.setText("Last"); btnLast.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnLastActionPerformed(evt); } }); btnAdd.setText("Add"); btnAdd.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnAddActionPerformed(evt); } }); btnUpdate.setText("Update"); btnUpdate.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnUpdateActionPerformed(evt); } }); btnSave.setText("Save"); btnSave.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSaveActionPerformed(evt); } }); btnCancel.setText("Cancel"); btnCancel.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCancelActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addGap(162, 162, 162) .addComponent( jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup( layout .createSequentialGroup() .addContainerGap() .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent( jLabel10, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( jLabel9, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( jLabel8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( jLabel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( jLabel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( jLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addGap(34, 34, 34) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(TxtUserId) .addComponent(TxtUn) .addComponent(TxtPass) .addComponent( ddlUserStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(TxtName) .addComponent(ddlUserType, 0, 171, Short.MAX_VALUE) .addComponent(TxtNumber) .addComponent( TxtEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 171, Short.MAX_VALUE))) .addGroup( layout .createSequentialGroup() .addContainerGap() .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnFirst) .addComponent(btnAdd)) .addGap(31, 31, 31) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnPrev) .addComponent(btnUpdate)) .addGap(29, 29, 29) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnNxt) .addComponent(btnSave)) .addGap(26, 26, 26) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnCancel) .addComponent(btnLast)))) .addContainerGap(56, Short.MAX_VALUE))); layout.setVerticalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addGap(18, 18, 18) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent( TxtUserId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel4) .addComponent( TxtUn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5) .addComponent( TxtPass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel6) .addComponent( ddlUserType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel7) .addComponent( ddlUserStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel8) .addComponent( TxtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel9) .addComponent( TxtNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel10) .addComponent( TxtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(29, 29, 29) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnFirst) .addComponent(btnPrev) .addComponent(btnNxt) .addComponent(btnLast)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnAdd) .addComponent(btnUpdate) .addComponent(btnSave) .addComponent(btnCancel)) .addContainerGap())); } // </editor-fold>//GEN-END:initComponents