473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

combobox's + buttons + actionlisteners

Ok ive been looking around and i have having the same problem as this fellow<Removed> im trying to use the same action listener for the buttons and the combo boxes it doesnt seem to be working. check out some code, and thanks for your help


Expand|Select|Wrap|Line Numbers
  1. public void actionPerformed(ActionEvent event)
  2.       {
  3.             JComboBox yearcombo = (JComboBox)event.getSource(); //i get an error here
  4.            JComboBox gendercombo = (JComboBox)event.getSource();
  5.  
  6.            JComboBox statecombo = (JComboBox)event.getSource();
  7.         if (event.getSource() == clear)
  8.         {
  9.             for( int i=0; i<firsta.size(); i++)
  10.         {
  11.  
  12.     System.out.println("First Name: "+firsta.get(i));
  13.     System.out.println("Last Name: "+lasta.get(i));
  14.     System.out.println("Age: "+agea.get(i));
  15.     System.out.println("Street Address: "+streeta.get(i));
  16.     System.out.println("City Name: "+citya.get(i));
  17.    // System.out.println("State Name: "+statea.get(i));
  18.    // System.out.println("Year: "+yeara.get(i));
  19.     //System.out.println("Gender: "+gendera.get(i));
  20.  
  21. }
  22.            clearall = true;
  23.            if (clearall = true)
  24.            {
  25.             street.setText(null);
  26.             first.setText(null);
  27.             last.setText(null);
  28.             age.setText(null);
  29.             city.setText(null);
  30.         //    gender.setText(null);
  31.             clearall=false;
  32.         }
  33.  
  34.         }    
  35.  
  36.         if (event.getSource() == Bok)
  37.            {
  38.  
  39.                //String g = gendercombo.getSelectedItem();
  40.               //gendera.add(i,genderselect);
  41.               // String y= yearcombo.getSelectedItem();
  42.               // yeara.add(i,yearselect);
  43.               // String s= statecombo.getSelectedItem();
  44.               // statea.add(i,stateselect);
  45.  
  46.               try{
  47.     // Create file 
  48.     FileWriter fstream = new FileWriter("database.txt");
  49.         BufferedWriter out = new BufferedWriter(fstream);
  50.  
  51.         for( int i=0; i<firsta.size(); i++)
  52.         {
  53.  
  54.     out.write("First Name:  "+firsta.get(i));
  55.     out.newLine();
  56.     out.write("Last Name:   "+lasta.get(i));
  57.     out.newLine();
  58.     out.write("Age:  "+agea.get(i));
  59.     out.newLine();
  60.     out.write("Street Address:  "+streeta.get(i));
  61.     out.newLine();
  62.     out.write("City Name:  "+citya.get(i));
  63.     out.newLine();
  64.     out.newLine();
  65.     out.write("State Name: "+statea.get(i));
  66.     out.write("Year: "+yeara.get(i));
  67.     out.write("Gender: "+gendera.get(i));
  68.  
  69. }
  70.     //Close the output stream
  71.     out.close();
  72.     }catch (Exception e){//Catch exception if any
  73.       System.out.println("Error: " + e.getMessage());
  74.     }
  75.  
  76.             //System.out.println(i);
  77.             //System.out.println(firsta.get(i));
  78.  
  79.  
  80.  
  81.  
  82.  
  83.             clearall = false;
  84.  
  85.         } 
  86.  
  87.         if (event.getSource() == Bcc)
  88.            {
  89.  
  90.                f1.dispose();
  91.            }
  92.         if (event.getSource() == submit)
  93.         {
  94.  
  95.  
  96.  
  97.             // Get the new item
  98.            String yearselect = (String)yearcombo.getSelectedItem();
  99.  
  100.  
  101.  
  102.  
  103.  
  104.             // Get the new item
  105.          String genderselect = (String)gendercombo.getSelectedItem();
  106.  
  107.  
  108.  
  109.  
  110.             // Get the new item
  111.        String stateselect = (String)statecombo.getSelectedItem();
  112.  
  113.  
  114.           firststring = first.getText();
  115.             firsta.add(i,firststring);
  116.             laststring = last.getText();
  117.             lasta.add(i,laststring);
  118.              try{
  119.             agestring = age.getText();
  120.             ageint = Integer.parseInt(agestring); 
  121.              }catch (Exception e){//Catch exception if any
  122.       System.out.println("Error: Numbers only....");
  123.     }
  124.             agea.add(i,ageint);
  125.             streetstring = street.getText();
  126.             streeta.add(i,streetstring);
  127.             citystring = city.getText();
  128.             citya.add(i,citystring);
  129.             yeara.add(i,yearselect);
  130.             gendera.add(i,genderselect);
  131.             statea.add(i,stateselect);
  132.  
  133.             i++;
  134.  
  135.  
  136.             street.setText(null);
  137.             first.setText(null);
  138.             last.setText(null);
  139.             age.setText(null);
  140.             city.setText(null);
  141.  
  142.  
  143.  
  144.  
  145.  
  146.         }
Oct 7 '07 #1
1 2101
r035198x
13,262 8TB
Starting multiple threads on the same topic not only confuses eveyone, it is also against the site's posting guidelines. Better stick to one thread for the same problem. This post of yours doesn't make much sense.
You just dumped some code here and asked us to help you with it.
Help you do what?
Oct 8 '07 #2

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

Similar topics

6
by: Georges Heinesch | last post by:
An easy ComboBox question. ;) I would like to create a ComboBox, which permits to cycle through 3 subforms. These 3 subforms are entered in the ComboBox as Value List. The subforms should only...
2
by: Zlatko Matić | last post by:
I have several forms hierarchycaly nested in each other (form/subform/subform/subform....). The final form is "continous form", while parent forms are single forms through which navigation was...
0
by: Hiroyuki Tanaka | last post by:
Hi All, I am trying to develop an application for a touch screen using buttons for the numeric pad with Completion ComboBoxes. At the moment I am having a problem sending the button presses to...
2
by: John Tyce | last post by:
When a button is clicked, a date is inserted or added into a combo box like this : ComboBox.Items.Add(string) or ComboBox.Items.Insert(0,string); Either way, the new string does not show up in the...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
2
by: VBTricks.de.vu Webmaster | last post by:
Hello, I'm still reimplementing the GUI of my app using the new toolstrips. My current problem is to autosize a combobox to the available with in the parent toolstrip. There are some buttons...
6
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox...
3
by: Eric | last post by:
Hi. I have this Combobox name 'Origin' that contains all states and countries. I would like to create two Radio buttons (State and Country) that when you select State, the combobox will query only...
6
akashazad
by: akashazad | last post by:
Hi Friends, Question:- In my VB6.0 Form I have used a ComboBox and a ToolBar in which I have provided some buttons such as Add,Modify,Abort,Delete,Save,Print,Exit. and also provided shortcuts to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.