Address Book

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ttoboobz
    New Member
    • Oct 2006
    • 9

    Address Book

    Help anyone... I'm creating a simple address book java program that would store 100 records. The GUI should be able to accept the name, address, phone no., and email add of a person by clicking a button named ADD. It should also be able to EDIT or DELETE a record and can VIEW ALL ENTRIES.

    I have already INSTANTIATED the CLASS, and declared or created the necessary methods(accesso r, mutator & constructors) and the arrays(containe r). I also already created the FORM and the necessary textfield and buttons in it, in a separate CLASS under the same package. The codes for the FORM was automatically generated by the IDE.

    My problem is that, how am I going to make the GUI FORM work. Meaning to ADD, EDIT, DELETE or VIEW the entries.

    These are the codes so far:
    Code:
    package addressbook1;
    
    public class AddressBook1 {
        
        private String name;
        private String address;
        private String telNum;
        private String emailAdd;
        
        public AddressBook1(String name, String address, String telNum, String emailAdd){
            this.name = name;
            this.address = address;
            this.telNum = telNum;
            this.emailAdd = emailAdd;
        }
        
        public String getName(){
            return name;
        }
        public String getAddress(){
            return address;
        }
        public String getTelNum(){
            return telNum;
        }
        public String getEmailAdd(){
            return emailAdd;
        }
        
        public void setName(String tempName){
            name = tempName;
        }
        public void setAddress(String tempAddress){
            address = tempAddress;
        }
        public void setTelNum(String tempTelNum){
            telNum = tempTelNum;
        }
        public void setEmailAdd(String tempEmailAdd){
            emailAdd = tempEmailAdd;
        }
        
        public static void main(String []args){
            
        }
    
    }

    Due to limitation of text per discussion, I am posting the codes of the GUI FORM in another discussion titled "Address Book(con't)".
  • ttoboobz
    New Member
    • Oct 2006
    • 9

    #2
    Address Book(con't)

    Here's the GUI FORM codes generated by the IDE:

    Code:
    package addressbook1;
    
    
    public class AddressBookEntry extends javax.swing.JFrame {
        
        /** Creates new form AddressBookEntry */
        public AddressBookEntry() {
            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.
         */
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                          
        private void initComponents() {
            lbName = new javax.swing.JLabel();
            tfName = new javax.swing.JTextField();
            lbAddress = new javax.swing.JLabel();
            tfAddress = new javax.swing.JTextField();
            lbTelNum = new javax.swing.JLabel();
            tfTelNum = new javax.swing.JTextField();
            lbEmailAdd = new javax.swing.JLabel();
            tfEmailAdd = new javax.swing.JTextField();
            butAddEntry = new javax.swing.JButton();
            butUpdate = new javax.swing.JButton();
            butDelete = new javax.swing.JButton();
            butViewAllEntries = new javax.swing.JButton();
            butExit = new javax.swing.JButton();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Address Book");
            setName("entryForm");
            lbName.setText("NAME");
            lbName.setName("lbName");
    
            tfName.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
            tfName.setName("tfName");
    
            lbAddress.setText("ADDRESS");
            lbAddress.setName("lbAddress");
    
            tfAddress.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
            tfAddress.setName("tfAddress");
    
            lbTelNum.setText("Phone No.");
            lbTelNum.setName("lbTelNum");
    
            tfTelNum.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
            tfTelNum.setName("tfTelNum");
    
            lbEmailAdd.setText("e-mail");
            lbEmailAdd.setName("lbEmailAdd");
    
            tfEmailAdd.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
            tfEmailAdd.setName("tfEmailAdd");
    
            butAddEntry.setText("ADD ENTRY");
            butAddEntry.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
            butAddEntry.setName("butAddEntry");
    
            butUpdate.setText("UPDATE");
            butUpdate.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
            butUpdate.setName("butUpdate");
    
            butDelete.setText("DELETE");
            butDelete.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
            butDelete.setName("butDelete");
    
            butViewAllEntries.setText("VIEW ALL");
            butViewAllEntries.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
            butViewAllEntries.setName("butViewAllEntries");
    
            butExit.setText("EXIT");
            butExit.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
            butExit.setName("butExit");
    
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .addContainerGap()
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(butAddEntry, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                        .add(layout.createSequentialGroup()
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(lbName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 55, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(lbAddress)
                                .add(lbTelNum)
                                .add(lbEmailAdd))
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(tfAddress, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE)
                                .add(tfName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE)
                                .add(tfTelNum, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE)
                                .add(tfEmailAdd, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE)))
                        .add(layout.createSequentialGroup()
                            .add(butUpdate, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 98, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                            .add(butDelete, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 82, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                            .add(butViewAllEntries, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 91, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                            .add(butExit, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)))
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .addContainerGap()
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(lbName)
                        .add(tfName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(lbAddress)
                        .add(tfAddress, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(lbTelNum)
                        .add(tfTelNum, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(lbEmailAdd)
                        .add(tfEmailAdd, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(butAddEntry)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(butViewAllEntries)
                        .add(butExit)
                        .add(butDelete)
                        .add(butUpdate))
                    .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
            pack();
        }// </editor-fold>                        
        
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new AddressBookEntry().setVisible(true);
                }
            });
        }
        
        // Variables declaration - do not modify                     
        private javax.swing.JButton butAddEntry;
        private javax.swing.JButton butDelete;
        private javax.swing.JButton butExit;
        private javax.swing.JButton butUpdate;
        private javax.swing.JButton butViewAllEntries;
        private javax.swing.JLabel lbAddress;
        private javax.swing.JLabel lbEmailAdd;
        private javax.swing.JLabel lbName;
        private javax.swing.JLabel lbTelNum;
        private javax.swing.JTextField tfAddress;
        private javax.swing.JTextField tfEmailAdd;
        private javax.swing.JTextField tfName;
        private javax.swing.JTextField tfTelNum;
        // End of variables declaration                   
        
    }
    Your help is highly appreciated.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by ttoboobz
      Here's the GUI FORM codes generated by the IDE:

      Code:
      package addressbook1;
       
       
      public class AddressBookEntry extends javax.swing.JFrame {
       
      /** Creates new form AddressBookEntry */
      public AddressBookEntry() {
      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.
      */
      // <editor-fold defaultstate="collapsed" desc=" Generated Code "> 
      private void initComponents() {
      lbName = new javax.swing.JLabel();
      tfName = new javax.swing.JTextField();
      lbAddress = new javax.swing.JLabel();
      tfAddress = new javax.swing.JTextField();
      lbTelNum = new javax.swing.JLabel();
      tfTelNum = new javax.swing.JTextField();
      lbEmailAdd = new javax.swing.JLabel();
      tfEmailAdd = new javax.swing.JTextField();
      butAddEntry = new javax.swing.JButton();
      butUpdate = new javax.swing.JButton();
      butDelete = new javax.swing.JButton();
      butViewAllEntries = new javax.swing.JButton();
      butExit = new javax.swing.JButton();
       
      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
      setTitle("Address Book");
      setName("entryForm");
      lbName.setText("NAME");
      lbName.setName("lbName");
       
      tfName.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
      tfName.setName("tfName");
       
      lbAddress.setText("ADDRESS");
      lbAddress.setName("lbAddress");
       
      tfAddress.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
      tfAddress.setName("tfAddress");
       
      lbTelNum.setText("Phone No.");
      lbTelNum.setName("lbTelNum");
       
      tfTelNum.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
      tfTelNum.setName("tfTelNum");
       
      lbEmailAdd.setText("e-mail");
      lbEmailAdd.setName("lbEmailAdd");
       
      tfEmailAdd.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
      tfEmailAdd.setName("tfEmailAdd");
       
      butAddEntry.setText("ADD ENTRY");
      butAddEntry.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
      butAddEntry.setName("butAddEntry");
       
      butUpdate.setText("UPDATE");
      butUpdate.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
      butUpdate.setName("butUpdate");
       
      butDelete.setText("DELETE");
      butDelete.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
      butDelete.setName("butDelete");
       
      butViewAllEntries.setText("VIEW ALL");
      butViewAllEntries.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
      butViewAllEntries.setName("butViewAllEntries");
       
      butExit.setText("EXIT");
      butExit.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
      butExit.setName("butExit");
       
      org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
      layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
      .add(layout.createSequentialGroup()
      .addContainerGap()
      .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
      .add(butAddEntry, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
      .add(layout.createSequentialGroup()
      .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
      .add(lbName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 55, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
      .add(lbAddress)
      .add(lbTelNum)
      .add(lbEmailAdd))
      .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
      .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
      .add(tfAddress, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE)
      .add(tfName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE)
      .add(tfTelNum, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE)
      .add(tfEmailAdd, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE)))
      .add(layout.createSequentialGroup()
      .add(butUpdate, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 98, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
      .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
      .add(butDelete, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 82, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
      .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
      .add(butViewAllEntries, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 91, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
      .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
      .add(butExit, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)))
      .addContainerGap())
      );
      layout.setVerticalGroup(
      layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
      .add(layout.createSequentialGroup()
      .addContainerGap()
      .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
      .add(lbName)
      .add(tfName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
      .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
      .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
      .add(lbAddress)
      .add(tfAddress, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
      .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
      .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
      .add(lbTelNum)
      .add(tfTelNum, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
      .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
      .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
      .add(lbEmailAdd)
      .add(tfEmailAdd, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
      .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
      .add(butAddEntry)
      .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
      .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
      .add(butViewAllEntries)
      .add(butExit)
      .add(butDelete)
      .add(butUpdate))
      .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
      );
      pack();
      }// </editor-fold> 
       
      /**
      * @param args the command line arguments
      */
      public static void main(String args[]) {
      java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
      new AddressBookEntry().setVisible(true);
      }
      });
      }
       
      // Variables declaration - do not modify 
      private javax.swing.JButton butAddEntry;
      private javax.swing.JButton butDelete;
      private javax.swing.JButton butExit;
      private javax.swing.JButton butUpdate;
      private javax.swing.JButton butViewAllEntries;
      private javax.swing.JLabel lbAddress;
      private javax.swing.JLabel lbEmailAdd;
      private javax.swing.JLabel lbName;
      private javax.swing.JLabel lbTelNum;
      private javax.swing.JTextField tfAddress;
      private javax.swing.JTextField tfEmailAdd;
      private javax.swing.JTextField tfName;
      private javax.swing.JTextField tfTelNum;
      // End of variables declaration 
       
      }
      Your help is highly appreciated.
      Please keep one problem in one thread.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by ttoboobz
        Help anyone... I'm creating a simple address book java program that would store 100 records. The GUI should be able to accept the name, address, phone no., and email add of a person by clicking a button named ADD. It should also be able to EDIT or DELETE a record and can VIEW ALL ENTRIES.

        I have already INSTANTIATED the CLASS, and declared or created the necessary methods(accesso r, mutator & constructors) and the arrays(containe r). I also already created the FORM and the necessary textfield and buttons in it, in a separate CLASS under the same package. The codes for the FORM was automatically generated by the IDE.

        My problem is that, how am I going to make the GUI FORM work. Meaning to ADD, EDIT, DELETE or VIEW the entries.

        These are the codes so far:
        Code:
        package addressbook1;
         
        public class AddressBook1 {
         
        private String name;
        private String address;
        private String telNum;
        private String emailAdd;
         
        public AddressBook1(String name, String address, String telNum, String emailAdd){
        this.name = name;
        this.address = address;
        this.telNum = telNum;
        this.emailAdd = emailAdd;
        }
         
        public String getName(){
        return name;
        }
        public String getAddress(){
        return address;
        }
        public String getTelNum(){
        return telNum;
        }
        public String getEmailAdd(){
        return emailAdd;
        }
         
        public void setName(String tempName){
        name = tempName;
        }
        public void setAddress(String tempAddress){
        address = tempAddress;
        }
        public void setTelNum(String tempTelNum){
        telNum = tempTelNum;
        }
        public void setEmailAdd(String tempEmailAdd){
        emailAdd = tempEmailAdd;
        }
         
        public static void main(String []args){
         
        }
         
        }

        Due to limitation of text per discussion, I am posting the codes of the GUI FORM in another discussion titled "Address Book(con't)".


        To make the actions work you need to implement the relevant actions. If you have buttons on the form then all you need to do is to addActionListen ers to them and write the actions to be performed when the buttons are clicked.

        Comment

        • ttoboobz
          New Member
          • Oct 2006
          • 9

          #5
          Originally posted by r035198x
          To make the actions work you need to implement the relevant actions. If you have buttons on the form then all you need to do is to addActionListen ers to them and write the actions to be performed when the buttons are clicked.

          Can you give me the code for this? I mean, the codes for the actions to be made. Like for example, if I type a name on the TEXTFIELD on the FORM and click the ADD button, the name that I typed in will be added to the array for 100 records.

          Thanks.

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by ttoboobz
            Can you give me the code for this? I mean, the codes for the actions to be made. Like for example, if I type a name on the TEXTFIELD on the FORM and click the ADD button, the name that I typed in will be added to the array for 100 records.

            Thanks.
            I prefer that you write the code. You learn better that way.
            It's not at all difficult. Just make sure the button has the correct listeners registered for it and override the actionPerformed method.

            Comment

            Working...