Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / May 2005

Tip: Looking for answers? Try searching our database.

refreshing/paint()

Thread view: 
foo - 27 May 2005 21:48 GMT
the following applet is supposed to draw random lines on the screen, but
doesn't. does anyone know how to make it refresh?

thanks in advance

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;
import java.text.*;
import java.lang.*;

public class UI2 extends Applet{
 private int x1,y1,x2,y2;

 public void init() {
   for(;;) {
     x1=(int)(Math.random()*100);
     y1=(int)(Math.random()*100);
     x2=(int)(Math.random()*100);
     y2=(int)(Math.random()*100);
     repaint();
   }
 }

 public void paint(Graphics g) {
   g.setColor(Color.black);

   g.drawLine(x1, y1, x2, y2);
 }

 public void update(Graphics g) {
   paint(g);
 }

}
Skip - 28 May 2005 16:54 GMT
>   public void init() {
>     for(;;) {
[quoted text clipped - 5 lines]
>     }
>   }

repaint() does not repaint straight away, but schedules it in another thread
which might be processed at any time in the future.

With your tight loop you don't give the other thread any time to process the
repaint-requests. Futher: this code never leaves the init() so it will
probably never reach paint(g)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.