imputing data in an array Please help.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • carlos123
    New Member
    • Sep 2007
    • 53

    #1

    imputing data in an array Please help.

    Ok i have a few different arrays for names, last names, address, and city , and i have a textfield for each one. Ultimatly i want my project to be able to enter the names in and hit "save" and it enteres it in to a database. Then i have a submit button, and i want it to write the database to a text file. here is what i have so far. it can be opened in bluej, but here is the code. thanks in advance for helping me out! i really need help here, thanks.
    Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class Main
    {
            JFrame f1;
            JPanel p1,p2;
           boolean clearall = false;
           String[] firsta = new String[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };
           String[] lasta = new String[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };
           String[] agea = new String[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };
           String[] citya = new String[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };
           String[] streeta = new String[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };
           
    
           
           
           
           GP g1;
            String firststring,laststring,agestring,streetstring,citystring,test;
            JButton Bok,Bcc,clear,submit;
            JTextField first,last,age,street,city,gender;
            JLabel firstl,lastl,agel,streetl,cityl,genderl,monthl,statel,yearl;
        public Main()
        {  
            
           test = ("TESTSETSETSETSETSETSETSETSES");
            String[] year = { "1980", "1981", "1982", "1983", "1984", "1985", "1986", "1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008" , "2009", "2010"};
           
            firstl = new JLabel("First Name");
            lastl = new JLabel("Last Name");
            agel = new JLabel("Age");
            streetl = new JLabel("Street");
            cityl = new JLabel("City");
            genderl = new JLabel("Gender");
            monthl = new JLabel("Month");
            statel = new JLabel("State");
            yearl = new JLabel("Year");
            JComboBox yearcombo = new JComboBox(year);
            yearcombo.setSelectedIndex(29);
     
             yearcombo.setEditable(false);
            String[] month = { "January", "Febuary", "March", "April", "May", "June", "July", "October", "November", "December"};
            JComboBox monthcombo = new JComboBox(month);
            monthcombo.setEditable(false);
            monthcombo.setSelectedIndex(9);
           
            String[] state = { "Alabama AL", "Alaska AK" ,"Arizona AZ", "Arkansas AR", "California CA" ,"Colorado CO", "Connecticut CT" ,"Delaware DE", "Florida FL","Georgia GA", "Hawaii HI"," Idaho ID","Illinois IL" ,"Indiana IN", "Iowa IA", "Kansas KS" ,"Kentucky KY" ,"Louisiana LA", "Maine ME", "Maryland MD" ,"Massachusetts MA", "Michigan MI" ,"Minnesota MN" ,"Mississippi MS" ,"Missouri MO", "Montana MT" ,"Nebraska NE", "Nevada NV" ,"New Hampshire NH" ,"New Jersey NJ", "New Mexico NM", "New York NY", "North Carolina NC", "North Dakota ND" ,"Ohio OH" ,"Oklahoma OK", "Oregon OR" ,"Pennsylvania PA" ,"Rhode Island RI", "South Carolina SC", "South Dakota SD" ,"Tennessee TN", "Texas TX" ,"Utah UT", "Vermont VT" ,"Virginia VA" ,"Washington WA", "West Virginia WV", "Wisconsin WI" ,"Wyoming WY"};
            JComboBox statecombo = new JComboBox(state);
            statecombo.setSelectedIndex(49);
    
            String[] gender = {"M","F"};
            JComboBox gendercombo = new JComboBox(gender);
            gendercombo.setSelectedIndex(1);
         
            gendercombo.setEditable(false);
            
            MyActionListener actionListener = new MyActionListener();
        yearcombo.addActionListener(actionListener);
    
        gendercombo.addActionListener(actionListener);
     
        statecombo.addActionListener(actionListener);
            f1 = new JFrame("fafafffdas");
              f1.setSize(832,200);        
            Container c1 = f1.getContentPane();
            
            
            p1 = new JPanel();
            p1.setSize(1000,200);
            p1.setLayout(new BorderLayout());
            
            first = new JTextField(12);
            last = new JTextField(12);
            age = new JTextField(12);
            street = new JTextField(12);
            city = new JTextField(12);
            clear = new JButton("Clear");
            clear.addActionListener(new ButtonListener());
            submit = new JButton("Submit");
            submit.addActionListener(new ButtonListener());
            Bok = new JButton("Save");
             Bok.addActionListener(new ButtonListener());
            Bcc = new JButton("Quit");
             Bcc.addActionListener(new ButtonListener());
             
             
             
              // Get number of items
           //  int numyear = yearcombo.getItemCount();
          // int numgender = statecombo.getItemCount();
          // int numstate = gendercombo.getItemCount();
           
        
             
            p2 = new JPanel();  //panel to add JLabel and TextField
            
            g1 = new GP();    
             p1.add(g1,BorderLayout.CENTER);
           
            g1.add(firstl);  
            g1.add(first);
            g1.add(lastl);
            g1.add(last);
            g1.add(agel);
            g1.add(age);
            g1.add(yearl);
            g1.add(yearcombo);
            g1.add(genderl);
            g1.add(gendercombo);
            g1.add(streetl);
            g1.add(street);
            g1.add(cityl);
            g1.add(city);
            g1.add(statel);
            g1.add(statecombo);
            p2.add(submit);
            p2.add(Bok);
            p2.add(clear);
            p2.add(Bcc);
    
            p1.add(p2,BorderLayout.SOUTH);      //adds p2 to south (Bottom) Graphics Panel will be added to Center    
            c1.add(p1);
           
            f1.show();
    
        }
     
           
    
        
      
       
      
    
       
         public class MyActionListener implements ActionListener
         {
            public void actionPerformed(ActionEvent evt)
            {
                JComboBox yearcombo = (JComboBox)evt.getSource();
        
                // Get the new item
                Object yearselect = yearcombo.getSelectedItem();
                
            
            
                JComboBox gendercombo = (JComboBox)evt.getSource();
        
                // Get the new item
                Object genderselect = gendercombo.getSelectedItem();
                
            
            
               JComboBox statecombo = (JComboBox)evt.getSource();
        
                // Get the new item
                Object stateselect = statecombo.getSelectedItem();
                
            }
        }
        
        private class ButtonListener implements ActionListener
        {
          public void actionPerformed (ActionEvent event)
          {
              
              
            if (event.getSource() == clear)
            {
                clearall = true;
                if (clearall = true)
                {
                street.setText("");
                first.setText("");
                last.setText("");
                age.setText("");
                city.setText("");
                gender.setText("");
                
                }
            }    
          
            if (event.getSource() == Bok)
               {
               
                firststring = first.getText();
                laststring = last.getText();
                agestring = age.getText();
                streetstring = street.getText();
                citystring = city.getText();
                
               }
               
            if (event.getSource() == Bcc)
               {
    
                   f1.dispose();
               }
            if (event.getSource() == submit)
            {
               
                firststring = first.getText();
                laststring = last.getText();
                agestring = age.getText();
                streetstring = street.getText();
                citystring = city.getText();
             clearall = true;
    
            }
    
              g1.repaint();  
            }
        }
        
        
    }
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Please do not just dump all your code here.
    If you are facing any specific problem just point that part out.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      @OP: that code of yours is never going to work as it is now; there are so many
      mistakes, lack of design etc. etc. in it. I suggest you start over again and dump
      this piece of code where it belongs: in the trash bin.

      I'm sorry for saying so but if you start all over chances are that you successfully
      finish your project. If you keep on hacking at random with this code you'll never
      finish this project no matter what you had in mind for it.

      Good luck with it and

      kind regards,

      Jos

      Comment

      Working...