• 0

[JAVA] many classes/objects


Question

Im creating a little program to move lines around.

My project has 4 classes

Main class

Table class

Line class

Thread class

Main class:

creates a window/object of the Table class

creates a second Thread

creates 3 objects of the Lines class

the second Thread will then just keep running by moving the lines around the screen.

in the table class i have a method that can get and set the limits in the window where the lines will bounce

and my plan was to use the values from the table in the thread but I cant call the method.

how am I to design my program so my objects can get and set information even if they are from different classes and objects?

I am trying to follow the golden rules of OO programming so I have lots of methods :) .

creating the lines from the table class and moving them around works just fine... but this is not then correct way to do it... I suppose.

Edited by Puskas
Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

I'm guessing this is an assignment? maybe you should post a link to the actual assignment so we can read what it says.

I am trying to follow the golden rules of OO programming so I have lots of methods

good add more methods :) ..... just kidding- OO programming is not about having lots of methods, but you will learn.

on another note: I think you may need to work with event listeners, push, firestate change models, but until I see some more info I cant help you

Link to comment
Share on other sites

  • 0

well I dont plan to solve this for you, but this is what I think... not sure if it would work or not

1: create instance of table

2: adds 3 Line threads that impelement "PropertyChangeListener" to table, passing inital size of table when constructing thread

3: when table size changes, table firePropertyChangeEvent(oldVal, newVal); - the threads will pick up the event and change there table size paramters accordingly.

does this sound like what you want to do.

also you can use listener as a flag to stop/pause the threads

Link to comment
Share on other sites

  • 0

yes, but the coordination system/routine is in the thread class, and I cant get any info from the table class because the thread class cant see the objects i created from the main class..

so not just solving my current problem, but what do I have to think about when designing a program that needs to comunicate with other classes and objects not created by the object/class i need the info from/to... :)

Link to comment
Share on other sites

  • 0

The event model that I talked about !!!!!!

//you normally pull information like this

Thread Object{aSize = getTable().whatIsGridSize() }

//now you want to have the information pushed through listeners

Table Object {size change, fireStateChange() for thread to listen to} --->

Thread Object {propertyChangeEvent() heard a change to table, now do something}

Link to comment
Share on other sites

  • 0
yes, but the coordination system/routine is in the thread class, and I cant get any info from the table class because the thread class cant see the objects i created from the main class..

so not just solving my current problem, but what do I have to think about when designing a program that needs to comunicate with other classes and objects not created by the object/class i need the info from/to... :)

You can pass them into the constructors of the objects you create.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.