Hey I am still just learning Java programming, and I am working on a program for Warhammer 40K (yeah im a nerd) that will cut out a lot of the dice rolling involved.

Anyways, I am making the menu for now, and I have one class for each menu so far, and I want to link all the classes to run from one master class that runs the applet. I tried to do it all in one class, but it would have been thousands of lines, and many linking problems I just didnt want to deal with. Anyone know how to link the classes that way? My teacher suggested Object references, but i dont know how to use them. Any suggestions?

01-07-2009, 12:13 AM

Fubarable

There is no difference on how you'd use multiple classes here with applets as you would with any java project that uses multiple classes. Have you created a class previously that was used by another class? I'm sorry, but I'm not quite sure exactly what your question is.

Best of luck.

01-07-2009, 09:13 AM

hardwired

Anyone know how to link the classes that way? My teacher suggested Object references, but i dont know how to use them. Any suggestions?
Yes. There are many ways to put things together. Here's an example to give you an idea:

public class MultiClass extends JApplet {
// Object references can be declared:
// ClassType variableName;
// or declared and instantiated:
// ClassType reference/variable = new Object();
// Object on right hand side is created/instantiated
// with the [i]new[/i] operator. A reference to it,
// saved in a member variable, is what we use to
// access the objects fields and methods.
// Use the "view" variable to access fields and call
// methods in this new instance of the View class.
View view = new View();
// Create an instance of the Control class and save
// a reference to it (the new object) in the member
// variable "control".
Control control = new Control(view);

class Control implements ActionListener, ChangeListener {
// Object reference to the instance of the View class
// being shown in the applet. You can use this object
// reference to access fields and call methods in this
// instance of View.
View view;
JSlider xSlider;
JSlider ySlider;

Create separate java files for each class and make the classes as public class.

01-07-2009, 11:47 PM

lordbob75

Ok, so is the slideshow class supposed to link the classes togetther? I am only a beginning programmer, that confused me a little bit....

01-08-2009, 02:22 AM

hardwired

is the slideshow class supposed to link the classes togetther?
The linking of classes is usually done in the class that has the main method and builds/shows the gui (graphical user interface). This is a logical place to assemble/put everything (components) together.
In the example the linking is done in the JApplet, here:

Code:

public class MultiClass extends JApplet {
View view = new View();
Control control = new Control(view);