• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Applets and Threads

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've got a problem with my applet. I want to create a new object which extends thread. While that object is active it continuously calls the paint method of the applet. However upon compilation I'm told that I the non-static method cannot be called from a static context. Here's a snippet of the code:
<CODE>
class Projectile extends Thread {
int x,y;
boolean exists;
public Projectile(int x, int y) {
this.x=x;
this.y=y;
exists=true;
}
public void run() {
while (exists) {
x++;
if (x>640) exists=false;
war.draw();
try {
sleep(100);
}
catch (InterruptedException e) {}
}
}
}
</CODE>
The draw method in the applet War just calls repaint(). I'm informed that draw isn't static and I can't make it static since repaint() cannot be overriden to be static. What am I doing wrong? Any suggestions would be appreciated.
 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
i was looking at ur code.whats the problem...
u can instantiate ur applet class and then can call the draw() method. it wont give u any error..
i hope ,i got correct understanding of ur question
 
reply
    Bookmark Topic Watch Topic
  • New Topic