473,472 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

imputing data in an array Please help.

53 New Member
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.
Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. public class Main
  6. {
  7.         JFrame f1;
  8.         JPanel p1,p2;
  9.        boolean clearall = false;
  10.        String[] firsta = new String[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };
  11.        String[] lasta = new String[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };
  12.        String[] agea = new String[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };
  13.        String[] citya = new String[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };
  14.        String[] streeta = new String[] { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };
  15.  
  16.  
  17.  
  18.  
  19.  
  20.        GP g1;
  21.         String firststring,laststring,agestring,streetstring,citystring,test;
  22.         JButton Bok,Bcc,clear,submit;
  23.         JTextField first,last,age,street,city,gender;
  24.         JLabel firstl,lastl,agel,streetl,cityl,genderl,monthl,statel,yearl;
  25.     public Main()
  26.     {  
  27.  
  28.        test = ("TESTSETSETSETSETSETSETSETSES");
  29.         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"};
  30.  
  31.         firstl = new JLabel("First Name");
  32.         lastl = new JLabel("Last Name");
  33.         agel = new JLabel("Age");
  34.         streetl = new JLabel("Street");
  35.         cityl = new JLabel("City");
  36.         genderl = new JLabel("Gender");
  37.         monthl = new JLabel("Month");
  38.         statel = new JLabel("State");
  39.         yearl = new JLabel("Year");
  40.         JComboBox yearcombo = new JComboBox(year);
  41.         yearcombo.setSelectedIndex(29);
  42.  
  43.          yearcombo.setEditable(false);
  44.         String[] month = { "January", "Febuary", "March", "April", "May", "June", "July", "October", "November", "December"};
  45.         JComboBox monthcombo = new JComboBox(month);
  46.         monthcombo.setEditable(false);
  47.         monthcombo.setSelectedIndex(9);
  48.  
  49.         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"};
  50.         JComboBox statecombo = new JComboBox(state);
  51.         statecombo.setSelectedIndex(49);
  52.  
  53.         String[] gender = {"M","F"};
  54.         JComboBox gendercombo = new JComboBox(gender);
  55.         gendercombo.setSelectedIndex(1);
  56.  
  57.         gendercombo.setEditable(false);
  58.  
  59.         MyActionListener actionListener = new MyActionListener();
  60.     yearcombo.addActionListener(actionListener);
  61.  
  62.     gendercombo.addActionListener(actionListener);
  63.  
  64.     statecombo.addActionListener(actionListener);
  65.         f1 = new JFrame("fafafffdas");
  66.           f1.setSize(832,200);        
  67.         Container c1 = f1.getContentPane();
  68.  
  69.  
  70.         p1 = new JPanel();
  71.         p1.setSize(1000,200);
  72.         p1.setLayout(new BorderLayout());
  73.  
  74.         first = new JTextField(12);
  75.         last = new JTextField(12);
  76.         age = new JTextField(12);
  77.         street = new JTextField(12);
  78.         city = new JTextField(12);
  79.         clear = new JButton("Clear");
  80.         clear.addActionListener(new ButtonListener());
  81.         submit = new JButton("Submit");
  82.         submit.addActionListener(new ButtonListener());
  83.         Bok = new JButton("Save");
  84.          Bok.addActionListener(new ButtonListener());
  85.         Bcc = new JButton("Quit");
  86.          Bcc.addActionListener(new ButtonListener());
  87.  
  88.  
  89.  
  90.           // Get number of items
  91.        //  int numyear = yearcombo.getItemCount();
  92.       // int numgender = statecombo.getItemCount();
  93.       // int numstate = gendercombo.getItemCount();
  94.  
  95.  
  96.  
  97.         p2 = new JPanel();  //panel to add JLabel and TextField
  98.  
  99.         g1 = new GP();    
  100.          p1.add(g1,BorderLayout.CENTER);
  101.  
  102.         g1.add(firstl);  
  103.         g1.add(first);
  104.         g1.add(lastl);
  105.         g1.add(last);
  106.         g1.add(agel);
  107.         g1.add(age);
  108.         g1.add(yearl);
  109.         g1.add(yearcombo);
  110.         g1.add(genderl);
  111.         g1.add(gendercombo);
  112.         g1.add(streetl);
  113.         g1.add(street);
  114.         g1.add(cityl);
  115.         g1.add(city);
  116.         g1.add(statel);
  117.         g1.add(statecombo);
  118.         p2.add(submit);
  119.         p2.add(Bok);
  120.         p2.add(clear);
  121.         p2.add(Bcc);
  122.  
  123.         p1.add(p2,BorderLayout.SOUTH);      //adds p2 to south (Bottom) Graphics Panel will be added to Center    
  124.         c1.add(p1);
  125.  
  126.         f1.show();
  127.  
  128.     }
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.      public class MyActionListener implements ActionListener
  139.      {
  140.         public void actionPerformed(ActionEvent evt)
  141.         {
  142.             JComboBox yearcombo = (JComboBox)evt.getSource();
  143.  
  144.             // Get the new item
  145.             Object yearselect = yearcombo.getSelectedItem();
  146.  
  147.  
  148.  
  149.             JComboBox gendercombo = (JComboBox)evt.getSource();
  150.  
  151.             // Get the new item
  152.             Object genderselect = gendercombo.getSelectedItem();
  153.  
  154.  
  155.  
  156.            JComboBox statecombo = (JComboBox)evt.getSource();
  157.  
  158.             // Get the new item
  159.             Object stateselect = statecombo.getSelectedItem();
  160.  
  161.         }
  162.     }
  163.  
  164.     private class ButtonListener implements ActionListener
  165.     {
  166.       public void actionPerformed (ActionEvent event)
  167.       {
  168.  
  169.  
  170.         if (event.getSource() == clear)
  171.         {
  172.             clearall = true;
  173.             if (clearall = true)
  174.             {
  175.             street.setText("");
  176.             first.setText("");
  177.             last.setText("");
  178.             age.setText("");
  179.             city.setText("");
  180.             gender.setText("");
  181.  
  182.             }
  183.         }    
  184.  
  185.         if (event.getSource() == Bok)
  186.            {
  187.  
  188.             firststring = first.getText();
  189.             laststring = last.getText();
  190.             agestring = age.getText();
  191.             streetstring = street.getText();
  192.             citystring = city.getText();
  193.  
  194.            }
  195.  
  196.         if (event.getSource() == Bcc)
  197.            {
  198.  
  199.                f1.dispose();
  200.            }
  201.         if (event.getSource() == submit)
  202.         {
  203.  
  204.             firststring = first.getText();
  205.             laststring = last.getText();
  206.             agestring = age.getText();
  207.             streetstring = street.getText();
  208.             citystring = city.getText();
  209.          clearall = true;
  210.  
  211.         }
  212.  
  213.           g1.repaint();  
  214.         }
  215.     }
  216.  
  217.  
  218. }
Sep 25 '07 #1
2 1410
r035198x
13,262 MVP
Please do not just dump all your code here.
If you are facing any specific problem just point that part out.
Sep 26 '07 #2
JosAH
11,448 Recognized Expert MVP
@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
Sep 26 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Kevin Knorpp | last post by:
Hello. I need to be able to extract the data from the attached file (or any file in the same format) so that I can work with the data in PHP. I'm fairly comfortable with using PHP with...
0
by: Duncan Smith | last post by:
Hello, I'm not very experienced in SQL and I need some advice. I have a comma separarated values file containing around 20 million records and about 20 fields. There are many missing values...
3
by: Jimski | last post by:
Hello all, I am having a problem where I get an error message when I call FlushFinalBlock when decrypting my encrypted text. I am using the Rijndael algorithm. The error message is "Length...
10
by: Nevets Steprock | last post by:
I'm writing a web program where one of the sections is supposed to output a correlation matrix. The typical correlation matrix looks like this: ..23 ..34 .54 ..76 .44 .28 ..02 .77 ...
2
by: salsipius | last post by:
Can someone please help me clarify the below code. I think the shifting has to do with converting datatypes and/or loss of data but am not really clear on the details, could you help shed some...
0
grassh0pp3r
by: grassh0pp3r | last post by:
Hello, I'm trying to make a very simple comments page on my site using PHP and am having problems somewhere. I am very new to PHP. I was able to create one that works with comments appended, but...
3
by: egarobar | last post by:
I am using Access 2003 (on WinXP) to read from an Oracle db, where there is a table with a CLOB which is a variable-size text field. In the 'linked table' which is created in the Tables panel of...
3
by: lilbit02 | last post by:
Hi, I want to grab data from a .csv file and add all the data to the array. I have the part where I'm grabbing the data from the .csv file but the array issue I haven't totally figured out. ...
4
by: TechnoAtif | last post by:
Hi ALL I have entered some array values using checkboxes into mysql database through a form. Next iam creating a searchpage where all those cateogories inserted through checkboxes has to be...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.