[2407] in java-interest
Re: Applet questions
daemon@ATHENA.MIT.EDU (Arthur van Hoff)
Sat Sep 30 10:18:44 1995
Date: Fri, 29 Sep 1995 09:46:56 -0700
From: Arthur.Vanhoff@Eng.Sun.COM (Arthur van Hoff)
To: raychen@loop.com
Cc: java-interest@java.Eng.Sun.COM
Hi Ray,
> (1) Is there a way to pass what Applet #1 gets from user input to
> Applet #2?
Yes. Here are two simple applets that illustrate the principle:
--
import java.awt.*;
public class Applet1 extends java.applet.Applet {
public boolean handleEvent(Event evt) {
Applet2 buddy = (Applet2)getAppletContext().getApplet("buddy");
return (buddy != null) ? buddy.handleEvent(evt) : false;
}
}
--
import java.awt.*;
public class Applet2 extends java.applet.Applet {
String str = "";
public boolean handleEvent(Event evt) {
str = evt.toString();
repaint();
return true;
}
public void paint(Graphics g) {
g.drawString(str, 0, size().height * 2 / 3);
}
}
--
<applet code=Applet1.class width=100 height=100>
</applet>
<applet code=Applet2.class width=400 height=30 name=buddy>
</applet>
> (2) Is there a way to get the path of a file given only the filename?
> (i.e. is there a way to search the file system for a file with it's path?)
> I know that in java.lang.io there's a method getPath(), but all the File
> constructors need directory (or path) info in order to instanciate a File
> object. Now, what I want to know requires the input of what I want to know.
> It looks like an endless circle. Any ideas?
The only way to do that is to write a method that looks file the file by
trying to access it in several places. This is what the compiler does.
Have fun,
Arthur van Hoff
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com