[4808] in java-interest

home help back first fref pref prev next nref lref last post

Re: Must applets and associated classes stick together?

daemon@ATHENA.MIT.EDU (Harwijn Bolwit)
Mon Jan 15 19:00:24 1996

Date: Mon, 15 Jan 1996 23:44:08 +0100 (MET)
From: Harwijn Bolwit <harwijn@alibaba.dds.nl>
To: "John D. Kane" <john@insightnews.com>
cc: "' java@java.sun.com'" <java@java.sun.com>,
        "Arthur.Vanhoff" <Arthur.Vanhoff@Eng.Sun.COM>,
        "'java-interest@java.sun.com'" <java-interest@java.sun.com>,
        "'jug@solect.com'" <jug@solect.com>
In-Reply-To: <30FB05CF@insightnews.com>

On Mon, 15 Jan 1996, John D. Kane wrote:

> I've asked this question before. What I received was a response saying I 
> should use the codebase tag to try and take care of this problem. I haven't 
> been able to do that since my applet and imported classes are in separate 
> subdirectories. Now I'm looking for a straight answer, no guessing, no 
> beating around the bush ... Must my custom classes reside in the same 
> directory as the applet which calls them at runtime?
> 
> John

Yes you can. But you have to keep the Applet's itself in one directory,
if there are using the same imported classes. Here's a (goofy) example:

in a public www directory there's:

Show.html:
---
<applet code="Show.class">
</applet>
---

Show.java:
---
import msg.Message;
import java.applet.Applet;
import java.awt.Event;

public class Show extends Applet {
	Message one,two;

	public Show() {
		one = new Message("MouseClick!");
		two = new Message("MouseUp!");
	}
	public boolean mouseDown(Event evt, int x, int y) {
		one.showMe(this);
		return true;
	}
	public boolean mouseUp(Event evt, int x, int y) {
		two.showMe(this);
		return true;
	}
}
---

in subdirectory "msg" there's:

Message.java:
---
package msg;

import java.lang.String;
import java.applet.Applet;
import java.applet.AppletContext;

public class Message extends Object {
	String msg;
		
	public Message(String s) {
		msg = s;
	}

	public void showMe(Applet a) {
		a.getAppletContext().showStatus(msg);
	}
}
---

To compile Show.java you must have "." (current directory) in your
CLASSPATH.

You must put your imported classes in a package, and import that package
in the Applet's .java files.

(you still need the codebase tag to point to your shared Applet directory)
(N.B. be very careful to declare public what needs to be declared public)

Hope this helps.

Harwijn
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post