You are on page 1of 9

import javax.swing.

DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author HUY
*/
public class Registration extends javax.swing.JFrame {
/**
* Creates new form Registration
*/
private Account account;
private int sex;
private String[] experiences;
public Registration() {
initComponents();
Session.setServerName("HUY-PC");
Session.setPort("1433");
Session.setDatabaseName("DBSJ");
Session.setUserID("sa");
Session.setPassword("sa");
new Login(this, true).setVisible(true);
//Begin----------------------------------------------------------------bgpSex.add(rdoMale);
bgpSex.add(rdoFemale);
//End------------------------------------------------------------------//Begin----------------------------------------------------------------String[] location = {"Cn Th", "Long An", "Tin Giang", "Bn Tre",
"Vnh Long", "Tr Vinh", "Hu Giang", "Sc Trng",
"ng Thp", "An Giang", "Kin Giang", "Bc Liu",
"C Mau"};
DefaultComboBoxModel mdlLocation = new DefaultComboBoxModel(location);
cbxLocation.setModel(mdlLocation);
//End------------------------------------------------------------------//Begin----------------------------------------------------------------account = new Account();
sex = 1;
experiences = new String[] {"", "", ""};
//End------------------------------------------------------------------txtUserName.requestFocus();
}
/**
* 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:i
nitComponents
private void initComponents() {
bgpSex = new javax.swing.ButtonGroup();
lblFormTitle = new javax.swing.JPanel();
lblUserName = new javax.swing.JLabel();
txtUserName = new javax.swing.JTextField();
lblPassword = new javax.swing.JLabel();
txtPassword = new javax.swing.JPasswordField();
lblAge = new javax.swing.JLabel();
txtAge = new javax.swing.JTextField();
lblSex = new javax.swing.JLabel();
rdoMale = new javax.swing.JRadioButton();
rdoFemale = new javax.swing.JRadioButton();
lblExperiences = new javax.swing.JLabel();
chkXML = new javax.swing.JCheckBox();
chkJava = new javax.swing.JCheckBox();
chkNET = new javax.swing.JCheckBox();
lblLocation = new javax.swing.JLabel();
cbxLocation = new javax.swing.JComboBox();
btnSave = new javax.swing.JButton();
btnReset = new javax.swing.JButton();
btnExit = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setMaximumSize(new java.awt.Dimension(317, 268));
setMinimumSize(new java.awt.Dimension(317, 268));
setResizable(false);
lblFormTitle.setBorder(javax.swing.BorderFactory.createTitledBorder(null
, "REGISTRATION", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.s
wing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font(".VnTime", 1, 24)))
; // NOI18N
lblUserName.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
lblUserName.setText("User name");
lblPassword.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
lblPassword.setText("Password");
lblAge.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
lblAge.setText("Age");
lblSex.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
lblSex.setText("Sex");
rdoMale.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
rdoMale.setSelected(true);
rdoMale.setText("Male");
rdoMale.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rdoMaleActionPerformed(evt);
}
});

rdoFemale.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N


rdoFemale.setText("Female");
rdoFemale.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rdoFemaleActionPerformed(evt);
}
});
lblExperiences.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
lblExperiences.setText("Experiences");
chkXML.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
chkXML.setText("XML");
chkXML.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chkXMLActionPerformed(evt);
}
});
chkJava.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
chkJava.setText("Java");
chkJava.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chkJavaActionPerformed(evt);
}
});
chkNET.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
chkNET.setText(".NET");
chkNET.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chkNETActionPerformed(evt);
}
});
lblLocation.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
lblLocation.setText("Location");
cbxLocation.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
"Item 1", "Item 2", "Item 3", "Item 4" }));
btnSave.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
btnSave.setText("Save");
btnSave.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSaveActionPerformed(evt);
}
});
btnReset.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
btnReset.setText("Reset");
btnReset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnResetActionPerformed(evt);
}
});
btnExit.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
btnExit.setText("Exit");
btnExit.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {


btnExitActionPerformed(evt);
}
});
javax.swing.GroupLayout lblFormTitleLayout = new javax.swing.GroupLayout
(lblFormTitle);
lblFormTitle.setLayout(lblFormTitleLayout);
lblFormTitleLayout.setHorizontalGroup(
lblFormTitleLayout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addGroup(lblFormTitleLayout.createSequentialGroup()
.addContainerGap()
.addGroup(lblFormTitleLayout.createParallelGroup(javax.swing.Gro
upLayout.Alignment.LEADING)
.addGroup(lblFormTitleLayout.createSequentialGroup()
.addGroup(lblFormTitleLayout.createParallelGroup(javax.s
wing.GroupLayout.Alignment.LEADING)
.addComponent(lblAge)
.addComponent(lblSex)
.addComponent(lblExperiences)
.addComponent(lblLocation))
.addGroup(lblFormTitleLayout.createParallelGroup(javax.s
wing.GroupLayout.Alignment.LEADING)
.addGroup(lblFormTitleLayout.createSequentialGroup()
.addGap(6, 6, 6)
.addGroup(lblFormTitleLayout.createParallelGroup
(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(lblFormTitleLayout.createSequentia
lGroup()
.addGroup(lblFormTitleLayout.createParal
lelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(chkXML)
.addComponent(rdoMale))
.addGap(18, 18, 18)
.addGroup(lblFormTitleLayout.createParal
lelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(rdoFemale)
.addGroup(lblFormTitleLayout.createS
equentialGroup()
.addComponent(chkJava)
.addGap(18, 18, 18)
.addComponent(chkNET))))
.addGroup(lblFormTitleLayout.createSequentia
lGroup()
.addComponent(btnSave, javax.swing.Group
Layout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle
.ComponentPlacement.RELATED)
.addComponent(btnReset)
.addPreferredGap(javax.swing.LayoutStyle
.ComponentPlacement.RELATED)
.addComponent(btnExit))
.addComponent(cbxLocation, javax.swing.Group
Layout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VA
LUE)))
.addGroup(lblFormTitleLayout.createSequentialGroup()
.addGap(11, 11, 11)
.addComponent(txtAge, javax.swing.GroupLayout.PR
EFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE))))

.addGroup(lblFormTitleLayout.createSequentialGroup()
.addGroup(lblFormTitleLayout.createParallelGroup(javax.s
wing.GroupLayout.Alignment.LEADING)
.addComponent(lblUserName)
.addComponent(lblPassword))
.addGap(18, 18, 18)
.addGroup(lblFormTitleLayout.createParallelGroup(javax.s
wing.GroupLayout.Alignment.LEADING)
.addComponent(txtPassword, javax.swing.GroupLayout.P
REFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtUserName, javax.swing.GroupLayout.P
REFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX
_VALUE))
);
lblFormTitleLayout.setVerticalGroup(
lblFormTitleLayout.createParallelGroup(javax.swing.GroupLayout.Align
ment.LEADING)
.addGroup(lblFormTitleLayout.createSequentialGroup()
.addGap(20, 20, 20)
.addGroup(lblFormTitleLayout.createParallelGroup(javax.swing.Gro
upLayout.Alignment.BASELINE)
.addComponent(lblUserName)
.addComponent(txtUserName, javax.swing.GroupLayout.PREFERRED
_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_S
IZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRE
LATED)
.addGroup(lblFormTitleLayout.createParallelGroup(javax.swing.Gro
upLayout.Alignment.BASELINE)
.addComponent(lblPassword)
.addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED
_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_S
IZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRE
LATED)
.addGroup(lblFormTitleLayout.createParallelGroup(javax.swing.Gro
upLayout.Alignment.BASELINE)
.addComponent(lblAge)
.addComponent(txtAge, javax.swing.GroupLayout.PREFERRED_SIZE
, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRE
LATED)
.addGroup(lblFormTitleLayout.createParallelGroup(javax.swing.Gro
upLayout.Alignment.BASELINE)
.addComponent(lblSex)
.addComponent(rdoMale)
.addComponent(rdoFemale))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRE
LATED)
.addGroup(lblFormTitleLayout.createParallelGroup(javax.swing.Gro
upLayout.Alignment.BASELINE)
.addComponent(lblExperiences)
.addComponent(chkXML)
.addComponent(chkJava)
.addComponent(chkNET))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRE
LATED)
.addGroup(lblFormTitleLayout.createParallelGroup(javax.swing.Gro
upLayout.Alignment.BASELINE)

.addComponent(lblLocation)
.addComponent(cbxLocation, javax.swing.GroupLayout.PREFERRED
_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_S
IZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addGroup(lblFormTitleLayout.createParallelGroup(javax.swing.Gro
upLayout.Alignment.BASELINE)
.addComponent(btnSave)
.addComponent(btnReset)
.addComponent(btnExit)))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentP
ane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(lblFormTitle, javax.swing.GroupLayout.PREFERRED_SI
ZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE
)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(lblFormTitle, javax.swing.GroupLayout.PREFERRED_SI
ZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE
)
.addContainerGap())
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>//GEN-END:initComponents
private void resetForm() {
txtUserName.setText("");
txtPassword.setText("");
txtAge.setText("");
rdoMale.setSelected(true);
chkXML.setSelected(false);
chkJava.setSelected(false);
chkNET.setSelected(false);
cbxLocation.setSelectedIndex(0);
txtUserName.requestFocus();
}
private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F
IRST:event_btnSaveActionPerformed
if(!Utility.isEmpty(txtUserName.getText(), "User name")) {
if(!Utility.isOverFlow(txtUserName.getText(), 20, "User name")) {
if(!Utility.isEmpty(new String(txtPassword.getPassword()), "Pass
word")) {
if(!Utility.isOverFlow(new String(txtPassword.getPassword())

, 20, "Password")) {
if(!Utility.isEmpty(txtAge.getText(), "Age")) {
if(!Utility.isNaN(txtAge.getText(), "Age")) {
if(account.checkPK(txtUserName.getText())) {
account.insert(txtUserName.getText(),
new String(txtPassword.getPas
sword()),
Integer.parseInt(txtAge.getTe
xt()),
sex,
experiences[0] + experiences[
1] + experiences[2],
cbxLocation.getSelectedItem()
.toString());
JOptionPane.showMessageDialog(this, "Insert
successfully", null, JOptionPane.INFORMATION_MESSAGE);
resetForm();
}
}
}
}
}
}
}
}//GEN-LAST:event_btnSaveActionPerformed
private void rdoMaleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F
IRST:event_rdoMaleActionPerformed
sex = 1;
}//GEN-LAST:event_rdoMaleActionPerformed
private void rdoFemaleActionPerformed(java.awt.event.ActionEvent evt) {//GEN
-FIRST:event_rdoFemaleActionPerformed
sex = 2;
}//GEN-LAST:event_rdoFemaleActionPerformed
private void chkXMLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
RST:event_chkXMLActionPerformed
if(chkXML.isSelected()) {
experiences[0] = "XML";
}
else {
experiences[0] = "";
}
}//GEN-LAST:event_chkXMLActionPerformed
private void chkJavaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F
IRST:event_chkJavaActionPerformed
if(chkJava.isSelected()) {
experiences[1] = ", Java";
}
else {
experiences[1] = "";
}
}//GEN-LAST:event_chkJavaActionPerformed
private void chkNETActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
RST:event_chkNETActionPerformed
if(chkNET.isSelected()) {
experiences[2] = ", .NET";

}
else {
experiences[2] = "";
}
}//GEN-LAST:event_chkNETActionPerformed
private void btnResetActionPerformed(java.awt.event.ActionEvent evt) {//GENFIRST:event_btnResetActionPerformed
resetForm();
}//GEN-LAST:event_btnResetActionPerformed
private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F
IRST:event_btnExitActionPerformed
System.exit(0);
}//GEN-LAST:event_btnExitActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting cod
e (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the d
efault look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lo
okandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIMana
ger.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Registration.class.getName()).log
(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Registration.class.getName()).log
(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Registration.class.getName()).log
(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Registration.class.getName()).log
(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Registration().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables

private javax.swing.ButtonGroup bgpSex;


private javax.swing.JButton btnExit;
private javax.swing.JButton btnReset;
private javax.swing.JButton btnSave;
private javax.swing.JComboBox cbxLocation;
private javax.swing.JCheckBox chkJava;
private javax.swing.JCheckBox chkNET;
private javax.swing.JCheckBox chkXML;
private javax.swing.JLabel lblAge;
private javax.swing.JLabel lblExperiences;
private javax.swing.JPanel lblFormTitle;
private javax.swing.JLabel lblLocation;
private javax.swing.JLabel lblPassword;
private javax.swing.JLabel lblSex;
private javax.swing.JLabel lblUserName;
private javax.swing.JRadioButton rdoFemale;
private javax.swing.JRadioButton rdoMale;
private javax.swing.JTextField txtAge;
private javax.swing.JPasswordField txtPassword;
private javax.swing.JTextField txtUserName;
// End of variables declaration//GEN-END:variables
}

You might also like