Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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.
- */
- package student.registry;
- import java.awt.Image;
- import java.awt.Toolkit;
- import java.sql.*;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.*;
- import net.proteanit.sql.DbUtils;
- public class StudentRegistry extends javax.swing.JFrame {
- Connection con;
- PreparedStatement pst;
- ResultSet rs;
- public StudentRegistry() {
- initComponents();
- this.setResizable(false);
- this.setSize(931, 569);
- this.setLocation(400, 100);
- try {
- con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sample","root","");
- String sql = "SELECT * FROM studentinfo";
- pst = con.prepareStatement(sql);
- rs = pst.executeQuery();
- tableData.setModel(DbUtils.resultSetToTableModel(rs));
- } catch (SQLException ex) {
- Logger.getLogger(StudentRegistry.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- /**
- * 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() {
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- jLabel4 = new javax.swing.JLabel();
- jLabel5 = new javax.swing.JLabel();
- jLabel6 = new javax.swing.JLabel();
- jTextField1 = new javax.swing.JTextField();
- txtFName = new javax.swing.JTextField();
- txtLName = new javax.swing.JTextField();
- txtGLevel = new javax.swing.JTextField();
- txtSection = new javax.swing.JTextField();
- txtCNumber = new javax.swing.JTextField();
- btnCreate = new javax.swing.JButton();
- btnUpdate = new javax.swing.JButton();
- btnDelete = new javax.swing.JButton();
- jScrollPane1 = new javax.swing.JScrollPane();
- tableData = new javax.swing.JTable();
- jLabel7 = new javax.swing.JLabel();
- jLabel8 = new javax.swing.JLabel();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setMaximumSize(new java.awt.Dimension(931, 569));
- setMinimumSize(new java.awt.Dimension(931, 569));
- getContentPane().setLayout(null);
- jLabel1.setBackground(new java.awt.Color(255, 0, 102));
- jLabel1.setFont(new java.awt.Font("Lucida Sans Typewriter", 3, 18)); // NOI18N
- jLabel1.setForeground(new java.awt.Color(255, 255, 255));
- jLabel1.setText("ID");
- getContentPane().add(jLabel1);
- jLabel1.setBounds(39, 59, 150, 50);
- jLabel2.setBackground(new java.awt.Color(255, 0, 102));
- jLabel2.setFont(new java.awt.Font("Lucida Sans Typewriter", 3, 18)); // NOI18N
- jLabel2.setForeground(new java.awt.Color(255, 255, 255));
- jLabel2.setText("FIRST NAME");
- getContentPane().add(jLabel2);
- jLabel2.setBounds(39, 88, 150, 50);
- jLabel3.setBackground(new java.awt.Color(255, 0, 102));
- jLabel3.setFont(new java.awt.Font("Lucida Sans Typewriter", 3, 18)); // NOI18N
- jLabel3.setForeground(new java.awt.Color(255, 255, 255));
- jLabel3.setText("LAST NAME");
- getContentPane().add(jLabel3);
- jLabel3.setBounds(39, 117, 150, 50);
- jLabel4.setBackground(new java.awt.Color(255, 0, 102));
- jLabel4.setFont(new java.awt.Font("Lucida Sans Typewriter", 3, 18)); // NOI18N
- jLabel4.setForeground(new java.awt.Color(255, 255, 255));
- jLabel4.setText("GRADE LEVEL");
- getContentPane().add(jLabel4);
- jLabel4.setBounds(39, 146, 150, 50);
- jLabel5.setBackground(new java.awt.Color(255, 0, 102));
- jLabel5.setFont(new java.awt.Font("Lucida Sans Typewriter", 3, 18)); // NOI18N
- jLabel5.setForeground(new java.awt.Color(255, 255, 255));
- jLabel5.setText("SECTION");
- getContentPane().add(jLabel5);
- jLabel5.setBounds(39, 175, 150, 50);
- jLabel6.setBackground(new java.awt.Color(255, 0, 102));
- jLabel6.setFont(new java.awt.Font("Lucida Sans Typewriter", 3, 18)); // NOI18N
- jLabel6.setForeground(new java.awt.Color(255, 255, 255));
- jLabel6.setText("CLASS NUMBER");
- getContentPane().add(jLabel6);
- jLabel6.setBounds(39, 204, 150, 50);
- jTextField1.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 18)); // NOI18N
- jTextField1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1ActionPerformed(evt);
- }
- });
- getContentPane().add(jTextField1);
- jTextField1.setBounds(180, 70, 180, 30);
- txtFName.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 18)); // NOI18N
- txtFName.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txtFNameActionPerformed(evt);
- }
- });
- getContentPane().add(txtFName);
- txtFName.setBounds(180, 90, 180, 30);
- txtLName.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 18)); // NOI18N
- txtLName.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txtLNameActionPerformed(evt);
- }
- });
- getContentPane().add(txtLName);
- txtLName.setBounds(180, 120, 180, 30);
- txtGLevel.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 18)); // NOI18N
- txtGLevel.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txtGLevelActionPerformed(evt);
- }
- });
- getContentPane().add(txtGLevel);
- txtGLevel.setBounds(180, 150, 180, 30);
- txtSection.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 18)); // NOI18N
- txtSection.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txtSectionActionPerformed(evt);
- }
- });
- getContentPane().add(txtSection);
- txtSection.setBounds(180, 180, 180, 30);
- txtCNumber.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 18)); // NOI18N
- txtCNumber.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txtCNumberActionPerformed(evt);
- }
- });
- getContentPane().add(txtCNumber);
- txtCNumber.setBounds(180, 220, 180, 30);
- btnCreate.setText("CREATE");
- btnCreate.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnCreateActionPerformed(evt);
- }
- });
- getContentPane().add(btnCreate);
- btnCreate.setBounds(79, 312, 71, 23);
- btnUpdate.setText("UPDATE");
- getContentPane().add(btnUpdate);
- btnUpdate.setBounds(193, 312, 71, 23);
- btnDelete.setText("DELETE");
- getContentPane().add(btnDelete);
- btnDelete.setBounds(297, 312, 69, 23);
- tableData.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- {null, null, null, null},
- {null, null, null, null},
- {null, null, null, null},
- {null, null, null, null}
- },
- new String [] {
- "Title 1", "Title 2", "Title 3", "Title 4"
- }
- ));
- jScrollPane1.setViewportView(tableData);
- getContentPane().add(jScrollPane1);
- jScrollPane1.setBounds(440, 50, 452, 402);
- getContentPane().add(jLabel7);
- jLabel7.setBounds(193, 433, 0, 0);
- jLabel8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/student/registry/tite.jpeg"))); // NOI18N
- jLabel8.setMaximumSize(new java.awt.Dimension(931, 569));
- jLabel8.setMinimumSize(new java.awt.Dimension(931, 569));
- jLabel8.setPreferredSize(new java.awt.Dimension(931, 569));
- getContentPane().add(jLabel8);
- jLabel8.setBounds(0, 0, 930, 570);
- pack();
- }// </editor-fold>
- private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void txtFNameActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void txtLNameActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void txtGLevelActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void txtSectionActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void txtCNumberActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void btnCreateActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- String sql = "INSERT INTO studentinfo" + "(FIRSTNAME, LASTNAME, GRADELEVEL, SECTION, CN)" + "VALUES (?,?,?,?,?)";
- con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sample","root","");
- pst = con.prepareStatement(sql);
- pst.setString(1 , txtFName.getText());
- pst.setString(2 , txtLName.getText());
- pst.setString(3 , txtGLevel.getText());
- pst.setString(4 , txtSection.getText());
- pst.setString(5 , txtCNumber.getText());
- pst.executeUpdate();
- JOptionPane.showMessageDialog(this, "Added Successfully");
- } catch (SQLException ex) {
- Logger.getLogger(StudentRegistry.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- /**
- * @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 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(StudentRegistry.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(StudentRegistry.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(StudentRegistry.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(StudentRegistry.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 StudentRegistry().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton btnCreate;
- private javax.swing.JButton btnDelete;
- private javax.swing.JButton btnUpdate;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JLabel jLabel5;
- private javax.swing.JLabel jLabel6;
- private javax.swing.JLabel jLabel7;
- private javax.swing.JLabel jLabel8;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JTextField jTextField1;
- private javax.swing.JTable tableData;
- private javax.swing.JTextField txtCNumber;
- private javax.swing.JTextField txtFName;
- private javax.swing.JTextField txtGLevel;
- private javax.swing.JTextField txtLName;
- private javax.swing.JTextField txtSection;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement