
January 29th, 2007, 04:44 AM
|
|
Registered User
|
|
Join Date: Jan 2003
Posts: 21
Time spent in forums: 54 m 25 sec
Reputation Power: 0
|
|
|
Problems with paint method
I have this two classe.
Code:
import java.awt.*;
class AnimatePanel extends Panel {
int x =60, y=60;
public void goAhead()
{
x++;
y++;
repaint();
}
public void paint(Graphics g)
{
g.setColor(Color.red);
g.drawRect(x, y, 20, 20);
}
}
Code:
import java.awt.*;
import java.applet.*;
public class Main extends Applet implements Runnable
{
Thread drawThread;
boolean running = false;
AnimatePanel draw;
int tempVal = 0;
public void init()
{
draw = new AnimatePanel();
setLayout(new BorderLayout());
add(draw);
drawThread = new Thread(this);
running = true;
drawThread.start();
}
public void destroy()
{
running = false;
drawThread = null;
}
public void run()
{
Thread tempThread = Thread.currentThread();
while (drawThread == tempThread)
{
draw.goAhead();
try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
System.out.println( "e jebiga!");
}
}
}
public void paint(Graphics g)
{
g.setColor(Color.red);
g.drawRect(10, 10, 200, 200);
}
}
class AnimatePanel does its paint method and probably override the paint method from Main class.
How can I solve it?
thanks in advanced
|