Java2D Clearing a Frame

This is a discussion on Java2D Clearing a Frame within the Tech Board forums, part of the Community Boards category; Please do not flame me for bringing up java on our board, but I have a question that has been ...

  1. #1
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    Java2D Clearing a Frame

    Please do not flame me for bringing up java on our board, but I have a question that has been sitting for a long time on the Java Technologies Board, and has not been answered.

    I have drawn with the graphics object on a jframe.
    I want to delete the drawings on the frame and start over new.
    Can I delete all drawings on that JFrame?
    Possibly a method call that would erase all drawings. I'm wanting to reuse the frame for an additional drawing after it has been cleared.

    Thank you for any help you provide.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    A JFrame is a container widget that you add components to. Im not sure exactly what your drawing to but to remove everything from a JFrame use this...

    myFrame.getContentPane().removeAll();

  3. #3
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    I believe you can simple do a fillRect() with a specified colour to clear the JFrame's contents.

    Also, I think it is widely accepted that drawing directly on a JFrame is bad form. You should do your drawing on a derived JPanel class, and use it as the JFrame's content pane (using setContentPane()).

  4. #4
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Location
    Mt. Prospect, IL
    Posts
    2,572
    >>I believe you can simple do a fillRect() with a specified colour to clear the JFrame's contents.
    <<

    yeah, but your method just covers whats underneath...Perspective's method is better.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  5. #5
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    removeAll() just removes components from the JFrame.

    It doesn't actually redraw the JFrame.

  6. #6
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    i searched google and found the following bit of code in a post that was made about 2 years ago. surprisingly it was not purged off the newsgroup it was located on. chalk another win for google. tell me what you think. yes it is a good way to do it, or no it isn't and why.

    Code:
    Graphics x = getGraphics();
    x.clearRect(0,0,400,400);	 //400 X 400 (frame size)
    again what i'm trying to do is erase the frame i'm drawing using a graphics object and with graphic methods (drawOval() & drawLine()). again thank you for the help. on the java board, i didn't get much assistance at all.

    btw the following doesn't work in my code for some reason.

    Quote Originally Posted by Perspective
    myFrame.getContentPane().removeAll();
    i'm extending jframe and using the inharitence. i executed the code with
    Code:
    getContentPane().removeAll();
    and nothing happened

    another fu question
    Quote Originally Posted by Dante Shamest
    Also, I think it is widely accepted that drawing directly on a JFrame is bad form. You should do your drawing on a derived JPanel class, and use it as the JFrame's content pane (using setContentPane()).
    why is it bad form? can you draw to a content pane similar like to a jframe?
    i have attached my code as .txt for comments on how to fix the bad form.
    please forgive the horrible commenting. I haven't finished the project yet.
    Attached Files Attached Files
    Last edited by xviddivxoggmp3; 11-19-2004 at 01:15 AM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Clearing Terminal
    By mrginger in forum C Programming
    Replies: 3
    Last Post: 04-15-2009, 11:58 AM
  2. Frame buffer not working
    By Noise in forum Game Programming
    Replies: 1
    Last Post: 02-15-2009, 11:05 AM
  3. Animation not working....
    By aquinn in forum C Programming
    Replies: 7
    Last Post: 02-19-2005, 04:37 AM
  4. the effects of textures on my frame rate
    By DavidP in forum Game Programming
    Replies: 37
    Last Post: 10-03-2003, 11:24 AM
  5. Text based frame in win32 console
    By GaPe in forum C Programming
    Replies: 8
    Last Post: 04-16-2002, 07:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21