File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes changing vector from GUI events Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "changing vector from GUI events" Watch "changing vector from GUI events" New topic
Author

changing vector from GUI events

kenji mapes
Ranch Hand

Joined: Jun 16, 2005
Posts: 38
Let me see if I can explain this without posting code.

I have a GUI class that extends JFrame and implements listeners, so the calss itself is the listener. The handlers are overriden in this calss.

In my driver class, I create a vector to hold instances of of type derived Vehicles (my abstract class), with the specific instances being "vanilla" cars, family cars, economy cars, and motorcycles.

I create the vector outside of the GUI calss so that I can reference it outside of a GUI instance. I pass the vector to the GUi constructor, and it adds the vector to a JList and a JComboBox. That is a bit reundant, but I wanted to play with both components so I could learn them.

Now for the event handling, I wanted to be able to add vehicles, remove vehicles, and sell vehicles from the handles on the buttons named "sell," "remove," and "add."

I'd like for the vector to be updated with these actions. I have code in the definition of actionPerformed.

For example, when a user wants to add a vehicle, I have input to select the vehicle type, and then prompt the user for info to store, and then pass to a new vehicle instantiation. I wanted this new object to be added to the vector, and then added to the combo box and list.

However, in my class definition it says that I cannot access the vector refeence variable that is declared in main, and then passed to the GUI contructor.

What gives? Thanks.

Kenji
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> declared in main

declare it as a class member

kenji mapes
Ranch Hand

Joined: Jun 16, 2005
Posts: 38
Thanks Michael, I will try that. I was thinking that the vector would be accessible in the same folder, same package, but I guess my idea of scope is not fully refined.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: changing vector from GUI events
 
Similar Threads
Java errors?
need help with JPanel, liseners, and referencing vectors
inheritence
layout managers and GUI
Need Help with Java Beans