Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class NewJFrame extends javax.swing.JFrame {
- public NewJFrame() {
- initComponents();
- getConnection ();
- }
- public Connection getConnection (){
- Connection con = null;
- try {
- con = DriverManager.getConnection("jdbc:mysql://localhost/products","root","");
- JOptionPane.showMessageDialog(null, "Connected");
- return con;
- } catch (SQLException ex) {
- Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
- JOptionPane.showMessageDialog(null, "Not Connected");
- return null;
- }
- }
- // Check input fields
- public boolean checkInputs (){
- if (txt_trackingNumber.getText() == null
- || txt_lastName.getText() == null
- || txt_firstName.getText() == null
- || txt_houseNo.getText() == null
- || txt_street.getText() == null
- || txt_barangay.getText() == null
- || txt_city.getText() == null){
- return false;
- }
- else{
- try{
- return true;
- }catch (Exception ex){
- return false;
- }
- }
- }
- txt_trackingNumber.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txt_trackingNumberActionPerformed(evt);
- }
- });
- jTable1.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- },
- new String [] {
- "Tracking No", "Last Name", "First Name", "House No.", "Street", "Barangay", "City"
- }
- ));
- jScrollPane1.setViewportView(jTable1);
- jLabel4.setText("House No.");
- jLabel5.setText("Street");
- jLabel6.setText("Barangay");
- jLabel8.setText("City");
- jLabel9.setText("Sender");
- jButton2.setText("INSERT");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- jButton3.setText("UPDATE");
- jButton4.setText("DELETE");
- jMenu1.setText("File");
- jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
- jMenuItem1.setText("New");
- jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenuItem1ActionPerformed(evt);
- }
- });
- jMenu1.add(jMenuItem1);
- jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
- jMenuItem2.setText("Save");
- jMenu1.add(jMenuItem2);
- jMenuBar1.add(jMenu1);
- jMenu2.setText("Edit");
- jMenuItem3.setText("Add");
- jMenu2.add(jMenuItem3);
- jMenuBar1.add(jMenu2);
- jMenu3.setText("Sorting");
- jMenuBar1.add(jMenu3);
- setJMenuBar(jMenuBar1);
- private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
- System.exit(0);
- }
- private void txt_trackingNumberActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- Object ImgFath = null;
- if (checkInputs() && ImgFath != null){
- try {
- Connection con = getConnection ();
- PreparedStatement ps = con.prepareStatement("INSERT INTO products(Transaction_No,Last_Name,First_Name,House_No,Street,Barangay,City)"
- + "values(?,?,?,?,?,?,?)");
- ps.setString(1, txt_trackingNumber.getText());
- ps.setString(2, txt_lastName.getText());
- ps.setString(3, txt_firstName.getText());
- ps.setString(4, txt_houseNo.getText());
- ps.setString(5, txt_street.getText());
- ps.setString(6, txt_barangay.getText());
- ps.setString(7, txt_city.getText());
- ps.executeUpdate();
- JOptionPane.showMessageDialog(null, "DATA INSERTED");
- } catch (Exception ex) {
- JOptionPane.showMessageDialog(null, ex.getMessage());
- }
- }
- else {
- JOptionPane.showMessageDialog(null, "One or");
- }
- System.out.println("Tracking Number => " +txt_trackingNumber.getText());
- System.out.println("LastName => " +txt_lastName.getText());
- System.out.println("FirstName => " +txt_firstName.getText());
- System.out.println("House Number => " +txt_houseNo.getText());
- System.out.println("Street => " +txt_street.getText());
- System.out.println("Barangay => " +txt_barangay.getText());
- System.out.println("City => " +txt_city.getText());
- }
- /**
- * @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(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.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 NewJFrame().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton2;
- private javax.swing.JButton jButton3;
- private javax.swing.JButton jButton4;
- 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 jLabel8;
- private javax.swing.JLabel jLabel9;
- private javax.swing.JMenu jMenu1;
- private javax.swing.JMenu jMenu2;
- private javax.swing.JMenu jMenu3;
- private javax.swing.JMenuBar jMenuBar1;
- private javax.swing.JMenuItem jMenuItem1;
- private javax.swing.JMenuItem jMenuItem2;
- private javax.swing.JMenuItem jMenuItem3;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JTable jTable1;
- private javax.swing.JTextField txt_barangay;
- private javax.swing.JTextField txt_city;
- private javax.swing.JTextField txt_firstName;
- private javax.swing.JTextField txt_houseNo;
- private javax.swing.JTextField txt_lastName;
- private javax.swing.JTextField txt_street;
- private javax.swing.JTextField txt_trackingNumber;
- // End of variables declaration
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement