• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple question about Panels

 
John McGahee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am adding 2 panels in an applet. Now I want to add shapes to these two panels and draw lines on it. IT seems I can't do both, if I add components and then try to draw on the panel, the drawing wipes out the components. How can I do both. Say if I had to draw something like this (pardon my drawing skills are not up the park)
___
|___|
|
|
___
|___|
Now these squares I'm adding in the start() method like
Panel p1 = new Panel();
p1.add(squareImage);
getContentPanel().add(p1);
and then to draw I have the following code in the start() method
Graphics g = p1.getGraphics();
g.drawLine(x1, y1, x2, y2);
But as it turns out I either see the line or the square (depending on what gets called on repaint)
is there a better way to do this? which method should I put the different sections of this code?
Any feedback is more than welcome I'm kinda running out of ideas up here...lol
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the DrawTest in the applets\demo directory of the jdk do what you want? It just does lines and points but it still leaves them like you want.
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John,
You should be able to overwrite the paint method of the Applet in order to perform your drawing. In order to get other components to show up just call the parent paint method first.

Regards,
Manfred.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic