Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

drawingJPanel's

Status
Not open for further replies.

blizeH

Programmer
Feb 20, 2005
1
GB
Hi, I'm basically creating an area that any number of ants up to 10 can be manipulated and moved around the area. I'm thinking of maybe using a drawingJPanel but instead of actually using a rectangle/circle or other shape I was going to use a text character as an ant ( ¥ ) and go from there.

Is there something similar to a drawingJPanel that allows me to insert a character instead of a shape, but still be able to move it around using co-ordinates?

Cheers,
blizeH
 
What I suggest :
1) create a class that extends Component and redefine it's paint(Graphics) method like this :
Code:
public void paint(Graphics g) {
   g.drawString("§", 10,10);
   // Change char and position
}

2) set the layout to the containing Jpanel to null.
3) add one instance of the above defined component to your panel.
4) the end of the story is about mouseMotion listeners to add to the commponent in order for it to "follow" mouse cursor.

The main advantage of this method is that when you will want to do a "prettyest" ant, you'll just have to refactor the paint method of your component (or create another one the same way).

Water is not bad as long as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top