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 stockit; import java.awt.BorderLayout; import java.awt.Color; import java.sql.ResultSet; import java.sql.Statement; import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.DefaultListModel; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.NumberTickUnit; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.DefaultCategoryDataset; /** * * @author ahmed */ public class Manager extends javax.swing.JFrame { private static String username; private static String companyName; private static String clientAccountID; /** * Creates new form Trader */ public Manager() { initComponents(); try { DefaultListModel demoList = new DefaultListModel(); DBConnection dbcon = new DBConnection(); dbcon.establishConnection(); Statement stmt = dbcon.con.createStatement(); ResultSet rs = stmt.executeQuery("SELECT tc.username" + " FROM trader as t, manager_account as mc," + " trader_account as tc" + " WHERE t.Manager_SSN = mc.Manager_SSN AND tc.Trader_SSN = t.Trader_SSN" + " AND mc.username = \"" + username + "\""); while (rs.next()) { demoList.addElement(rs.getString("username")); } dbcon.con.close(); listOfTraders = new JList(demoList); jScrollPane3.setViewportView(listOfTraders); //setUpTable(); } catch (Exception ex) { Logger.getLogger(clientLogin.class.getName()).log(Level.SEVERE, null, ex); } } private void setSelectedStock() { int row = table.getSelectedRow(); variableStockChange.setText(table.getValueAt(row, 0).toString()); } /** * 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() { AddTraderDialog = new javax.swing.JDialog(); addTraderButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton(); usernamebox = new javax.swing.JTextField(); passwordbox = new javax.swing.JTextField(); traderssnbox = new javax.swing.JTextField(); sectorbox = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); jLabel10 = new javax.swing.JLabel(); AddClientDialog = new javax.swing.JDialog(); addTraderButton1 = new javax.swing.JButton(); cancelButton1 = new javax.swing.JButton(); usernamebox1 = new javax.swing.JTextField(); passwordbox1 = new javax.swing.JTextField(); clientssnbox = new javax.swing.JTextField(); jLabel11 = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel(); jLabel13 = new javax.swing.JLabel(); namebox = new javax.swing.JTextField(); jLabel15 = new javax.swing.JLabel(); accounttypebox = new javax.swing.JComboBox<>(); jLabel16 = new javax.swing.JLabel(); jLabel17 = new javax.swing.JLabel(); clientagebox = new javax.swing.JTextField(); jLabel1 = new javax.swing.JLabel(); panel = new javax.swing.JPanel(); displayBtn = new javax.swing.JButton(); allStockBtn = new javax.swing.JButton(); jSeparator1 = new javax.swing.JSeparator(); transactionBtn = new javax.swing.JButton(); searchStock = new javax.swing.JLabel(); transaction = new javax.swing.JLabel(); trader = new javax.swing.JLabel(); companyText = new javax.swing.JLabel(); companyVariable = new javax.swing.JLabel(); jScrollPane3 = new javax.swing.JScrollPane(); listOfTraders = new javax.swing.JList<>(); jScrollPane4 = new javax.swing.JScrollPane(); table = new javax.swing.JTable(); searchClientBtn = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); selectedStock = new javax.swing.JLabel(); variableStockChange = new javax.swing.JLabel(); jScrollPane5 = new javax.swing.JScrollPane(); listOfClients = new javax.swing.JList<>(); searchTraderBtn = new javax.swing.JButton(); jLabel3 = new javax.swing.JLabel(); traderRefresh = new javax.swing.JButton(); jLabel8 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); jLabel9 = new javax.swing.JLabel(); addClientButton = new javax.swing.JButton(); jLabel14 = new javax.swing.JLabel(); jMenuBar1 = new javax.swing.JMenuBar(); flieMenuItem = new javax.swing.JMenu(); logoutItem = new javax.swing.JMenuItem(); AddTraderDialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); AddTraderDialog.setTitle("Add Trader"); AddTraderDialog.setSize(new java.awt.Dimension(300, 300)); AddTraderDialog.setResizable(false); AddTraderDialog.setType(java.awt.Window.Type.POPUP); addTraderButton.setText("Add Trader"); addTraderButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addTraderButtonActionPerformed(evt); } }); cancelButton.setText("Cancel"); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelButtonActionPerformed(evt); } }); passwordbox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { passwordboxActionPerformed(evt); } }); sectorbox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { sectorboxActionPerformed(evt); } }); jLabel4.setText("Username:"); jLabel5.setText("Password:"); jLabel6.setText("Trader SSN:"); jLabel10.setText("Sector:"); javax.swing.GroupLayout AddTraderDialogLayout = new javax.swing.GroupLayout( AddTraderDialog.getContentPane()); AddTraderDialog.getContentPane().setLayout(AddTraderDialogLayout); AddTraderDialogLayout.setHorizontalGroup( AddTraderDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(AddTraderDialogLayout.createSequentialGroup().addGap(60, 60, 60) .addGroup(AddTraderDialogLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel4).addComponent(jLabel5).addComponent(jLabel6) .addComponent(jLabel10)) .addGap(29, 29, 29) .addGroup(AddTraderDialogLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(usernamebox, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE) .addComponent(passwordbox).addComponent(traderssnbox) .addComponent(sectorbox)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(AddTraderDialogLayout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(addTraderButton).addGap(72, 72, 72).addComponent(cancelButton) .addGap(83, 83, 83))); AddTraderDialogLayout.setVerticalGroup( AddTraderDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, AddTraderDialogLayout.createSequentialGroup().addContainerGap(50, Short.MAX_VALUE) .addGroup(AddTraderDialogLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(usernamebox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel4)) .addGap(18, 18, 18) .addGroup(AddTraderDialogLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(passwordbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel5)) .addGap(18, 18, 18) .addGroup(AddTraderDialogLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(traderssnbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel6)) .addGap(18, 18, 18) .addGroup(AddTraderDialogLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(sectorbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel10)) .addGap(44, 44, 44) .addGroup(AddTraderDialogLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(addTraderButton).addComponent(cancelButton)) .addGap(49, 49, 49))); AddClientDialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); AddClientDialog.setTitle("Add Client"); AddClientDialog.setSize(new java.awt.Dimension(350, 450)); AddClientDialog.setResizable(false); AddClientDialog.setType(java.awt.Window.Type.POPUP); addTraderButton1.setText("Add Client"); addTraderButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addTraderButton1ActionPerformed(evt); } }); cancelButton1.setText("Cancel"); cancelButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelButton1ActionPerformed(evt); } }); passwordbox1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { passwordbox1ActionPerformed(evt); } }); jLabel11.setText("Username:"); jLabel12.setText("Password:"); jLabel13.setText("Client SSN:"); namebox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { nameboxActionPerformed(evt); } }); jLabel15.setText("Client name:"); accounttypebox.setModel( new javax.swing.DefaultComboBoxModel<>(new String[] { "INVESTMENTS", "SAVINGS", "CHEQUING" })); jLabel16.setText("Account Type:"); jLabel17.setText("Age:"); javax.swing.GroupLayout AddClientDialogLayout = new javax.swing.GroupLayout( AddClientDialog.getContentPane()); AddClientDialog.getContentPane().setLayout(AddClientDialogLayout); AddClientDialogLayout.setHorizontalGroup(AddClientDialogLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(AddClientDialogLayout.createSequentialGroup().addGap(59, 59, 59) .addGroup(AddClientDialogLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(AddClientDialogLayout.createSequentialGroup() .addGroup(AddClientDialogLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel17).addComponent(jLabel16) .addComponent(jLabel11).addComponent(jLabel12) .addComponent(jLabel13).addComponent(jLabel15)) .addGap(29, 29, 29) .addGroup( AddClientDialogLayout .createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(clientagebox) .addComponent(usernamebox1, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(passwordbox1, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(clientssnbox, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(namebox, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE) .addComponent(accounttypebox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(48, Short.MAX_VALUE)) .addGroup( AddClientDialogLayout.createSequentialGroup().addComponent(addTraderButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(cancelButton1).addGap(42, 42, 42))))); AddClientDialogLayout.setVerticalGroup( AddClientDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, AddClientDialogLayout.createSequentialGroup().addGap(29, 29, 29) .addGroup(AddClientDialogLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(namebox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel15)) .addGap(18, 18, 18) .addGroup(AddClientDialogLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(usernamebox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel11)) .addGap(18, 18, 18) .addGroup(AddClientDialogLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(passwordbox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel12)) .addGap(18, 18, 18) .addGroup(AddClientDialogLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(clientssnbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel13)) .addGap(18, 18, 18) .addGroup(AddClientDialogLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(clientagebox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel17)) .addGap(18, 18, 18) .addGroup(AddClientDialogLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(accounttypebox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel16)) .addGap(67, 67, 67) .addGroup(AddClientDialogLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(addTraderButton1).addComponent(cancelButton1)) .addContainerGap(71, Short.MAX_VALUE))); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setText("Manager:"); javax.swing.GroupLayout panelLayout = new javax.swing.GroupLayout(panel); panel.setLayout(panelLayout); panelLayout.setHorizontalGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 765, Short.MAX_VALUE)); panelLayout.setVerticalGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 408, Short.MAX_VALUE)); displayBtn.setText("Stock Performance"); displayBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { displayBtnActionPerformed(evt); } }); allStockBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/stockit/rsz_market-icon-3.png"))); // NOI18N allStockBtn.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); allStockBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { allStockBtnActionPerformed(evt); } }); transactionBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource( "/stockit/rsz_4kcf4flghdlgbu3jaet9jtonae_mpyd4w0kbgz5sxue6ry9-iem85hz3mdx1-iufyzxn.png"))); // NOI18N transactionBtn .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); transactionBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { transactionBtnActionPerformed(evt); } }); searchStock.setText("Search Stocks"); transaction.setText("Transaction"); trader.setText(username); companyText.setText("Company Name:"); companyVariable.setText(companyName); listOfTraders.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); jScrollPane3.setViewportView(listOfTraders); table.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { }, new String[] { "Symbol", "Name", "Sector", "Quantity", "High", "Low", "Last", "Today Change", "Currency", "Profit/Loss" }) { Class[] types = new Class[] { java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class }; boolean[] canEdit = new boolean[] { false, false, false, false, false, false, false, false, false, false }; public Class getColumnClass(int columnIndex) { return types[columnIndex]; } public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); table.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() { public void mouseDragged(java.awt.event.MouseEvent evt) { tableMouseDragged(evt); } }); table.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { tableMouseClicked(evt); } }); table.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { tableKeyPressed(evt); } public void keyReleased(java.awt.event.KeyEvent evt) { tableKeyReleased(evt); } }); jScrollPane4.setViewportView(table); if (table.getColumnModel().getColumnCount() > 0) { table.getColumnModel().getColumn(2).setResizable(false); } searchClientBtn .setIcon(new javax.swing.ImageIcon(getClass().getResource("/stockit/rsz_search-icon-512.png"))); // NOI18N searchClientBtn .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); searchClientBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { searchClientBtnActionPerformed(evt); } }); jLabel2.setText("View Stocks"); selectedStock.setText("Selected Stock:"); listOfClients.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); jScrollPane5.setViewportView(listOfClients); searchTraderBtn .setIcon(new javax.swing.ImageIcon(getClass().getResource("/stockit/rsz_search-icon-512.png"))); // NOI18N searchTraderBtn .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); searchTraderBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { searchTraderBtnActionPerformed(evt); } }); jLabel3.setText("View Clients"); traderRefresh.setIcon(new javax.swing.ImageIcon(getClass().getResource("/stockit/rsz_refresh.png"))); // NOI18N traderRefresh.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); traderRefresh.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { traderRefreshActionPerformed(evt); } }); jLabel8.setText("Refresh"); jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/stockit/rsz_plus-icon.png"))); // NOI18N jButton1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { newTraderBtnActionPerformed(evt); } }); jLabel9.setText("New Trader"); addClientButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/stockit/rsz_plus-icon.png"))); // NOI18N addClientButton .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); addClientButton.setMaximumSize(new java.awt.Dimension(82, 81)); addClientButton.setMinimumSize(new java.awt.Dimension(82, 81)); addClientButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addClientButtonnewTraderBtnActionPerformed(evt); } }); jLabel14.setText("New Client"); flieMenuItem.setText("File"); logoutItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_DELETE, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK)); logoutItem.setText("Logout"); logoutItem.setToolTipText("Click to Logout of Application"); logoutItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { logoutItemActionPerformed(evt); } }); flieMenuItem.add(logoutItem); jMenuBar1.add(flieMenuItem); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane4) .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING))) .addGroup(layout.createSequentialGroup().addGap(130, 130, 130) .addComponent(panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(12, 12, 12).addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(searchTraderBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup().addGap(18, 18, 18) .addComponent(jLabel3))) .addGap(18, 18, 18) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup().addGap(10, 10, 10) .addComponent(jLabel9))) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(28, 28, 28) .addComponent(jLabel14).addGap(44, 44, 44) .addComponent(jLabel8)) .addGroup(layout.createSequentialGroup().addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(addClientButton, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(traderRefresh, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGroup(layout.createSequentialGroup() .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(searchClientBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup().addGap(18, 18, 18) .addComponent(jLabel2))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(allStockBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup().addGap(10, 10, 10) .addComponent(searchStock))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(transactionBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup().addGap(10, 10, 10) .addComponent(transaction)))))) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(trader, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(480, 480, 480).addComponent(companyText).addGap(14, 14, 14) .addComponent(companyVariable, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addContainerGap() .addComponent(displayBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(selectedStock) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(variableStockChange, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(0, 75, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(companyText, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(companyVariable, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(trader, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(7, 7, 7) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(searchTraderBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(7, 7, 7).addComponent(jLabel3).addGap(0, 0, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(addClientButton, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(traderRefresh, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel9).addComponent(jLabel14)) .addComponent(jLabel8))) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup() .addComponent(searchClientBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(7, 7, 7).addComponent(jLabel2)) .addGroup(layout.createSequentialGroup() .addComponent(allStockBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(7, 7, 7).addComponent(searchStock)) .addGroup(layout.createSequentialGroup() .addComponent(transactionBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(7, 7, 7).addComponent(transaction))) .addGap(7, 7, 7) .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(displayBtn) .addComponent(selectedStock)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(54, 54, 54)) .addGroup(layout.createSequentialGroup() .addComponent(variableStockChange, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))))); pack(); setLocationRelativeTo(null); }// </editor-fold>//GEN-END:initComponents private void displayBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_displayBtnActionPerformed // TODO add your handling code here: //panel.removeAll(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); int row = table.getSelectedRow(); if (row != -1) { //dataset.setValue(, "", table.getValueAt(0,1).toString()); String selectedStock = table.getValueAt(row, 0).toString(); try { DBConnection dbcon = new DBConnection(); dbcon.establishConnection(); Statement stmt = dbcon.con.createStatement(); ResultSet rs = stmt .executeQuery("Select stock_daily_performance.Closing_Price, stock_daily_performance.Date\n" + "FROM stock_daily_performance, stock\n" + "WHERE stock_daily_performance.StockID = stock.StockID AND stock.StockID = '" + selectedStock + "'" + "AND Date IN\n" + "( Select * from\n" + "(\n" + "SELECT Date \n" + "FROM stock_daily_performance \n" + "WHERE StockID = stockID \n" + "ORDER BY Date ASC\n" + ") temp_table)\n" + " "); while (rs.next()) { String formattedDate = rs.getString("Date"); int closing_price = rs.getInt("Closing_Price"); System.out.println("Closing Price: " + closing_price); System.out.println("Date: " + formattedDate); dataset.setValue(closing_price, "value", formattedDate); } dbcon.con.close(); } catch (Exception ex) { Logger.getLogger(clientLogin.class.getName()).log(Level.SEVERE, null, ex); } String stockName = table.getValueAt(row, 1).toString(); JFreeChart chart = ChartFactory.createBarChart3D(stockName + " Stock Performance", "Date", "Value", dataset, PlotOrientation.VERTICAL, false, false, false); Color c = new Color(240, 240, 240, 0); chart.setBackgroundPaint(c); CategoryPlot catPlot = chart.getCategoryPlot(); catPlot.setRangeGridlinePaint(Color.BLACK); //set interval of Y-axis ticks (tick every 5 units) NumberAxis yAxis = (NumberAxis) catPlot.getRangeAxis(); yAxis.setTickUnit(new NumberTickUnit(5)); //set y-axis labels as currency types ($) NumberFormat currency = NumberFormat.getCurrencyInstance(); yAxis.setNumberFormatOverride(currency); //setting number of lines an x-axis label is displayed on CategoryAxis categoryAxis = catPlot.getDomainAxis(); categoryAxis.setMaximumCategoryLabelLines(4); panel.setLayout(new java.awt.BorderLayout()); ChartPanel chartPanel = new ChartPanel(chart); panel.removeAll(); panel.add(chartPanel, BorderLayout.CENTER); panel.validate(); panel.repaint(); } }//GEN-LAST:event_displayBtnActionPerformed private void logoutItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logoutItemActionPerformed // TODO add your handling code here: dispose(); String X[] = { "Returning From Trader Main Screen" }; mainScreen.main(X); }//GEN-LAST:event_logoutItemActionPerformed private void allStockBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allStockBtnActionPerformed // TODO add your handling code here: String[] array = new String[1]; array[0] = username; allStocks.main(array); }//GEN-LAST:event_allStockBtnActionPerformed private void searchClientBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchClientBtnActionPerformed // TODO add your handling code here: if (listOfClients.isSelectionEmpty()) { JOptionPane.showMessageDialog(getContentPane(), "Please Select a Client", "Error", JOptionPane.ERROR_MESSAGE); } else { String selectedClient = listOfClients.getSelectedValue(); System.out.println(selectedClient); try { DBConnection dbcon = new DBConnection(); dbcon.establishConnection(); Statement stmt = dbcon.con.createStatement(); ResultSet rs = stmt.executeQuery( "SELECT stock.stockID, company.Name, stock_sector.Sector, stock_daily_performance.Currency, stock_daily_performance.High, stock_daily_performance.Low, stock_daily_performance.Closing_Price, has_positions.Qty, (stock_daily_performance.Opening_Price - stock_daily_performance.Closing_Price) AS Today_Change, ((stock_daily_performance.Opening_Price - stock_daily_performance.Closing_Price) * has_positions.Qty) AS Profit\n" + "FROM stock, stock_sector, stock_daily_performance, has_positions, account, client, company\n" + "WHERE client.Name = '" + selectedClient + "'" + "AND client.Client_SSN = account.Client_SSN AND account.Account_ID = has_positions.Account_ID AND stock_daily_performance.StockID = has_positions.Stock_ID AND stock.StockID = has_positions.Stock_ID AND stock_sector.StockID = has_positions.Stock_ID AND company.StockID = stock.StockID AND Date IN\n" + "( Select * from \n" + "(\n" + "SELECT max(Date) \n" + "FROM stock_daily_performance, stock\n" + "where stock_daily_performance.StockID=stock.StockID\n" + "group by stock.StockID\n" + "ORDER BY Date\n" + ") temp_table)"); DefaultTableModel model = (DefaultTableModel) table.getModel(); model.setRowCount(0); while (rs.next()) { System.out.println( rs.getString("stockID") + "\t" + rs.getString("Name") + "\t" + rs.getString("Sector") + "\t" + rs.getString("Currency") + "\t" + rs.getString("Closing_Price") + "\t" + rs.getString("Qty") + rs.getString("Today_Change")); model.addRow(new Object[] { rs.getString("stockID"), rs.getString("Name"), rs.getString("Sector"), rs.getString("Qty"), rs.getString("High"), rs.getString("Low"), rs.getString("Closing_Price"), rs.getString("Today_Change"), rs.getString("Currency"), rs.getString("Profit") }); } dbcon.con.close(); } catch (Exception ex) { Logger.getLogger(clientLogin.class.getName()).log(Level.SEVERE, null, ex); } } }//GEN-LAST:event_searchClientBtnActionPerformed private void tableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMouseClicked // TODO add your handling code here: setSelectedStock(); }//GEN-LAST:event_tableMouseClicked private void tableKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tableKeyPressed // TODO add your handling code here: //up arrow (40), down arrow (38), enter-key (10) if (evt.getKeyCode() == 40 || evt.getKeyCode() == 38 || evt.getKeyCode() == 10) { setSelectedStock(); } }//GEN-LAST:event_tableKeyPressed private void tableMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMouseDragged // TODO add your handling code here: setSelectedStock(); }//GEN-LAST:event_tableMouseDragged private void tableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tableKeyReleased // TODO add your handling code here: //up arrow (40), down arrow (38), enter-key (10) if (evt.getKeyCode() == 40 || evt.getKeyCode() == 38 || evt.getKeyCode() == 10) { setSelectedStock(); //System.out.println("after: " + StockInfoTable.getSelectedRow()); } }//GEN-LAST:event_tableKeyReleased private void transactionBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_transactionBtnActionPerformed // TODO add your handling code here: if (listOfClients.isSelectionEmpty()) { JOptionPane.showMessageDialog(getContentPane(), "Please Select a Client", "Transaction Error", JOptionPane.ERROR_MESSAGE); } else { String selectedClient = listOfClients.getSelectedValue(); String[] array = new String[1]; array[0] = selectedClient; transactionFrame.main(array); } }//GEN-LAST:event_transactionBtnActionPerformed private void searchTraderBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchTraderBtnActionPerformed // TODO add your handling code here: if (listOfTraders.isSelectionEmpty()) { JOptionPane.showMessageDialog(getContentPane(), "Please Select a Trader", "Error", JOptionPane.ERROR_MESSAGE); } else { String selectedTrader = listOfTraders.getSelectedValue(); System.out.println(selectedTrader); try { DefaultListModel demoList = new DefaultListModel(); DBConnection dbcon = new DBConnection(); dbcon.establishConnection(); Statement stmt = dbcon.con.createStatement(); ResultSet rs = stmt.executeQuery("SELECT C.Name" + " FROM client as C, trader as t, trader_account as tc, account as a" + " WHERE C.Client_SSN = a.Client_SSN AND " + " tc.Trader_SSN = t.Trader_SSN " + " AND a.Trader_SSN = t.Trader_SSN " + " AND tc.username = \"" + selectedTrader + "\""); while (rs.next()) { demoList.addElement(rs.getString("Name")); } dbcon.con.close(); listOfClients = new JList(demoList); jScrollPane5.setViewportView(listOfClients); } catch (Exception ex) { Logger.getLogger(clientLogin.class.getName()).log(Level.SEVERE, null, ex); } } }//GEN-LAST:event_searchTraderBtnActionPerformed private void traderRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_traderRefreshActionPerformed // TODO add your handling code here: String[] array = new String[2]; array[0] = username; array[1] = companyName; dispose(); Manager.main(array); }//GEN-LAST:event_traderRefreshActionPerformed private void newTraderBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newTraderBtnActionPerformed AddTraderDialog.setVisible(true); }//GEN-LAST:event_newTraderBtnActionPerformed private void addTraderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addTraderButtonActionPerformed // TODO add your handling code here: try { DBConnection dbcon = new DBConnection(); dbcon.establishConnection(); Statement stmt = dbcon.con.createStatement(); int compid = 0; int manssn = 0; boolean allgood = true; ResultSet rs = stmt.executeQuery("SELECT ic.Id" + " FROM investment_company as ic" + " WHERE ic.Name = \"" + companyName + "\""); while (rs.next()) { compid = rs.getInt("Id"); } rs = stmt.executeQuery("SELECT Manager_SSN" + " FROM manager_account" + " WHERE username = \"" + username + "\""); while (rs.next()) { manssn = rs.getInt("Manager_SSN"); } if (this.usernamebox.getText().isEmpty() || this.passwordbox.getText().isEmpty() || this.traderssnbox.getText().isEmpty() || this.sectorbox.getText().isEmpty()) { allgood = false; JOptionPane.showMessageDialog(getContentPane(), "Please complete all fields.", "Empty Field Error", JOptionPane.ERROR_MESSAGE); } if (allgood && this.traderssnbox.getText().length() != 9) { this.traderssnbox.setText(""); allgood = false; JOptionPane.showMessageDialog(getContentPane(), "SSN must be 9 digits.", "SSN Error", JOptionPane.ERROR_MESSAGE); } if (allgood) { stmt.executeUpdate("INSERT INTO trader(Trader_SSN, Sector, Investment_Company_ID, Manager_SSN)" + " VALUES(" + Integer.parseInt(this.traderssnbox.getText()) + ", \"" + this.sectorbox.getText() + "\"," + compid + "," + manssn + ")"); stmt.executeUpdate("INSERT INTO trader_sector(Trader_SSN, Sector)" + " VALUES(" + Integer.parseInt(this.traderssnbox.getText()) + ", \"" + this.sectorbox.getText() + "\")"); stmt.executeUpdate("INSERT INTO trader_account(Trader_SSN, username, password)" + " VALUES(" + Integer.parseInt(this.traderssnbox.getText()) + ", \"" + this.usernamebox.getText() + "\"," + " \"" + this.passwordbox.getText() + "\")"); this.AddTraderDialog.setVisible(false); this.usernamebox.setText(""); this.passwordbox.setText(""); this.traderssnbox.setText(""); this.sectorbox.setText(""); } dbcon.con.close(); } catch (NumberFormatException nfe) { JOptionPane.showMessageDialog(getContentPane(), "SSN must be valid number.", "Number Error", JOptionPane.ERROR_MESSAGE); } catch (Exception ex) { Logger.getLogger(clientLogin.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_addTraderButtonActionPerformed private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed this.AddTraderDialog.setVisible(false); this.usernamebox.setText(""); this.passwordbox.setText(""); this.traderssnbox.setText(""); this.sectorbox.setText(""); }//GEN-LAST:event_cancelButtonActionPerformed private void passwordboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_passwordboxActionPerformed // TODO add your handling code here: }//GEN-LAST:event_passwordboxActionPerformed private void sectorboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sectorboxActionPerformed // TODO add your handling code here: }//GEN-LAST:event_sectorboxActionPerformed private void addTraderButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addTraderButton1ActionPerformed // TODO add your handling code here: try { DBConnection dbcon = new DBConnection(); dbcon.establishConnection(); Statement stmt = dbcon.con.createStatement(); int traderssn = 0; boolean allgood = true; String traderusername = this.listOfTraders.getSelectedValue(); ResultSet rs = stmt .executeQuery("SELECT ta.Trader_SSN" + " FROM trader_account as ta" + " WHERE ta.username = \"" + traderusername + "\""); while (rs.next()) { traderssn = rs.getInt("Trader_SSN"); } if (this.usernamebox1.getText().isEmpty() || this.passwordbox1.getText().isEmpty() || this.clientssnbox.getText().isEmpty() || this.namebox.getText().isEmpty() || this.clientagebox.getText().isEmpty()) { allgood = false; JOptionPane.showMessageDialog(getContentPane(), "Please complete all fields.", "Empty Field Error", JOptionPane.ERROR_MESSAGE); } int age = Integer.parseInt(this.clientagebox.getText()); if (allgood && age < 18) { this.clientagebox.setText(""); allgood = false; JOptionPane.showMessageDialog(getContentPane(), "Age must be 18 or older.", "Age Error", JOptionPane.ERROR_MESSAGE); } if (allgood && this.clientssnbox.getText().length() != 9) { this.clientssnbox.setText(""); allgood = false; JOptionPane.showMessageDialog(getContentPane(), "SSN must be 9 digits.", "SSN Error", JOptionPane.ERROR_MESSAGE); } if (allgood) { stmt.executeUpdate("INSERT INTO client(Client_SSN, Name, Age)" + " VALUES(" + Integer.parseInt(this.clientssnbox.getText()) + ", \"" + this.namebox.getText() + "\", " + Integer.parseInt(this.clientagebox.getText()) + ")"); stmt.executeUpdate("INSERT INTO account(Client_SSN, Account_Type, username, password, Trader_SSN)" + " VALUES(" + Integer.parseInt(this.clientssnbox.getText()) + ", \"" + this.accounttypebox.getSelectedItem() + "\", \"" + this.usernamebox1.getText() + "\", \"" + this.passwordbox1.getText() + "\", " + traderssn + ")"); this.AddClientDialog.setVisible(false); this.usernamebox1.setText(""); this.passwordbox1.setText(""); this.namebox.setText(""); this.clientssnbox.setText(""); this.clientagebox.setText(""); } dbcon.con.close(); } catch (NumberFormatException nfe) { JOptionPane.showMessageDialog(getContentPane(), "Age/SSN must be valid number.", "Number Error", JOptionPane.ERROR_MESSAGE); } catch (Exception ex) { Logger.getLogger(clientLogin.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_addTraderButton1ActionPerformed private void cancelButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButton1ActionPerformed // TODO add your handling code here: this.AddClientDialog.setVisible(false); this.usernamebox.setText(""); this.passwordbox.setText(""); this.traderssnbox.setText(""); this.sectorbox.setText(""); }//GEN-LAST:event_cancelButton1ActionPerformed private void passwordbox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_passwordbox1ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_passwordbox1ActionPerformed private void nameboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nameboxActionPerformed // TODO add your handling code here: }//GEN-LAST:event_nameboxActionPerformed private void addClientButtonnewTraderBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addClientButtonnewTraderBtnActionPerformed // TODO add your handling code here: if (listOfTraders.isSelectionEmpty()) { JOptionPane.showMessageDialog(getContentPane(), "Please Select a Trader", "Error", JOptionPane.ERROR_MESSAGE); } else { AddClientDialog.setVisible(true); } }//GEN-LAST:event_addClientButtonnewTraderBtnActionPerformed /** * @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(Manager.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Manager.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Manager.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Manager.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> //</editor-fold> /* Create and display the form */ username = args[0]; companyName = args[1]; System.out.println("Trader main: " + username); System.out.println("Trader Company: " + companyName); java.awt.EventQueue.invokeLater(() -> { new Manager().setVisible(true); }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JDialog AddClientDialog; private javax.swing.JDialog AddTraderDialog; private javax.swing.JComboBox<String> accounttypebox; private javax.swing.JButton addClientButton; private javax.swing.JButton addTraderButton; private javax.swing.JButton addTraderButton1; private javax.swing.JButton allStockBtn; private javax.swing.JButton cancelButton; private javax.swing.JButton cancelButton1; private javax.swing.JTextField clientagebox; private javax.swing.JTextField clientssnbox; private javax.swing.JLabel companyText; private javax.swing.JLabel companyVariable; private javax.swing.JButton displayBtn; private javax.swing.JMenu flieMenuItem; private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel16; private javax.swing.JLabel jLabel17; 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.JMenuBar jMenuBar1; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JScrollPane jScrollPane4; private javax.swing.JScrollPane jScrollPane5; private javax.swing.JSeparator jSeparator1; private javax.swing.JList<String> listOfClients; private javax.swing.JList<String> listOfTraders; private javax.swing.JMenuItem logoutItem; private javax.swing.JTextField namebox; private javax.swing.JPanel panel; private javax.swing.JTextField passwordbox; private javax.swing.JTextField passwordbox1; private javax.swing.JButton searchClientBtn; private javax.swing.JLabel searchStock; private javax.swing.JButton searchTraderBtn; private javax.swing.JTextField sectorbox; private javax.swing.JLabel selectedStock; private javax.swing.JTable table; private javax.swing.JLabel trader; private javax.swing.JButton traderRefresh; private javax.swing.JTextField traderssnbox; private javax.swing.JLabel transaction; private javax.swing.JButton transactionBtn; private javax.swing.JTextField usernamebox; private javax.swing.JTextField usernamebox1; private javax.swing.JLabel variableStockChange; // End of variables declaration//GEN-END:variables }