Java tutorial
/* * 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 StockForecast; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.Collections; import java.util.Date; import java.util.Iterator; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.ButtonGroup; import javax.swing.JOptionPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator; import org.json.JSONArray; import org.json.JSONObject; /** * * @author c07nw8vqg1hw */ public class Main extends javax.swing.JFrame { /** * Creates new form Main */ public Main() { try { initComponents(); groupButtonProfile(); groupButtonStock(); groupPanelProfile(); initJRadio(); generateID(); maxDate(); groupPanelStock(); setHintText(); } catch (Exception ex) { Logger.getLogger(Main.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">//GEN-BEGIN:initComponents private void initComponents() { jTabbedPane3 = new javax.swing.JTabbedPane(); jPanel1 = new javax.swing.JPanel(); jPanel2 = new javax.swing.JPanel(); jTextField1 = new javax.swing.JTextField(); jTextField4 = new javax.swing.JTextField(); jTextField5 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jComboBox1 = new javax.swing.JComboBox<>(); 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(); jPasswordField1 = new javax.swing.JPasswordField(); jPasswordField2 = new javax.swing.JPasswordField(); jLabel7 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); jTextField6 = new javax.swing.JTextField(); jLabel10 = new javax.swing.JLabel(); jRadioButton1 = new javax.swing.JRadioButton(); jPanel3 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jButton2 = new javax.swing.JButton(); jComboBox2 = new javax.swing.JComboBox<>(); jRadioButton2 = new javax.swing.JRadioButton(); jComboBox4 = new javax.swing.JComboBox<>(); jPanel5 = new javax.swing.JPanel(); jTabbedPane1 = new javax.swing.JTabbedPane(); jPanel6 = new javax.swing.JPanel(); jRadioButton3 = new javax.swing.JRadioButton(); jRadioButton4 = new javax.swing.JRadioButton(); dateChooserCombo1 = new datechooser.beans.DateChooserCombo(); dateChooserCombo2 = new datechooser.beans.DateChooserCombo(); jLabel11 = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel(); jComboBox3 = new javax.swing.JComboBox<>(); jButton3 = new javax.swing.JButton(); jScrollPane2 = new javax.swing.JScrollPane(); jTable2 = new javax.swing.JTable(); jPanel7 = new javax.swing.JPanel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jTabbedPane3.setTabPlacement(javax.swing.JTabbedPane.LEFT); jTabbedPane3.setToolTipText("User"); jTextField1.setToolTipText("Username"); jTextField1.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR)); jButton1.setText("Create"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Admin", "User" })); jComboBox1.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { jComboBox1ItemStateChanged(evt); } }); jLabel2.setText("Username"); jLabel3.setText("Password"); jLabel4.setText("Confirm Pasword"); jLabel6.setText("Address"); jLabel7.setText("Name"); jLabel8.setText("jLabel8"); jLabel9.setText("Phone Number"); jLabel10.setText("ID"); jRadioButton1.setText("Create New User"); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton1).addGap(83, 83, 83)) .addGroup(jPanel2Layout.createSequentialGroup().addGap(90, 90, 90).addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE) .addGap(23, 23, 23).addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addGroup(jPanel2Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED)) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(1, 1, 1)) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jLabel10).addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addGroup(jPanel2Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField1).addComponent(jPasswordField1) .addComponent(jPasswordField2).addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(2, 2, 2)) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED))) .addGroup(jPanel2Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jTextField6, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE) .addComponent(jTextField5))))) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap()) .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addComponent(jRadioButton1) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addComponent(jRadioButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE) .addComponent(jLabel1).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel8).addComponent(jLabel10)) .addGap(12, 12, 12) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4).addComponent(jPasswordField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel7)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel6)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel9)) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addGap(49, 49, 49) .addComponent(jLabel5)) .addGroup(jPanel2Layout.createSequentialGroup().addGap(18, 18, 18).addComponent( jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(129, 129, 129))); jTable1.setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { null, null }, { null, null }, { null, null }, { null, null }, { null, null } }, new String[] { "User ID", "Username" })); jTable1.setAlignmentX(1.0F); jTable1.setAlignmentY(1.0F); jScrollPane1.setViewportView(jTable1); jButton2.setText("Search"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jComboBox2.setModel(new javax.swing.DefaultComboBoxModel<>( new String[] { "All", "User ID", "User Name", "User Phone Number" })); jComboBox2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jComboBox2ActionPerformed(evt); } }); jRadioButton2.setText("Edit User"); jRadioButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButton2ActionPerformed(evt); } }); jComboBox4.setEditable(true); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(jPanel3Layout.createSequentialGroup().addComponent(jRadioButton2) .addGap(0, 0, Short.MAX_VALUE)) .addGroup(jPanel3Layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 686, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jPanel3Layout.createSequentialGroup() .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, 448, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap())))); jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap().addComponent(jRadioButton2) .addGap(32, 32, 32) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton2) .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(42, Short.MAX_VALUE))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); jTabbedPane3.addTab("User Management", jPanel1); jRadioButton3.setText("Auto Update"); jRadioButton4.setText("Manual Update"); jRadioButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButton4ActionPerformed(evt); } }); dateChooserCombo1.setCurrentView(new datechooser.view.appearance.AppearancesList("Light", new datechooser.view.appearance.ViewAppearance("custom", new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 255), false, true, new datechooser.view.appearance.swing.ButtonPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 255), true, true, new datechooser.view.appearance.swing.ButtonPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 255), new java.awt.Color(0, 0, 255), false, true, new datechooser.view.appearance.swing.ButtonPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(128, 128, 128), new java.awt.Color(0, 0, 255), false, true, new datechooser.view.appearance.swing.LabelPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 255), false, true, new datechooser.view.appearance.swing.LabelPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0), new java.awt.Color(255, 0, 0), false, false, new datechooser.view.appearance.swing.ButtonPainter()), (datechooser.view.BackRenderer) null, false, true))); dateChooserCombo2.setCurrentView(new datechooser.view.appearance.AppearancesList("Light", new datechooser.view.appearance.ViewAppearance("custom", new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 255), false, true, new datechooser.view.appearance.swing.ButtonPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 255), true, true, new datechooser.view.appearance.swing.ButtonPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 255), new java.awt.Color(0, 0, 255), false, true, new datechooser.view.appearance.swing.ButtonPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(128, 128, 128), new java.awt.Color(0, 0, 255), false, true, new datechooser.view.appearance.swing.LabelPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 255), false, true, new datechooser.view.appearance.swing.LabelPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0), new java.awt.Color(255, 0, 0), false, false, new datechooser.view.appearance.swing.ButtonPainter()), (datechooser.view.BackRenderer) null, false, true))); jLabel11.setText("Start Date"); jLabel12.setText("End Date"); jComboBox3.setEditable(true); jComboBox3.setToolTipText("Stock Symbol"); jButton3.setText("Update"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jTable2.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" })); jScrollPane2.setViewportView(jTable2); javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6); jPanel6.setLayout(jPanel6Layout); jPanel6Layout.setHorizontalGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout.createSequentialGroup().addGap(79, 79, 79).addGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jScrollPane2) .addGroup(jPanel6Layout.createSequentialGroup() .addGroup( jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jRadioButton3).addComponent(jRadioButton4)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 239, Short.MAX_VALUE) .addGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(jPanel6Layout.createSequentialGroup().addComponent(jLabel12) .addGap(24, 24, 24).addComponent(dateChooserCombo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel6Layout.createSequentialGroup().addComponent(jLabel11) .addGap(18, 18, 18).addComponent(dateChooserCombo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jComboBox3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) .addGap(234, 234, 234))); jPanel6Layout.setVerticalGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout.createSequentialGroup().addGap(14, 14, 14).addGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jRadioButton3).addComponent(jLabel11)) .addComponent(dateChooserCombo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton3) .addGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jRadioButton4).addComponent(dateChooserCombo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jLabel12)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jTabbedPane1.addTab("Stock View", jPanel6); javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7); jPanel7.setLayout(jPanel7Layout); jPanel7Layout.setHorizontalGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 1001, Short.MAX_VALUE)); jPanel7Layout.setVerticalGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 361, Short.MAX_VALUE)); jTabbedPane1.addTab("Stock Casting", jPanel7); javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); jPanel5.setLayout(jPanel5Layout); jPanel5Layout.setHorizontalGroup( jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel5Layout .createSequentialGroup().addContainerGap().addComponent(jTabbedPane1).addContainerGap())); jPanel5Layout.setVerticalGroup( jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel5Layout .createSequentialGroup().addContainerGap().addComponent(jTabbedPane1).addContainerGap())); jTabbedPane1.getAccessibleContext().setAccessibleName("Stock View"); jTabbedPane3.addTab("Stock Management", jPanel5); jPanel5.getAccessibleContext().setAccessibleName("Stock Management"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jTabbedPane3)); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(81, Short.MAX_VALUE).addComponent(jTabbedPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 440, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap())); pack(); }// </editor-fold>//GEN-END:initComponents private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: Connect a = new Connect(); DefaultTableModel tm = new DefaultTableModel(); jTable1.setRowHeight(25); tm.addColumn("User ID"); tm.addColumn("Username"); tm.addColumn("Password"); tm.addColumn("User Type"); tm.addColumn("Name"); tm.addColumn(""); tm.addColumn(""); Action delete = new AbstractAction() { public void actionPerformed(ActionEvent e) { jTable1 = (JTable) e.getSource(); int modelRow = Integer.valueOf(e.getActionCommand()); ((DefaultTableModel) jTable1.getModel()).removeRow(modelRow); } }; String selectItem = jComboBox2.getSelectedItem().toString(); String partQuery = ""; String text = ""; System.out.println(jComboBox4.getItemCount()); if (jComboBox4.isEnabled()) { if (jComboBox4.getItemCount() > 0) { switch (selectItem) { case "All": partQuery = ""; break; case "User ID": text = jComboBox4.getSelectedItem().toString(); partQuery = " WHERE LOGINID='" + text + "'"; break; case "User Name": text = jComboBox4.getSelectedItem().toString(); partQuery = " WHERE NAME='" + text + "'"; break; case "User Phone Number": text = jComboBox4.getSelectedItem().toString(); partQuery = " WHERE NAME='" + text + "'"; break; default: System.out.println("This Search Condition Not Yet Implemented"); } try { ResultSet rs = a.connectSelect("1", "SELECT * FROM ROOT.LOGIN NATURAL JOIN PROFILE" + partQuery); if (text.equals("")) { JOptionPane.showMessageDialog(this, "Please Input Search Text"); } else if (!rs.next()) { JOptionPane.showMessageDialog(this, "There Is No Data With " + selectItem + ": " + text + "\n" + "Please Try Using Valid (" + selectItem + ")"); } else { do { tm.addRow(new Object[] { rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(6), "Delete", "Update" }); jTable1.setModel(tm); ButtonColumn buttonColumn = new ButtonColumn(jTable1, delete, 5); ButtonColumn btnColumn = new ButtonColumn(jTable1, delete, 6); buttonColumn.setMnemonic(KeyEvent.VK_D); btnColumn.setMnemonic(KeyEvent.VK_U); } while (rs.next()); } } catch (Exception ex) { System.out.println("Error: " + ex); } } else { JOptionPane.showMessageDialog(this, "There Is no Data Display in Table"); } } else { try { ResultSet rs = a.connectSelect("1", "SELECT * FROM ROOT.LOGIN NATURAL JOIN PROFILE"); if (!rs.next()) { JOptionPane.showMessageDialog(this, "There Is no Data Display in Table"); } else { do { tm.addRow(new Object[] { rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(6), "Delete", "Update" }); jTable1.setModel(tm); ButtonColumn buttonColumn = new ButtonColumn(jTable1, delete, 5); ButtonColumn btnColumn = new ButtonColumn(jTable1, delete, 6); buttonColumn.setMnemonic(KeyEvent.VK_D); btnColumn.setMnemonic(KeyEvent.VK_U); } while (rs.next()); } } catch (Exception ex) { Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex); } } }//GEN-LAST:event_jButton2ActionPerformed private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox1ItemStateChanged try { // TODO add your handling code here: generateID(); } catch (Exception ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_jComboBox1ItemStateChanged private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: Date date = new Date(); Connect connect = new Connect(); String id = jLabel8.getText(); String usrname = jTextField1.getText(); String pass = new String(jPasswordField1.getPassword()); String usrtype = jComboBox1.getSelectedItem().toString(); String name = jTextField4.getText(); String add = jTextField5.getText(); String phoneNum = jTextField6.getText(); String errUsrname = ""; String errPass = ""; String errConfPass = ""; String errName = ""; String errAdd = ""; String errPhoneNum = ""; try { ResultSet rs = connect.connectSelect("1", "SELECT * FROM ROOT.LOGIN WHERE USERNAME='" + usrname + "'"); if (usrname.isEmpty()) { errUsrname = "Please Input Valid Username"; } while (rs.next()) { String uname = rs.getString("username"); if (usrname.toUpperCase().equals(uname.toUpperCase())) { errUsrname = "Username: (" + usrname + ") is Already Exist, Try Another"; } else { break; } } if (jPasswordField1.getPassword().length == 0) { errPass = "\n" + "Please Input Valid Password"; } if (jPasswordField2.getPassword().length == 0) { errConfPass = "\n" + "Please Input Valid Confirm Password"; } if (jPasswordField1.getPassword().length != 0 && !Arrays.equals(jPasswordField1.getPassword(), jPasswordField2.getPassword())) { errPass = "\n" + "Password & Confirm Password Didn't Match"; } if (name.isEmpty()) { errName = "\n" + "Please Input Valid Name"; } if (add.isEmpty()) { errAdd = "\n" + "Please Input Valid Address"; } if (phoneNum.isEmpty()) { errPhoneNum = "\n" + "Please Input Valid Phone Number"; } if (errUsrname.equals("") && errPass.equals("") && errAdd.equals("") && errConfPass.equals("") && errPhoneNum.equals("")) { try { connect.connectInsert("INSERT INTO LOGIN VALUES ('" + id + "','" + usrname + "','" + pass + "','" + usrtype + "')"); connect.connectInsert("INSERT INTO PROFILE VALUES (DEFAULT,'" + id + "','" + name + "','" + add + "','" + phoneNum + "','" + new Timestamp(date.getTime()) + "')"); clearField(); JOptionPane.showMessageDialog(this, id + ": " + "(" + usrname + ") " + "Succes Created"); } catch (Exception ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } else { JOptionPane.showMessageDialog(this, errUsrname + errPass + errConfPass + errName + errAdd + errPhoneNum); } generateID(); rs.close(); } catch (Exception ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_jButton1ActionPerformed private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed // TODO add your handling code here: try { DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Date today = Calendar.getInstance().getTime(); Calendar c = Calendar.getInstance(); c.setTime(today); c.add(Calendar.DATE, -1); String todayForm = df.format(today); String actualDate = df.format(c.getTime()); String startDate = dateChooserCombo1.getText(); String endDate = dateChooserCombo2.getText(); Date comStart = df.parse(startDate); Date comEnd = df.parse(endDate); if (startDate.equals(endDate)) { JOptionPane.showMessageDialog(this, "Please Select Range Date"); } else if (todayForm.equals(startDate)) { JOptionPane.showMessageDialog(this, "Please Select : (" + actualDate + ") as a Maximum Date"); } else if (todayForm.equals(endDate)) { JOptionPane.showMessageDialog(this, "Please Select : (" + actualDate + ") as a Maximum Date"); } else if (comStart.compareTo(comEnd) > 0) { JOptionPane.showMessageDialog(this, "Start Date is After End Date, Please Select Proper Range Date"); } else { System.out.println("DO Something"); } } catch (ParseException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_jButton3ActionPerformed private void jRadioButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton4ActionPerformed // TODO add your handling code here: try { SearchBoxModel sbm = new SearchBoxModel(jComboBox3); jComboBox3.setModel(sbm); sbm.setCon(""); jComboBox3.addItemListener(sbm); } catch (Exception ex) { Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_jRadioButton4ActionPerformed private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed try { // TODO add your handling code here: searchBoxCond(); } catch (Exception ex) { System.out.println("Somethings Wrong" + "\n" + ex); } }//GEN-LAST:event_jRadioButton2ActionPerformed private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox2ActionPerformed try { // TODO add your handling code here: displayProfile(); searchBoxCond(); } catch (Exception ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_jComboBox2ActionPerformed private void displayProfile() throws Exception { String selectItem = jComboBox2.getSelectedItem().toString(); int itemCount = jComboBox4.getItemCount(); if (itemCount == 0) { System.out.println("There is no Item"); } else { for (int i = 0; i < itemCount; i++) { jComboBox4.removeItemAt(0); } } Connect con = new Connect(); ResultSet rs = con.connectSelect("1", "SELECT * FROM ROOT.LOGIN NATURAL JOIN PROFILE"); switch (selectItem) { case "All": if (!rs.next()) { System.out.println("There Is No Data Display"); } else { do { String s = rs.getString("loginid"); jComboBox4.addItem(s); } while (rs.next()); } break; case "User ID": if (!rs.next()) { System.out.println("There Is No Data Display"); } else { do { jComboBox4.addItem(rs.getString("loginid")); } while (rs.next()); } break; case "User Name": if (!rs.next()) { System.out.println("There Is No Data Display"); } else { do { jComboBox4.addItem(rs.getString("name")); } while (rs.next()); } break; case "User Phone Number": if (!rs.next()) { System.out.println("There Is No Data Display"); } else { do { jComboBox4.addItem(rs.getString("phone")); } while (rs.next()); } break; default: System.out.println("ERROR"); } AutoCompleteDecorator.decorate(this.jComboBox4); } private void getStock() throws IOException, MalformedURLException, Exception { String sym = jComboBox1.getSelectedItem().toString(); Connect connect = new Connect(); ResultSet rs = connect.connectSelect("1", "SELECT * FROM ROOT.STOCK"); ArrayList<String> stringList = new ArrayList<>(); while (rs.next()) { String symbol = rs.getString("symbol"); System.out.println(symbol); stringList.add(symbol); } System.out.println(stringList); System.err.println(stringList.size()); for (int i = 0; i < stringList.size(); i++) { System.out.println(stringList.get(i)); getHistoricalData(stringList.get(i)); } } private void getHistoricalData(String stockSymbol) throws ParseException, MalformedURLException, IOException, Exception { String sym = stockSymbol; String startDate = dateChooserCombo1.getText(); String endDate = dateChooserCombo2.getText(); SimpleDateFormat oldFormat = new SimpleDateFormat("MM/dd/yy"); SimpleDateFormat newFormat = new SimpleDateFormat("yyyy-MM-dd"); Date startDateFormat = oldFormat.parse(startDate); Date endDateFormat = oldFormat.parse(endDate); String sDate = newFormat.format(startDateFormat); String eDate = newFormat.format(endDateFormat); Connect connect = new Connect(); ResultSet rs = connect.connectSelect("1", "SELECT * FROM ROOT.STOCKDETAILS"); ArrayList<String> stringList = new ArrayList<>(); while (rs.next()) { String stockDate = rs.getString("stockdate"); System.out.println(stockDate); stringList.add(stockDate); } Calendar c = Calendar.getInstance(); while (!sDate.equals(eDate)) { System.out.println(sDate); { String s = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.historicaldata%20where%20symbol%20%3D%20%22" + sym + ".JK%22%20and%20startDate%20%3D%20%22" + sDate + "%22%20and%20endDate%20%3D%20%22" + sDate + "%22&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback="; URL url = new URL(s); BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream())); String a = null; String strTemp = ""; while (null != (strTemp = br.readLine())) { a = strTemp; } JSONObject obj = new JSONObject(a); JSONObject query = obj.getJSONObject("query"); int count = query.getInt("count"); System.out.println(count); if (count == 0) { JOptionPane.showMessageDialog(this, "Please Select Actual Date"); } else if (count == 1) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); JSONObject results = query.getJSONObject("results"); JSONObject quote = results.getJSONObject("quote"); String high = quote.getString("High"); String low = quote.getString("Low"); String volume = quote.getString("Volume"); String adjClose = quote.getString("Adj_Close"); String close = quote.getString("Close"); Date date = formatter.parse(quote.getString("Date")); String open = quote.getString("Open"); String exactVolume = ""; if (volume.equals("0")) { Date vDate = newFormat.parse(sDate); c.setTime(vDate); c.add(Calendar.DATE, -1); String prevDate = newFormat.format(c.getTime()); connect.connectSelect("1", "SELECT * FROM ROOT.STOCKDETAILS WHERE DATE='" + prevDate + "'"); while (rs.next()) { exactVolume = rs.getString("volume"); } } System.out.println(high + ", " + low + ", " + volume + ", " + exactVolume + ", " + adjClose + ", " + close + ", " + formatter.format(date) + ", " + open); if (stringList.contains(date)) { System.out.println("Data on : (" + date + ") Is Already Added"); } else { connect.connectInsert("INSERT INTO STOCKDETAILS VALUES (DEFAULT,'" + sym + "','" + date + "', '" + high + "', '" + low + "', '" + volume + "', '" + exactVolume + "', '" + adjClose + "', '" + close + "', '" + open + "')"); } } else { JSONObject results = query.getJSONObject("results"); JSONArray array = results.getJSONArray("quote"); System.out.println(array); System.out.println(array.length()); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); for (int ic = 0; ic < array.length(); ic++) { String high = array.getJSONObject(ic).getString("High"); String low = array.getJSONObject(ic).getString("Low"); String volume = array.getJSONObject(ic).getString("Volume"); String adjClose = array.getJSONObject(ic).getString("Adj_Close"); String close = array.getJSONObject(ic).getString("Close"); Date date = formatter.parse(array.getJSONObject(ic).getString("Date")); String open = array.getJSONObject(ic).getString("Open"); String exactVolume = ""; if (volume.equals("0")) { Date vDate = newFormat.parse(sDate); c.setTime(vDate); c.add(Calendar.DATE, -1); String prevDate = newFormat.format(c.getTime()); connect.connectSelect("1", "SELECT * FROM ROOT.STOCKDETAILS WHERE DATE='" + prevDate + "'"); while (rs.next()) { exactVolume = rs.getString("volume"); } } System.out.println(high + ", " + low + ", " + volume + ", " + adjClose + ", " + close + ", " + formatter.format(date) + ", " + open); if (stringList.contains(date)) { System.out.println("Data on : (" + date + ") Is Already Added"); } else { connect.connectInsert("INSERT INTO STOCKDETAILS VALUES (DEFAULT,'" + sym + "','" + date + "', '" + high + "', '" + low + "', '" + volume + "', '" + exactVolume + "', '" + adjClose + "', '" + close + "', '" + open + "')"); } } } br.close(); rs.close(); } Date date = newFormat.parse(sDate); c.setTime(date); c.add(Calendar.DATE, 1); String getDate = newFormat.format(c.getTime()); sDate = getDate; } } private void maxDate() { DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Date today = Calendar.getInstance().getTime(); Calendar c = Calendar.getInstance(); c.setTime(today); c.add(Calendar.DATE, -1); dateChooserCombo1.setMaxDate(c); dateChooserCombo2.setMaxDate(c); dateChooserCombo1.setDateFormat(df); dateChooserCombo2.setDateFormat(df); } private void clearField() { jTextField1.setText(""); jTextField4.setText(""); jTextField5.setText(""); jTextField6.setText(""); jPasswordField1.setText(""); jPasswordField2.setText(""); } private void groupButtonProfile() { ButtonGroup bg1 = new ButtonGroup(); bg1.add(jRadioButton1); bg1.add(jRadioButton2); } private void groupButtonStock() { ButtonGroup bg1 = new ButtonGroup(); bg1.add(jRadioButton3); bg1.add(jRadioButton4); } private void groupPanelStock() throws Exception { jRadioButton3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jLabel11.setEnabled(false); jLabel12.setEnabled(false); dateChooserCombo1.setEnabled(false); dateChooserCombo2.setEnabled(false); jComboBox3.setEnabled(false); jButton3.setEnabled(false); jTable2.setEnabled(false); } }); jRadioButton4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jLabel11.setEnabled(true); jLabel12.setEnabled(true); dateChooserCombo1.setEnabled(true); dateChooserCombo2.setEnabled(true); jComboBox3.setEnabled(true); jButton3.setEnabled(true); jTable2.setEnabled(true); } }); } private void groupPanelProfile() { jRadioButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jComboBox1.setEnabled(true); jLabel2.setEnabled(true); jLabel3.setEnabled(true); jLabel4.setEnabled(true); jLabel6.setEnabled(true); jLabel7.setEnabled(true); jLabel8.setEnabled(true); jLabel9.setEnabled(true); jLabel10.setEnabled(true); jTextField1.setEnabled(true); jTextField4.setEnabled(true); jTextField5.setEnabled(true); jTextField6.setEnabled(true); jPasswordField1.setEnabled(true); jPasswordField2.setEnabled(true); jButton1.setEnabled(true); jComboBox2.setEnabled(false); jButton2.setEnabled(false); jTable1.setEnabled(false); jComboBox4.setEnabled(false); } }); jRadioButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jComboBox1.setEnabled(false); jLabel2.setEnabled(false); jLabel3.setEnabled(false); jLabel4.setEnabled(false); jLabel6.setEnabled(false); jLabel7.setEnabled(false); jLabel8.setEnabled(false); jLabel9.setEnabled(false); jLabel10.setEnabled(false); jTextField1.setEnabled(false); jTextField4.setEnabled(false); jTextField5.setEnabled(false); jTextField6.setEnabled(false); jPasswordField1.setEnabled(false); jPasswordField2.setEnabled(false); jButton1.setEnabled(false); jComboBox2.setEnabled(true); jButton2.setEnabled(true); jTable1.setEnabled(true); searchBoxCond(); } }); } private void initJRadio() { jRadioButton1.setSelected(true); jRadioButton3.setSelected(true); jComboBox2.setEnabled(false); jComboBox4.setEnabled(false); jButton2.setEnabled(false); jTable1.setEnabled(false); jLabel11.setEnabled(false); jLabel12.setEnabled(false); dateChooserCombo1.setEnabled(false); dateChooserCombo2.setEnabled(false); jComboBox3.setEnabled(false); jButton3.setEnabled(false); jTable2.setEnabled(false); } private void setHintText() throws Exception { jTextField1.setUI(new HintTextUI("ex: (Tukijo)", Color.gray)); jTextField4.setUI(new HintTextUI("ex: (Tukijo Juminten)", Color.gray)); jTextField5.setUI(new HintTextUI("ex: (Jl. Mana Aja)", Color.gray)); jTextField6.setUI(new HintTextUI("ex: (08981111111)", Color.gray)); } private void displayUser() throws Exception { String selectItem = jComboBox2.getSelectedItem().toString(); Connect connect = new Connect(); DefaultTableModel displayTable = new DefaultTableModel(); String text = jComboBox4.getSelectedItem().toString(); System.out.println(text.toUpperCase()); displayTable.addColumn("User ID"); displayTable.addColumn("Username"); displayTable.addColumn("Password"); displayTable.addColumn("User Type"); displayTable.addColumn("Name"); displayTable.addColumn(""); displayTable.addColumn(""); ResultSet rs = connect.connectSelect("1", "SELECT * FROM ROOT.LOGIN NATURAL JOIN PROFILE WHERE LOGINID='" + text + "'"); displayTable.addRow(new Object[] { rs.getString("loginid"), rs.getString("username"), rs.getString("password"), rs.getString("usertype"), rs.getString("name"), "Delete", "Update" }); jTable1.setModel(displayTable); Action delete = new AbstractAction() { public void actionPerformed(ActionEvent e) { JTable table = (JTable) e.getSource(); int modelRow = Integer.valueOf(e.getActionCommand()); ((DefaultTableModel) table.getModel()).removeRow(modelRow); } }; ButtonColumn buttonColumn = new ButtonColumn(jTable1, delete, 5); ButtonColumn btnColumn = new ButtonColumn(jTable1, delete, 6); buttonColumn.setMnemonic(KeyEvent.VK_D); btnColumn.setMnemonic(KeyEvent.VK_U); } private void searchBoxCond() { String slctItm = jComboBox2.getSelectedItem().toString(); if (slctItm.equals("All")) { jComboBox4.setEnabled(false); } else { jComboBox4.setEnabled(true); } } private void generateID() throws Exception { String selectItem = jComboBox1.getSelectedItem().toString(); Connect connect = new Connect(); ResultSet rs = connect.connectSelect("1", "SELECT * FROM ROOT.LOGIN NATURAL JOIN PROFILE"); ArrayList<String> stringList = new ArrayList<String>(); while (rs.next()) { String usrId = rs.getString("loginid"); System.out.println(usrId); stringList.add(usrId); } if (stringList.isEmpty()) { if (selectItem.equals("Admin")) { jLabel8.setText("ADM100001"); } else if (selectItem.equals("User")) { jLabel8.setText("USR100001"); } else { JOptionPane.showMessageDialog(this, "ERROR"); } } else { System.out.println(stringList); Iterator<String> itr = stringList.iterator(); ArrayList<Integer> admin = new ArrayList<Integer>(); ArrayList<Integer> user = new ArrayList<Integer>(); while (itr.hasNext()) { String iter = itr.next(); if (iter.contains("ADM")) { String[] parts = iter.split("ADM"); int num = Integer.parseInt(parts[1]); admin.add(num); } else if (iter.contains("USR")) { String[] parts = iter.split("USR"); int num = Integer.parseInt(parts[1]); user.add(num); } } System.out.println("This is Admin: " + admin); System.out.println("This is User: " + user); if (user.isEmpty() && !admin.isEmpty()) { int newNumAdm = Collections.max(admin) + 1; String newAdmNum = Integer.toString(newNumAdm); if (selectItem.equals("Admin")) { jLabel8.setText("ADM" + newAdmNum); } else if (selectItem.equals("User")) { jLabel8.setText("USR100001"); } else { JOptionPane.showMessageDialog(this, "ERROR"); } } else if (admin.isEmpty() && !user.isEmpty()) { int newNumUsr = Collections.max(user) + 1; String newUsrNum = Integer.toString(newNumUsr); if (selectItem.equals("Admin")) { jLabel8.setText("ADM100001"); } else if (selectItem.equals("User")) { jLabel8.setText("USR" + newUsrNum); } else { JOptionPane.showMessageDialog(this, "ERROR"); } } else { int newNumAdm = Collections.max(admin) + 1; int newNumUsr = Collections.max(user) + 1; String newAdmNum = Integer.toString(newNumAdm); String newUsrNum = Integer.toString(newNumUsr); if (selectItem.equals("Admin")) { jLabel8.setText("ADM" + newAdmNum); } else if (selectItem.equals("User")) { jLabel8.setText("USR" + newUsrNum); } else { JOptionPane.showMessageDialog(this, "ERROR"); } } } } /** * @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(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Main.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 Main().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private datechooser.beans.DateChooserCombo dateChooserCombo1; private datechooser.beans.DateChooserCombo dateChooserCombo2; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JComboBox<String> jComboBox1; private javax.swing.JComboBox<String> jComboBox2; private javax.swing.JComboBox<String> jComboBox3; private javax.swing.JComboBox<String> jComboBox4; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; 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.JLabel jLabel9; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel5; private javax.swing.JPanel jPanel6; private javax.swing.JPanel jPanel7; private javax.swing.JPasswordField jPasswordField1; private javax.swing.JPasswordField jPasswordField2; private javax.swing.JRadioButton jRadioButton1; private javax.swing.JRadioButton jRadioButton2; private javax.swing.JRadioButton jRadioButton3; private javax.swing.JRadioButton jRadioButton4; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTabbedPane jTabbedPane1; private javax.swing.JTabbedPane jTabbedPane3; private javax.swing.JTable jTable1; private javax.swing.JTable jTable2; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField4; private javax.swing.JTextField jTextField5; private javax.swing.JTextField jTextField6; // End of variables declaration//GEN-END:variables private Connect Connect() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }