• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Simple question about Panels

 
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
 
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.
 
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.
 
You didn't tell me he was so big. Unlike this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic