[5253] in java-interest
Re: Applet in frame / UDP works
daemon@ATHENA.MIT.EDU (Walter Szewelanczyk)
Sat Feb 3 22:04:12 1996
From: "Walter Szewelanczyk" <Walter@adco.com>
To: Tim Moons <tim@innet.be>, java-interest@java.sun.com
Date: Sat, 3 Feb 1996 20:44:32 +0000
Hi Tim,
on Sat, 03 Feb 1996 10:17:05 +0100 , Tim Moons <tim@innet.be>
wrote
> Does anybody know if it is possible to run a thread on a frame ???
> I want to run a clock on a frame that sends every minute a UDP-packet to
> our server. The meaning is that this goes on when our client surfs on.
>
> So, I want a different window as my netscape, that stays on top of the
> screen, while I surf on.
>
> BTW : I wrote a good working UDP-client and server, wich works online in
> the Netscape !!!!
>
I read it quickly and put together this simple example of a class
that extends Frame and implements runnable to give you a timer.
But now that I re-read it I am not sure if that is what you are
asking.
Just in case it is here is an example.
import java.awt.*;
import java.util.*;
class FrameThreadTest
{
public static void main(String args[])
{
FrameThread Win = new FrameThread("ThreadFrame");
Win.show();
}
}
class FrameThread extends Frame implements Runnable
{
Thread GO;
long Delay;
public FrameThread(String title)
{
super(title);
Delay = 5*1000; //5 seconds in milliseconds
GO = new Thread(this);
GO.start();
}
public void run()
{
while(true)
{
SendPacket();
try
{
Thread.sleep(Delay);
}
catch(InterruptedException E)
{
// Put appropriate exception code here
System.out.println("Exception : "+E);
}
}
}
private void SendPacket()
{
System.out.println("hi it is now "+new Date());
}
}
This should be an application that shows a tiny window but prints the
time every 5 seconds. You could have also Subclassed Frame and
created a new class that extends Thread and includes the same run
routine and SendPacket class and had the Frame subclass create that thread.
Again I am not sure if that was what you were asking but anyway.
I hope it helps,
Walt
********************************************************************************************
Walter Szewelanczyk Technical Director
Walter@adco.com NET VENTURE, Inc.
http://www.adco.com
"One must stay in a very RIGID state of FLEXABILITY"
********************************************************************************************
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com