Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clear Screen

 
James Hambrick
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"?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • 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
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • 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.
 
kunu patel
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..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic