Click to See Complete Forum and Search --> : How Do You Put 2 Containers Into a Single Applet?


lightofj
08-27-2005, 01:44 PM
As the topic suggests... :D

nspils
08-27-2005, 02:51 PM
Containers can be contained because they derive from the Component class ...

Therefore, you add containers to a container the same way you would add other components to a container ...

Have your Applet (or JApplet), add your JPanel, JList, JTextArea, TextBox, or other containers, to the outermost container. Remember the various organizing layouts of your choosing.

Norm
08-27-2005, 02:53 PM
What class does Container derive from?
When you see that you'll know.

lightofj
08-27-2005, 05:22 PM
i forgot to state i have to use jdk 1.1.8... so no java swing... and that's a big problem for me...

Norm
08-27-2005, 09:10 PM
So what is the problem now?
Do you get an error message when you try to add a Container to an Applet?
Please post it.

nspils
08-28-2005, 12:40 AM
As Norm indicated, the AWT is still available to you.

You can find an article on AWT for 1.0 and 1.1 at http://java.sun.com/products/jdk/awt/

and a "Short Course" at http://java.sun.com/developer/onlineTraining/awt/contents.html

lightofj
08-30-2005, 12:02 PM
what i dun understand is, usually a java file extends only one container, or should i say it can only extend one container. but i need to put 2 containers into my applet. so how do i actually do that?

nspils
08-30-2005, 03:16 PM
Here is a basic structure ...


class myApplet extends Applet
{
ScrollPane myScrollPane;
Panel myFirstPanel;
Panel mySecondPanel;

public void init()
{

establish layout, other attributes/properties of the applet

constuction code, etc. for myFirstPanel
add( myFirstPanel);

construction code, etc. for mySecondPanel
myFirstPanel.add(mySecondPanel);

construction code, etc. for myScrollPane
myApplet.add( myScrollPane);

}

public void start()
{
}

public void stop()
{
}

Norm
08-30-2005, 06:12 PM
I guess there is confusion in what you mean by:
to put 2 containers into my applet

We assumed that you wanted to use the Container.add() method. This will add a Component to the container. The above code added several Panels (which are Containers) to the Applet which is a Container. (which is == extends somewhere)

But you're talking about 'extend'? That's something different.
Could you explain what it is that you are trying to do?

lightofj
08-31-2005, 12:51 AM
I have a game that requires constant repainting to show movement. Because it requires constant repainting, it covers up a "colorButtonBar" that paints only once over on the applet, therefore I figured that I needed to have 2 Containers, one at the top to display the game, one at the bottom to display the bar.

Norm
08-31-2005, 09:13 AM
Do you understand the difference between extends and add()?

nspils
08-31-2005, 09:35 AM
Your predicament is just the kind of reason WHY you can add containers into containers - to protect one portion of your UI from activity you want to enable in another part.

Norm's questions to you are focused on your use of the word "extend" - a term of art implying inheritance from a parent class. Containers in the AWT do not have to extend any other class - unless, like Applet, it is a concrete class which cannot be implemented so you have to extend it.

You ADD components to containers (and since containers are components, you can add them, too) - you do not EXTEND a new container from another container in your UI. Just implement another Panel or Pane ... a new instance of the appropriate container class.

lightofj
08-31-2005, 01:02 PM
so what u mean is that in my current code that extends a Container, i add a container right?

nspils
08-31-2005, 04:13 PM
Yup - just add a container to your container.

By the way ...

Why is your current code extending "a Container"? Are you actually extending "THE" Container class? What functionality are you implementing which calls for that, rather than using one of the pre-existing Java Classes which extend Container? No matter what, you can add a container to a container, and your class is a container.