Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

applet paint() refresh problems
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);
}

}




Report this thread to moderator Post Follow-up to this message
Old Post
foo
05-28-05 01:58 AM


Re: applet paint() refresh problems
try doing your for loop in a new thread. at the moment, it blocks the
initialisation of the applet.

public void init(){
Thread t = new Thread(this);
t.start();
}
public void run(){
for(;;){
// etc....
}
}

PS - do you want lines that have been drawn to remain on the screen or
not?
if not, call super.paint(g) in the paint method before you draw.
if so, you may want to store the coordinates of the lines and repaint
them.


Report this thread to moderator Post Follow-up to this message
Old Post
sanjay manohar
06-02-05 09:01 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:40 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.