🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.java.programmer
Article #640

The best synchronized Paint!

#640
From: Kim Frederiksen
Date: Tue, 23 Mar 1999 00:00
47 lines
1944 bytes
Hi Everybody,

I've been working on getting my paint synchronized as good as possible,
this is what I've come up with, can you think of something that would
work even better, let me know :-)

Kim Frederiksen

int currentTime;
int lastTime;
int appletSpeed=30; // Max wait time in milliseconds


public void start()
{
 startTime=(int) System.currentTimeMillis();
}

synchronized public void run ()
{
 while (true)
 {
  repaint();
  try
  {
   wait();
  }
  catch(InterruptedException e) { }
  currentTime=((int) System.currentTimeMillis())-startTime;
  sleepTime=(lastTime+appletSpeed)-currentTime;
  lastTime=currentTime;
  if(sleepTime>0)
  {
   try
   {
    spinThread.sleep(sleepTime);
   }
   catch(InterruptedException e) { }
  }
  lastTime=((int) System.currentTimeMillis())-startTime;
 }
}

synchronized public void paint(Graphics g)
{
     notifyAll();
}
Technical Details
Message-ID: <36F75CF1.37367641@greydirect.dk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f9a23,e7dc548027defe93,start
X-Google-Attributes: gidf9a23,public
X-Google-Thread: 100145,e7dc548027defe93,start
X-Google-Attributes: gid100145,public
X-Google-Thread: f5e83,e7dc548027defe93,start
X-Google-Attributes: gidf5e83,public
X-Google-Thread: 10a146,e7dc548027defe93,start
X-Google-Attributes: gid10a146,public
From: Kim Frederiksen <kf@greydirect.dk>
Subject: The best synchronized Paint!
Date: 1999/03/23
Message-ID: <36F75CF1.37367641@greydirect.dk>
X-Deja-AN: 457913612
Content-Transfer-Encoding: 7bit
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: Department of Abuse <abuse@news.inet.tele.dk>
X-Trace: news.inet.tele.dk 922180867 2548 194.192.200.51 (23 Mar 1999 09:21:07 GMT)
Organization: Grey Direct - Interactive
Mime-Version: 1.0
NNTP-Posting-Date: 23 Mar 1999 09:21:07 GMT
Newsgroups: comp.lang.java.programmer,comp.lang.java.softwaretools,dk.edb.programmering.java,microsoft.public.java.visualj++