Appendix
Appendix
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/**
*
* @author latifahdrupadi
*/
public class loginpage extends javax.swing.JFrame {
/**
* Creates new form loginpage
*/
public loginpage() {
initComponents();
}
public void close(){
WindowEvent closeWindow=new
WindowEvent(this,WindowEvent.WINDOW_CLOSING);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(closeWindow);
}
/**
* 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">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setIcon(new
javax.swing.ImageIcon(getClass().getResource("/childrenform/java/newpackage/mom (1)
(1).png"))); // NOI18N
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILI
NG)
.addComponent(jButton3)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILI
NG)
.addComponent(jLabel3)
.addComponent(jLabel2))
.addGap(71, 71, 71)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILI
NG)
.addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE,
150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(user, javax.swing.GroupLayout.PREFERRED_SIZE, 150,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(showpass)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton2)
.addGap(145, 145, 145)
.addComponent(jButton1)))
.addGap(77, 77, 77))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(jLabel4)
.addGap(62, 62, 62))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(247, 247, 247)
.addComponent(jLabel5)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel5)
.addGap(24, 24, 24)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addComponent(jLabel1)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASEL
INE)
.addComponent(jLabel2)
.addComponent(user, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASEL
INE)
.addComponent(jLabel3)
.addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(showpass)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASEL
INE)
.addComponent(jButton1)
.addComponent(jButton2))))
.addGap(18, 18, 18)
.addComponent(jButton3)
.addContainerGap(30, Short.MAX_VALUE))
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>
ResultSet rs = st.executeQuery(query);
while(rs.next()){
passDb = rs.getString("Password");
usr = rs.getString("Username");
notFound = 1;
}
if(notFound == 1 && Password.equals(passDb)){
this.dispose();
homepage home=new homepage(user.getText());
home.setVisible(true);
}else{
JOptionPane.showMessageDialog(new JFrame(), "Incorrect username or
password", "Error",
JOptionPane.ERROR_MESSAGE);
}
password.setText("");
}
}catch(Exception e){
System.out.println("Error!" + e.getMessage());
}
}
/**
* @param args the command line arguments
*/
public static void loginpage(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and
feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(loginpage.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(loginpage.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(loginpage.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(loginpage.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
}
//</editor-fold>
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import static javax.swing.JOptionPane.showMessageDialog;
/**
*
* @author latifahdrupadi
*/
public class registpage extends javax.swing.JFrame {
/**
* Creates new form registpage
*/
public registpage() {
initComponents();
/**
* 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">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel5.setIcon(new
javax.swing.ImageIcon(getClass().getResource("/childrenform/java/newpackage/mom (1)
(1).png"))); // NOI18N
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILI
NG, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(39, 39, 39)
.addComponent(jLabel5)
.addGap(20, 20, 20)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILI
NG)
.addComponent(showpass)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addGap(62, 62, 62)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG, false)
.addComponent(user, javax.swing.GroupLayout.DEFAULT_SIZE,
150, Short.MAX_VALUE)
.addComponent(password)))))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(97, 97, 97)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(create)
.addGap(21, 21, 21)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addGap(0, 53, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addGap(53, 53, 53))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addComponent(jLabel4)
.addGap(216, 216, 216))))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel4)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILI
NG)
.addComponent(jLabel5)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASEL
INE)
.addComponent(user, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASEL
INE)
.addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(showpass)))
.addGap(29, 29, 29)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASEL
INE)
.addComponent(create)
.addComponent(jButton2))
.addGap(40, 40, 40))
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>
pass = password.getText();
System.out.println(password);
String checkQuery = "SELECT * FROM userpass WHERE Username = '" + usr + "'";
try (ResultSet resultSet = st.executeQuery(checkQuery)) {
if (resultSet.next()) {
JOptionPane.showMessageDialog(new JFrame(), "Username already exists",
"Error",
JOptionPane.ERROR_MESSAGE);
} else {
query = "INSERT INTO userpass (Username, Password)"+
"VALUES('"+usr+"', '"+pass+"')";
st.execute(query);
user.setText("");
password.setText("");
showMessageDialog(null, "New account has been CREATED successfully!");
}}}
}catch(Exception e){
System.out.println("Error!" + e.getMessage());
}
}
/**
* @param args the command line arguments
*/
public static void registpage(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and
feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(registpage.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(registpage.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(registpage.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(registpage.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
}
//</editor-fold>
/**
*
* @author latifahdrupadi
*/
public class homepage extends javax.swing.JFrame {
/**
* Creates new form homepage
*/
public homepage(String name) {
initComponents();
user.setText(name);
}
/**
* 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">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addComponent(jLabel4)
.addComponent(jLabel3)
.addComponent(jLabel2)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(user, javax.swing.GroupLayout.PREFERRED_SIZE, 50,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addComponent(jButton1)
.addGap(51, 51, 51)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel5)
.addGap(39, 39, 39)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG, false)
.addComponent(user, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel4)
.addGap(18, 18, 18)
.addComponent(jButton1)
.addContainerGap(36, Short.MAX_VALUE))
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void homepage(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and
feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(homepage.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(homepage.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(homepage.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(homepage.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
}
//</editor-fold>
}
});
}
/**
*
* @author latifahdrupadi
*/
public class mainpage extends javax.swing.JFrame {
/**
* Creates new form mainpage
*/
public mainpage() {
initComponents();
dob.getDateEditor().setEnabled(false);
}
public void close(){
WindowEvent closeWindow=new
WindowEvent(this,WindowEvent.WINDOW_CLOSING);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(closeWindow);
}
public void addData(){
}
/**
* 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">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
tbl_add_data.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null}
},
new String [] {
"Name", "ID", "Date of Birth", "Blood Type", "Weight (kg)", "Height (cm)", "Head
Circumference (cm)", "Delivery of Birth", "Father's Name", "Mother's Name", "Address"
}
){
Class[] types = new Class [] {
java.lang.Object.class, java.lang.Integer.class, java.lang.Object.class,
java.lang.Object.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class,
java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class
};
boolean[] canEdit = new boolean [] {
false, false, false, false, false, false, false, false, false, false, false
};
id.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
idActionPerformed(evt);
}
});
dob.setDateFormatString("YYYY-MM-dd");
weight.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
weightActionPerformed(evt);
}
});
height.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
heightActionPerformed(evt);
}
});
father.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
fatherActionPerformed(evt);
}
});
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jLabel2)
.addGap(493, 493, 493)
.addComponent(refresh))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addComponent(jLabel4)
.addComponent(jLabel5)
.addComponent(jLabel3)
.addComponent(jLabel6)
.addComponent(jLabel7)
.addComponent(jLabel8)
.addComponent(jLabel9)
.addComponent(jLabel10)
.addComponent(jLabel11)
.addComponent(jLabel12)
.addComponent(jLabel13))
.addGap(43, 43, 43)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addComponent(id)
.addComponent(dob, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(blood, 0, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(wob, 0, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(weight)
.addComponent(height, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(head, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(father, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(mother, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(address, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(name, javax.swing.GroupLayout.Alignment.TRAILING))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE,
864, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addComponent(add)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(delete)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(update)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(recap)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton4)))
.addGap(34, 34, 34))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addContainerGap(536, Short.MAX_VALUE)
.addComponent(jLabel1)
.addGap(536, 536, 536))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(74, 74, 74)
.addComponent(refresh))
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(12, 12, 12)
.addComponent(jLabel2)))
.addGap(30, 30, 30)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASEL
INE)
.addComponent(id, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addComponent(dob, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASEL
INE)
.addComponent(blood,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6)))
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addComponent(weight, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASEL
INE)
.addComponent(height, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASEL
INE)
.addComponent(head, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel9))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASEL
INE)
.addComponent(wob, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel10))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASEL
INE)
.addComponent(father, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel11))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASEL
INE)
.addComponent(mother, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel12))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASEL
INE)
.addComponent(address, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel13)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE,
470, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASEL
INE)
.addComponent(jButton4)
.addComponent(add)
.addComponent(delete)
.addComponent(update)
.addComponent(recap))))
.addContainerGap(21, Short.MAX_VALUE))
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>
public boolean containsOnlyLetters(String str) {
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (!Character.isLetter(c)) {
return false;
}
}
return true;
}
public boolean containsOnlyNumbers(String str) {
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (!Character.isDigit(c)) {
return false;
}
}
return true;
}
private void addActionPerformed(java.awt.event.ActionEvent evt) {
DefaultTableModel model;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test",
"root", "");
if("".equals(name.getText())){
JOptionPane.showMessageDialog(new JFrame(), "Name is required", "Error",
JOptionPane.ERROR_MESSAGE);
return;
}
if ("".equals(id.getText())) {
JOptionPane.showMessageDialog(new JFrame(), "ID is required", "Error",
JOptionPane.ERROR_MESSAGE);
return;
} else {
String idText = id.getText().trim();
if (idText.length() > 10) {
isSuccess = false;
JOptionPane.showMessageDialog(new JFrame(), "ID can only be a maximum of
10 numbers", "Error", JOptionPane.ERROR_MESSAGE);
}
}
if (!isSuccess) {
return;
}
if ("".equals(((JTextField) dob.getDateEditor().getUiComponent()).getText())) {
JOptionPane.showMessageDialog(new JFrame(), "Date of Birth is required", "Error",
JOptionPane.ERROR_MESSAGE);
return;
}
if (blood.getSelectedIndex() == -1) {
JOptionPane.showMessageDialog(new JFrame(), "Blood Type is required", "Error",
JOptionPane.ERROR_MESSAGE);
return;
}
if ("".equals(weight.getText())) {
JOptionPane.showMessageDialog(new JFrame(), "Weight is required", "Error",
JOptionPane.ERROR_MESSAGE);
return;
}
if ("".equals(height.getText())) {
JOptionPane.showMessageDialog(new JFrame(), "Height is required", "Error",
JOptionPane.ERROR_MESSAGE);
return;
}
if ("".equals(head.getText())) {
JOptionPane.showMessageDialog(new JFrame(), "Head Circumference is required",
"Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (father.getText().trim().isEmpty()) {
JOptionPane.showMessageDialog(new JFrame(), "Father's Name is required",
"Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (mother.getText().trim().isEmpty()) {
JOptionPane.showMessageDialog(new JFrame(), "Mother's Name is required",
"Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (address.getText().trim().isEmpty()) {
JOptionPane.showMessageDialog(new JFrame(), "Address is required", "Error",
JOptionPane.ERROR_MESSAGE);
return;
}
if (wob.getSelectedIndex() == -1) {
JOptionPane.showMessageDialog(new JFrame(), "Delivery of Birth is required",
"Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (!containsOnlyLetters(name.getText().trim())) {
isSuccess = false;
JOptionPane.showMessageDialog(new JFrame(), "Name must contain only letters",
"Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (!containsOnlyNumbers(id.getText().trim())) {
isSuccess = false;
JOptionPane.showMessageDialog(new JFrame(), "ID must contain only numbers",
"Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (!containsOnlyNumbers(weight.getText().trim())) {
isSuccess = false;
JOptionPane.showMessageDialog(new JFrame(), "Weight must contain only
numbers", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (!containsOnlyNumbers(height.getText().trim())) {
isSuccess = false;
JOptionPane.showMessageDialog(new JFrame(), "Height must contain only
numbers", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (!containsOnlyNumbers(head.getText().trim())) {
isSuccess = false;
JOptionPane.showMessageDialog(new JFrame(), "Head Circumference must contain
only numbers", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (!containsOnlyLetters(father.getText().trim())) {
isSuccess = false;
JOptionPane.showMessageDialog(new JFrame(), "Father's name must contain only
letters", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (!containsOnlyLetters(mother.getText().trim())) {
isSuccess = false;
JOptionPane.showMessageDialog(new JFrame(), "Mother's name must contain only
letters", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
try {
ps.executeUpdate();
JOptionPane.showMessageDialog(null, "Data Saved!");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "ID must be unique.", "Error",
JOptionPane.ERROR_MESSAGE);
}
String selectSql = "SELECT * FROM inputdata";
try (Statement st = conn.createStatement(); ResultSet rs =
st.executeQuery(selectSql)) {
String[] columnNames = {"Name", "ID", "Date of Birth", "Blood Type",
"Weight (kg)", "Height (cm)", "Head Circumference (cm)", "Delivery of Birth", "Father's
Name", "Mother's Name", "Address"};
model = new DefaultTableModel(columnNames, 0);
while (rs.next()) {
Object[] obj = {
rs.getString("Name"),
rs.getString("ID"),
rs.getString("Day"),
rs.getString("Blood"),
rs.getString("Weight"),
rs.getString("Height"),
rs.getString("Head"),
rs.getString("Way"),
rs.getString("Father"),
rs.getString("Mother"),
rs.getString("Address")
};
model.addRow(obj);
}
tbl_add_data.setModel(model);
tbl_add_data.setDefaultEditor(Object.class, null);
tbl_add_data.setRowSelectionAllowed(true);
tbl_add_data.setColumnSelectionAllowed(false);
}
name.setText("");
id.setText("");
dob.setDate(null);
blood.setSelectedIndex(-1);
weight.setText("");
height.setText("");
head.setText("");
father.setText("");
mother.setText("");
address.setText("");
wob.setSelectedIndex(-1);
if (selectedRow != -1) {
// Get the ID of the selected row
String selectedIDString = model.getValueAt(selectedRow, 1).toString();
try {
Class.forName("com.mysql.cj.jdbc.Driver");
try (Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "")) {
// Delete data from the database
String sql = "DELETE FROM inputdata WHERE ID=?";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setString(1, selectedIDString);
int affectedRows = ps.executeUpdate();
if (affectedRows > 0) {
// Remove the selected row from the table
model.removeRow(selectedRow);
}
private void updateActionPerformed(java.awt.event.ActionEvent evt) {
DefaultTableModel tblModel = (DefaultTableModel) tbl_add_data.getModel();
int selectedRow = tbl_add_data.getSelectedRow();
if (selectedRow == -1) {
JOptionPane.showMessageDialog(this, "Please select a single row", "Error",
JOptionPane.ERROR_MESSAGE);
return;
}
String n = name.getText();
String a = (String) blood.getSelectedItem();
String ad = address.getText();
String hea = head.getText();
String hei = height.getText();
String wei = weight.getText();
String fa = father.getText();
String mo = mother.getText();
String iid = id.getText();
String wobb = (String) wob.getSelectedItem();
String dobb = ((JTextField) dob.getDateEditor().getUiComponent()).getText();
try {
// Check if weight, height, and head circumference are numeric
double weightValue = Double.parseDouble(wei);
double heightValue = Double.parseDouble(hei);
double headValue = Double.parseDouble(hea);
// Execute SQL update query to update only the selected row in the database
String updateQuery = "UPDATE inputdata SET Name=?, ID=?, Day=?, Blood=?,
Weight=?, Height=?, Head=?, Way=?, Father=?, Mother=?, Address=? WHERE ID=?";
try (Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "");
PreparedStatement ps = conn.prepareStatement(updateQuery)) {
ps.setString(1, n);
ps.setString(2, iid);
ps.setString(3, dobb);
ps.setString(4, a);
ps.setDouble(5, Double.parseDouble(wei));
ps.setDouble(6, Double.parseDouble(hei));
ps.setDouble(7, Double.parseDouble(hea));
ps.setString(8, wobb);
ps.setString(9, fa);
ps.setString(10, mo);
ps.setString(11, ad);
ps.setString(12, selectedID); // Use ID to identify the record to update
if (rowsAffected == 1) {
// Update the table model with the new values for the selected row
tblModel.setValueAt(n, selectedRow, 0);
tblModel.setValueAt(iid, selectedRow, 1);
tblModel.setValueAt(dobb, selectedRow, 2);
tblModel.setValueAt(a, selectedRow, 3);
tblModel.setValueAt(wei, selectedRow, 4);
tblModel.setValueAt(hei, selectedRow, 5);
tblModel.setValueAt(hea, selectedRow, 6);
tblModel.setValueAt(wobb, selectedRow, 7);
tblModel.setValueAt(fa, selectedRow, 8);
tblModel.setValueAt(mo, selectedRow, 9);
tblModel.setValueAt(ad, selectedRow, 10);
name.setText("");
id.setText("");
dob.setDate(null);
blood.setSelectedIndex(-1);
weight.setText("");
height.setText("");
head.setText("");
father.setText("");
mother.setText("");
address.setText("");
wob.setSelectedIndex(-1);
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, "Please enter valid numeric values for weight,
height, and head circumference", "Error", JOptionPane.ERROR_MESSAGE);
} catch (SQLException e) {
JOptionPane.showMessageDialog(this, "Error updating data: " + e.getMessage(),
"Error", JOptionPane.ERROR_MESSAGE);
}
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
close();
}
/**
* @param args the command line arguments
*/
public static void mainpage(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and
feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(mainpage.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(mainpage.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(mainpage.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(mainpage.class.getName()).log(java.util.logging.Level.S
EVERE, null, ex);
}
//</editor-fold>
}
End Page Code
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change
this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this
template
*/
package childrenform.java;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;
import javax.swing.RowFilter;
import javax.swing.table.TableRowSorter;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import java.awt.HeadlessException;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
/**
*
* @author latifahdrupadi
*/
public class endpage extends javax.swing.JFrame {
/**
* Creates new form endpage
*/
public endpage() {
initComponents();
}
public void close(){
WindowEvent closeWindow=new
WindowEvent(this,WindowEvent.WINDOW_CLOSING);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(closeWindow);
}
/**
* 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">
private void initComponents() {
tbl_add_data.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null}
},
new String [] {
"Name", "ID", "Date of Birth", "Blood Type", "Weight (kg)", "Height (cm)", "Head
Circumference", "Delivery of Birth", "Father's Name", "Mother's Name", "Address"
}
){
boolean[] canEdit = new boolean [] {
false, false, false, false, false, false, false, false, false, false, false
};
search.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
searchKeyReleased(evt);
}
});
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILI
NG)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton1)
.addGap(44, 44, 44)
.addComponent(pdf)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton4)
.addGap(34, 34, 34)
.addComponent(close))
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
jPanel1Layout.createSequentialGroup()
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(search, javax.swing.GroupLayout.PREFERRED_SIZE, 176,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel1)))
.addGap(65, 65, 65))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(416, 416, 416)
.addComponent(jLabel2)
.addContainerGap(416, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2)
.addGap(48, 48, 48)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASEL
INE)
.addComponent(jButton3)
.addComponent(search, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 487,
Short.MAX_VALUE)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASEL
INE)
.addComponent(jButton1)
.addComponent(pdf)
.addComponent(close)
.addComponent(jButton4))
.addGap(27, 27, 27))
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>
try {
PdfWriter.getInstance(document, new FileOutputStream("Children Data.pdf"));
document.open();
sorter.setRowFilter(filter);
} catch (NumberFormatException e) {
// If the input is not a number, use RowFilter.regexFilter for text
sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text)); // (?i) for case-insensitive
matching
}
}
/**
* @param args the command line arguments
*/
public static void endpage(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and
feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(endpage.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(endpage.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(endpage.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(endpage.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);
}
//</editor-fold>