Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Clear Screen

 
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an Applet that has three buttons on it, one being a clear screen button. I have it setup right now so it draws a rectangle the size of the applet and fills it with the background color. But when it does that my other two buttons disappear until I mouse over them again. Is there a better way to clear screen or anyway for the buttons to show back up after the "clear screen"?
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't draw the rectangle over the buttons! Instead of drawing directly on the applet, pack a subclass of JPanel into the applet , and do the drawing in that JPanel's paintComponent() method.
 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a good idea, I'll just have to figure out how to do that. My book I have isn't very good. Ill research it on various websites. Thanks for the advice.
 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a JPanel with
JPanel jp = new JPanel();

and set the layout
jp.setLayout(new FlowLayout());

This is the only code I have added so far. Is there something I'm missing???

I'm not sure how to draw on it. I have this code which draws.

 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed the name of the method from Paint(raphics g) to paintComponent(Graphics g) along with the editions I mentioned earlier and when I click Clear Screen the Red and Black buttons do not go away, but now I cant draw on the Panel. Any ideas why?

 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you override paintComponent(), you MUST start off by calling super.paintComponent(). !
 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was told to
"do the drawing in that JPanel's paintComponent() method" so I thought that is what I did. I dont have any examples of this so im kinda taking a shot in the dark when trying to implement the suggestions I get. If I call super.paintComponent() then I get an erros that says cannot find symbol.
 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think when I get home I will design this in NetBeans and see what it looks like. Even Sun's tutorial is not enough for me. Im using a content Pane and in Suns tutorials they are using Frames.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

James Hambrick wrote:I have created a JPanel with
JPanel jp = new JPanel();

and set the layout
jp.setLayout(new FlowLayout());

This is the only code I have added so far. Is there something I'm missing???

I'm not sure how to draw on it. I have this code which draws.



can you give full code for this clear screen applet ,...so i easily understand..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic