Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /*
- * Window.java
- *
- * Created on Dec 10, 2009, 12:51:18 AM
- */
- package customer;
- import javax.swing.JOptionPane;
- import javax.swing.UIManager;
- import javax.swing.UnsupportedLookAndFeelException;
- /**
- *
- * @author dontiveros
- */
- public class Window extends javax.swing.JFrame {
- Database walmart = new Database();
- /** Creates new form Window */
- public Window() {
- try {
- // Set System L&F
- UIManager.setLookAndFeel(
- UIManager.getSystemLookAndFeelClassName());
- }
- catch (UnsupportedLookAndFeelException e) {
- // handle exception
- }
- catch (ClassNotFoundException e) {
- // handle exception
- }
- catch (InstantiationException e) {
- // handle exception
- }
- catch (IllegalAccessException e) {
- // handle exception
- }
- initComponents();
- }
- /** This method is called from within the constructor to
- * initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is
- * always regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jLabel1 = new javax.swing.JLabel();
- guiAdd = new javax.swing.JButton();
- guiDelete = new javax.swing.JButton();
- guiList = new javax.swing.JButton();
- guiName = new javax.swing.JTextField();
- guiSSN = new javax.swing.JTextField();
- guiAreaCode = new javax.swing.JTextField();
- guiPhone = new javax.swing.JTextField();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- jLabel4 = new javax.swing.JLabel();
- jLabel5 = new javax.swing.JLabel();
- jMenuBar1 = new javax.swing.JMenuBar();
- jMenu1 = new javax.swing.JMenu();
- jMenuItem1 = new javax.swing.JMenuItem();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("Customer Application - Assignment 7");
- setResizable(false);
- jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14));
- jLabel1.setText("Customer Appilcation GUI");
- guiAdd.setBackground(java.awt.Color.white);
- guiAdd.setText("Add Customer");
- guiAdd.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- guiAddActionPerformed(evt);
- }
- });
- guiDelete.setBackground(java.awt.Color.white);
- guiDelete.setText("Delete Customer");
- guiDelete.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- guiDeleteActionPerformed(evt);
- }
- });
- guiList.setBackground(java.awt.Color.white);
- guiList.setText("List Customers");
- guiList.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- guiListActionPerformed(evt);
- }
- });
- guiName.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- guiNameActionPerformed(evt);
- }
- });
- jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
- jLabel2.setText("Customer Name");
- jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
- jLabel3.setText("Social Security Number");
- jLabel4.setBackground(java.awt.Color.white);
- jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12));
- jLabel4.setText("Area Code");
- jLabel5.setBackground(java.awt.Color.white);
- jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12));
- jLabel5.setText("Phone Number");
- jMenu1.setText("File");
- jMenuItem1.setText("Quit");
- jMenuItem1.setToolTipText("Quit Program");
- jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenuItem1ActionPerformed(evt);
- }
- });
- jMenu1.add(jMenuItem1);
- jMenuBar1.add(jMenu1);
- 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()
- .addGap(130, 130, 130)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel2)
- .addComponent(jLabel5)
- .addComponent(jLabel4)
- .addComponent(jLabel3))
- .addGap(37, 37, 37)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addComponent(guiPhone, javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(guiSSN)
- .addComponent(guiName, javax.swing.GroupLayout.DEFAULT_SIZE, 171, Short.MAX_VALUE)
- .addComponent(guiAreaCode, javax.swing.GroupLayout.Alignment.LEADING))
- .addContainerGap(137, Short.MAX_VALUE))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap(225, Short.MAX_VALUE)
- .addComponent(jLabel1)
- .addGap(211, 211, 211))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap(105, Short.MAX_VALUE)
- .addComponent(guiAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(39, 39, 39)
- .addComponent(guiDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(34, 34, 34)
- .addComponent(guiList, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(68, 68, 68))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(30, 30, 30)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(guiName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel2))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(guiSSN, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel3))
- .addGap(13, 13, 13)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(guiAreaCode, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel4))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(guiPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel5))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 42, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(guiDelete)
- .addComponent(guiAdd)
- .addComponent(guiList))
- .addGap(41, 41, 41))
- );
- pack();
- }// </editor-fold>
- private void guiAddActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- //Strings first
- String tempSSN = guiSSN.getText();
- String tempAreaCode = guiAreaCode.getText();
- String tempPhone = guiPhone.getText();
- int ssnParsed = 0;
- int acParsed = 0;
- int phoneParsed = 0;
- /*
- = (int) Integer.parseInt(guiSSN.getText().trim());
- * = (int) Integer.parseInt(guiAreaCode.getText().trim());
- * = (int) Integer.parseInt(guiPhone.getText().trim());
- */
- if (tempSSN.length() == 9)
- {
- try
- {
- ssnParsed = (int) Integer.parseInt(guiSSN.getText().trim());
- }
- catch (Exception ssn)
- {
- JOptionPane.showMessageDialog(this, "Bad SSN - Enter Digits only with no dashes", "Error", JOptionPane.ERROR_MESSAGE);
- System.out.println("Required Informaton Missing.");
- return;
- }
- }
- else
- {
- JOptionPane.showMessageDialog(this, "SSN should be 9 digits long", "Error", JOptionPane.ERROR_MESSAGE);
- return;
- }
- if (tempAreaCode.length() == 3)
- {
- if (tempAreaCode.equals("713") || tempAreaCode.equals("281"))
- {
- acParsed = (int) Integer.parseInt(guiAreaCode.getText().trim());
- }
- else
- {
- JOptionPane.showMessageDialog(this, "Area Code Should be 713 or 281", "Error", JOptionPane.ERROR_MESSAGE);
- System.out.println("Required Informaton Missing.");
- return;
- }
- }
- else
- {
- JOptionPane.showMessageDialog(this, "Area Code Should be 3 Digits", "Error", JOptionPane.ERROR_MESSAGE);
- System.out.println("Required Informaton Missing.");
- return;
- }
- if (tempPhone.length() == 7)
- {
- try
- {
- phoneParsed = (int) Integer.parseInt(guiPhone.getText().trim());
- }
- catch (Exception phone)
- {
- JOptionPane.showMessageDialog(this, "Bad Phone Number", "Error", JOptionPane.ERROR_MESSAGE);
- System.out.println("Required Informaton Missing.");
- return;
- }
- }
- else
- {
- JOptionPane.showMessageDialog(this, "Phone Number Need to be 7 digits", "Error", JOptionPane.ERROR_MESSAGE);
- System.out.println("Required Informaton Missing.");
- return;
- }
- int index = -1;
- for(int y = 0; y < walmart.data.size(); y++)
- {
- if (walmart.data.get(y).getSocialSecurityNumber() == ssnParsed )
- index = y;
- }
- if (index == -1)
- {
- walmart.addCustomer(guiName.getText(), ssnParsed, acParsed, phoneParsed);
- }
- else
- {
- JOptionPane.showMessageDialog(this, "Record Exists", "Error", JOptionPane.ERROR_MESSAGE);
- System.out.println("Existing Record!");
- }
- guiName.setText("");
- guiSSN.setText("");
- guiAreaCode.setText("");
- guiPhone.setText("");
- }
- private void guiDeleteActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- String temp = "";
- temp = guiSSN.getText();
- if (temp.length() == 9)
- {
- //Start of check
- int index = -1;
- for(int y = 0; y < walmart.data.size(); y++)
- {
- if (walmart.data.get(y).getSocialSecurityNumber() == (int) Integer.parseInt(guiSSN.getText().trim() ))
- index = y;
- }
- if (index != -1)
- {
- walmart.removeCustomer((int) Integer.parseInt(guiSSN.getText().trim()));
- }
- else
- {
- JOptionPane.showMessageDialog(this, "No Such Record!", "Error", JOptionPane.ERROR_MESSAGE);
- System.out.println("No Such Record!");
- }
- }
- else
- {
- JOptionPane.showMessageDialog(this, "SSN should be 9 digits long", "Error", JOptionPane.ERROR_MESSAGE);
- System.out.println("Please enter SSN.");
- }
- }
- private void guiListActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- String tempdata = "";
- String data = "";
- if( walmart.data.size() != 0 )
- {
- for( int i=0; i< Customer.getNumberOfObjects();i++)
- {
- tempdata = walmart.data.get(i).getName()
- + " "
- + walmart.data.get(i).getSocialSecurityNumber()
- + " "
- + walmart.data.get(i).getPhoneAreaCode()
- + " "
- + walmart.data.get(i).getPhoneNumber()
- + "\n";
- data = data + tempdata;
- }
- JOptionPane.showMessageDialog(this, data, "Record Layout", JOptionPane.INFORMATION_MESSAGE);
- walmart.listCustomers();
- return;
- }
- else
- {
- //System.out.println("There is no record.");
- }
- walmart.listCustomers();
- if( walmart.data.size() == 0)
- JOptionPane.showMessageDialog(this, "There are no records", "Error", JOptionPane.ERROR_MESSAGE);
- return;
- }
- private void guiNameActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- System.exit(1);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new Window().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton guiAdd;
- private javax.swing.JTextField guiAreaCode;
- private javax.swing.JButton guiDelete;
- private javax.swing.JButton guiList;
- private javax.swing.JTextField guiName;
- private javax.swing.JTextField guiPhone;
- private javax.swing.JTextField guiSSN;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JLabel jLabel5;
- private javax.swing.JMenu jMenu1;
- private javax.swing.JMenuBar jMenuBar1;
- private javax.swing.JMenuItem jMenuItem1;
- // End of variables declaration
- }
Add Comment
Please, Sign In to add comment