🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #16929

Re: how to use timer

#16929
From: Chris Hill
Date: Tue, 05 Jan 1999 00:00
97 lines
3340 bytes
I'll assume you mean the jbcl version.  It's hard to give a complete
example without posting a great deal of code and without giving you
the wrong impression about the way to use the timer.  The following
code is a few bits and pieces that should get you started.  Just
implement TimerClient and call startTimer, passing an instance of the
class that implements TimerClient.  You probably already have a frame
window for your application, so the best thing would be to implement
the Timer client there.

import borland.jbcl.util.Timer;
import borland.jbcl.util.TimerClient;

class AnyClassPerhapsYourFrame implements TimerClient
{
	static int myId = 1;
	static int myOtherId = 2;

	public void TimerEvent(int id)
	{
		/* if you only have one timer, you don't need to check

		(or even use) the id */
		if(id == myId) 
		{
			// handle the timer
		}
		else if(id == myOtherId)
		{
			// handle the other id
		}
	}
}

// Elsewhere in your code:

// timer_client is an instance of AnyClassPerhapsYourFrame
// For example, if you started the timer in the constructor of
// your frame which implements TimerClient, you might use "this" in
// place of "timer_client".

//Start timer(1000 millisecond period which fires until you call stop)
// You don't need to use the id if you are handling ony one 
// timer event
Timer.startTimer(timer_client, AnyClassPerhapsYourFrame.myId, 1000,
true);

// Later to stop the timer:
Timer.stopTimer(timer_client, AnyClassPerhapsYourFrame.myId);


On Tue, 05 Jan 1999 10:38:51 +0200, Ofir Amitai
<amitay@econ.haifa.ac.il> wrote:

>Hi
>
>Thanks for your help. could u please give me more detailed example ?
>
>Regrads
>Ofir Amitai
>
>
>Chris Hill wrote:
>
>> Borland has provided some Timer functionality with the
>> borland.jbcl.util.Timer class and the borland.jbcl.util.TimerClient
>> interface.
>>
>> Implement TimerClient in one of your classes (if you implement it in a
>> frame, it will be similar to C++ Builder where you implement the timer
>> event handler in your form's code).
>>
>> Next create a Timer instance and call the startTimer function.  Later
>> you can call the stopTimer if you wish.
>>
>> If you have a problem using Borland classes, you could use
>> javax.swing.Timer from JDK 1.2 or create your own class using Threads.
>> The basic idea is to spawn a new thread which sleeps for the period of
>> the timer then fires and event.
>>
>> On Mon, 04 Jan 1999 13:03:37 +0200, Ofir Amitai
>> <amitay@econ.haifa.ac.il> wrote:
>>
>> >Hi
>> >
>> >I need to use timer to execute a command in equal intervals
>> >in CBuilder I use the Timer component, what do I do in JBuilder ?
>> >
>> >Regrads
>> >Ofir Amitai
>> >
>>
>> Chris Hill
>> Chris244@aol.com
>

Chris Hill
Chris244@aol.com
Technical Details
Message-ID: <369223a3.407598796@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3690A008.C802EE4D@econ.haifa.ac.il> <3690c60f.318105441@forums.borland.com> <3691CF9A.EA310FE3@econ.haifa.ac.il>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,2f6728999b8f4dca
X-Google-Attributes: gidf74b3,public
From: Chris244@aol.com (Chris Hill)
Subject: Re: how to use timer
Date: 1999/01/05
Message-ID: <369223a3.407598796@forums.borland.com>
X-Deja-AN: 429031649
References: <3690A008.C802EE4D@econ.haifa.ac.il> <3690c60f.318105441@forums.borland.com> <3691CF9A.EA310FE3@econ.haifa.ac.il>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.language