Results 1 to 4 of 4
  1. #1
    theadolescent is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Exclamation 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 11:30 PM.

  2. #2
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Quote Originally Posted by theadolescent View Post
    Would I even need a vector for this project?
    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!

  3. #3
    theadolescent is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Default

    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.

  4. #4
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    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

  1. Couple Questions on Thread
    By Lil_Aziz1 in forum Threads and Synchronization
    Replies: 5
    Last Post: 01-06-2010, 03:02 PM
  2. Couple of questions regarding threading
    By exernet in forum New To Java
    Replies: 1
    Last Post: 12-15-2009, 01:23 PM
  3. Couple of newbie questions
    By ananasman in forum New To Java
    Replies: 11
    Last Post: 11-21-2008, 12:54 AM
  4. Replies: 9
    Last Post: 10-18-2008, 05:31 PM
  5. Java assignment - couple methods don't know how to figure out
    By Snowboardmylife in forum New To Java
    Replies: 1
    Last Post: 04-16-2008, 11:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •