Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

using a thread to draw  RSS feed

 
tony cosgrave
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have an class that extends thread, and it creates enemies for an applet game i'm working on, the problem is i don't know the right way to get the enemies (a class themselves) drawn in the applet properly.
i create the enemies in the run() method of the EnemyThread, but i want to draw these enemies in the applet, how do i go about doing that?
thanks for your time
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24216
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Welcome to JavaRanch!
Give the Enemy class a drawMe(Graphics) method. Make sure that all the Enemy objects are available in an array or Collection. Then the Applet's paint() method can just loop over that collection, passing the Graphics object to each Enemy's drawMe() method in turn.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
trio number,
Welcome to JavaRanch!
Is that your real name? We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!