Results 1 to 4 of 4
Thread: Couple questions about Java
- 05-18-2010, 10:14 PM #1
Member
- Join Date
- May 2010
- Posts
- 2
- Rep Power
- 0
Couple questions about Java
I'm currently trying to do my final project for my Java class. Here is a screen-shot of a completed version.

It's going to be an applet and may possibly be written in three classes: FinalProjectInit, CBus, and CThing. On the assignment sheet it says "Typically the CBus class will keep track of other objects using a Vector or an array."
and "CThing class - a class used for instantiating objects managed by CBus."
There was a total of four projects you could do so I don't know if everything said applies to my project.
For the project there are three pictures, each of a person and along with them is a name. When we select a radio button, it says (name assigned to picture) is (whatever radio button is selected). The button "Next" moves to the next picture along with that name and does the same thing.
Would I even need a vector for this project? I'm also a bit confused on what would go into CBus. My CThing currently looks like this:
import java.awt.Image;
public class CThing{
public static final int cpokemonRed = 1, cpokemonBlue = 2, cpokemonYellow = 3;
private String name, game;
private Image image;
public CThing(String n){
}
public String getName() {
return name;
}
public void setName(String n) {
this.name = n;
}
public String getGame() {
return game;
}
public void setGame(String g) {
this.game = g;
}
public Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
public String toString(){
return this.getName() + " is playing " + this.getGame();
}
}
Chunk from the Goonies, Samus Aran, and Chris Farley are my three images/names. And my output should look like: (name) is playing (one of the three pokemon games).
I'm pretty lost on this thing. I have nothing in CBus yet and I know I have more to do in CThing/FinalProjectInit.
Any help would be greatly appreciated.Last edited by theadolescent; 05-18-2010 at 10:30 PM.
- 05-18-2010, 11:53 PM #2
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
You're going to have 3 CThings to deal with, and one way to make dealing with a collection of objects is either an array or a Collection (such as a Vector, but I usually prefer an ArrayList -- but stick with what your instructor told you).
So assume that you're using a Vector<CThing>, you'll also give this class an int to represent the index in the Vector of the currently displayed image / currently selected JRadioButton. You would change this index if the radiobutton is pressed or the next button is pressed, and then use the new index to select a CThing object out of the Vector for display.
Give it a try and let's see what you can come up with.
Buena suerte!
- 05-19-2010, 02:08 AM #3
Member
- Join Date
- May 2010
- Posts
- 2
- Rep Power
- 0
Hey thanks for the reply. I'm sort of confused on how to write the code for "you'll also give this class an int to represent the index in the Vector of the currently displayed image / currently selected JRadioButton". I guess I'm sort of confused on how/where to put something in the vector. I also don't really know what's supposed to go in CBus. It almost seems like there doesn't need to be one.
- 05-19-2010, 02:13 AM #4
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
You don't put the int variable in the vector at all. Please understand that this class will be a composition class: it will hold an int index field, a Vector field and public methods that allow you to set and get the index and get the CThing object held by the Vector that is currently being pointed at.
Similar Threads
-
Couple Questions on Thread
By Lil_Aziz1 in forum Threads and SynchronizationReplies: 5Last Post: 01-06-2010, 02:02 PM -
Couple of questions regarding threading
By exernet in forum New To JavaReplies: 1Last Post: 12-15-2009, 12:23 PM -
Couple of newbie questions
By ananasman in forum New To JavaReplies: 11Last Post: 11-20-2008, 11:54 PM -
a couple of questions about Software Engineering plz
By pheonix in forum New To JavaReplies: 9Last Post: 10-18-2008, 04:31 PM -
Java assignment - couple methods don't know how to figure out
By Snowboardmylife in forum New To JavaReplies: 1Last Post: 04-16-2008, 10:52 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks