File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes Clear Screen Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Clear Screen" Watch "Clear Screen" New topic
Author

Clear Screen

James Hambrick
Ranch Hand

Joined: Sep 04, 2004
Posts: 282

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"?


Visit my blog! http://jameshambrick.com
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

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.


[Jess in Action][AskingGoodQuestions]
James Hambrick
Ranch Hand

Joined: Sep 04, 2004
Posts: 282

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

Joined: Sep 04, 2004
Posts: 282

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

Joined: Sep 04, 2004
Posts: 282

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

Joined: Jul 08, 2003
Posts: 24166
    
  30

If you override paintComponent(), you MUST start off by calling super.paintComponent(). !
James Hambrick
Ranch Hand

Joined: Sep 04, 2004
Posts: 282

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

Joined: Sep 04, 2004
Posts: 282

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

Joined: Apr 01, 2009
Posts: 11
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..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Clear Screen
 
Similar Threads
Applet Size
Refresh Applet
Accessing the components of a bean from an applet
how to see button in an applet ?
controlling asp from applets