home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2817
Discussions: 188,384, Posts: 2,243,509, Members: 232,615
Old March 2nd, 2003, 09:58 PM   Digg it!   #1 (permalink)
Ultimate Member
 
Tekk's Avatar
 
Join Date: Oct 2001
Location: Pasadena, CA
Posts: 2,152
Java GUI Help (ComboBox stuff)

Can someone give me an idea why the matching result is printed twice when I place it in the output window?

Code:
//-------------------------------------------------------
  public void itemStateChanged(ItemEvent ie)
  {
    if (ie.getSource() == acctList)
    {
      int testInt = Integer.parseInt((String) acctList.getSelectedItem());
      for (int x = 0; x < v.size(); x++)
      {
        Accounts a = (Accounts) v.elementAt(x);
        if (a.getAcctNum() == testInt)
        {
          output.append(a.toString());
          break;
        }
      }
    }
  }
//-------------------------------------------------------
It prints out the same account information twice. Im using append because I want it to obviously keep the results of the previous transactions in the output window. I cant figure out why it does it twice tho...does it consider the opening and closing of the ComboBox a seperate event, thus counting it twice????


The combo list consists of the account numbers only
Code:
for (int x = 0; x < v.size(); x++)
    {
      Accounts a = (Accounts) v.elementAt(x);
      acctList.addItem(a.getAcctNum() + "");
    }
Takes the info from v (vector) and adds the accountNum. pretty simple. Since addItem has to be of type Object I had to use the + "" to make the int a String.
__________________
YAH! I knew you'd be jealous

Tekk is offline   Reply With Quote
Old March 2nd, 2003, 10:20 PM     #2 (permalink)
Banned
 
qball's Avatar
 
Join Date: Oct 2001
Posts: 447
I'm not sure....

The only issue I see is this:

output.append(a.toString());

you seem to be evoking the Object Accounts toString method. I'm not sure what that is....

I think you just want to append the account #?

output.append(testInt);

If that no likey not string...

output.append(new Integer(testInt).toString());

or cast to string?

output.append((String)testInt);

Post back if still issues...

qball is offline   Reply With Quote
Old March 2nd, 2003, 10:43 PM     #3 (permalink)
Ultimate Member
 
Tekk's Avatar
 
Join Date: Oct 2001
Location: Pasadena, CA
Posts: 2,152
Im using the accounts class toString() because the parameter for ouput.append(STRING) is STRING. Putting just the object variable will not work.

I am trying to output the whole account object. I suppose it would be easier if I just did a submit button once i choose the account number but eh..thats no fun! I wanna learn something here

Tekk is offline   Reply With Quote
Old March 2nd, 2003, 11:07 PM     #4 (permalink)
Ultimate Member
 
Tekk's Avatar
 
Join Date: Oct 2001
Location: Pasadena, CA
Posts: 2,152
well when I was transfering the above code to an inner class, I just happened to type ActionListener instead of ItemListener. I decided to continue to see if it would work fine. And guess what...it did!!! I have no idea why...heres the code that I put:

mind you this is an inner class:

Code:
private class ComboBoxListener implements ActionListener
  {
  //-------------------------------------------------------
  public void actionPerformed(ActionEvent ae)
  {
    int testInt = Integer.parseInt((String) acctList.getSelectedItem());
    for (int x = 0; x < v.size(); x++)
    {
      Accounts a = (Accounts) v.elementAt(x);
      if (a.getAcctNum() == testInt)
      {
        output.append(a.toString());
        break;
      }
    }
  }
  //-------------------------------------------------------
  } //END CBL
Tekk is offline   Reply With Quote
Old March 2nd, 2003, 11:12 PM     #5 (permalink)
Ultimate Member
 
Tekk's Avatar
 
Join Date: Oct 2001
Location: Pasadena, CA
Posts: 2,152
AN EVEN BETTER VERSION OF THE CODE!!!!

Code:
private class ComboBoxListener implements ActionListener
  {
  //-------------------------------------------------------
  public void actionPerformed(ActionEvent ae)
  {
    int index = acctList.getSelectedIndex();
    Accounts a = (Accounts) v.elementAt(index);
    output.append(a.toString());
  }
  //-------------------------------------------------------
  } //END CBL
Tekk is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Most Active Discussions
Is It Just Me? (2897)
CPU wont boot (6)
3-days in and no threads about Gaza (160)
The United States Debt (20)
I think I just killed my computer w.. (24)
hp compaq nc6000 problems (139)
Upgrading RAM (5)
Folderchat Weekday thread (442)
Antec 300 bulk purchase? (11)
Recent Discussions
CPU wont boot (6)
GLaDOS is up. (3)
HP notebook reinstall Vista NO .. (5)
Building a gaming computer advi.. (4)
hp compaq nc6000 problems (139)
Folderchat Weekday thread (442)
Creative T-3000 Subwoofer (3)
ACPI controller halt on boot (2)
Worth the upgrade?? (15)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 10:42 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28