Results 1 to 6 of 6
  1. #1
    ChazZeromus is offline Member
    Join Date
    Sep 2008
    Posts
    13
    Rep Power
    0

    Default JApplet.getGraphics() draws but JFrame doesn't

    In my program, I'm following a book saying that I should use GetStrategyBuffer from JFrame to properly perform active drawing on screen. Only problem is that nothing appears when I draw with JFrame's Graphic's context, it works well with my apps' main JApplet Graphics context, but the only way to use GetStrategyBuffer is from JFrame. Is there there some other way to do this?

  2. #2
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    Not sure, possibly JFrame.getRootPane().getGraphics() would work. The best way is to write it in the paintComponent(Graphics) method of JComponents. You may also need to make the update(Graphics) method call the paintComponent(Graphics) method.

    Java Code:
    public void paintComponent(Graphics g){
         //do painting method here
    }
    public void update(Graphics g){
         paintComponent(g);
    }
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  3. #3
    ChazZeromus is offline Member
    Join Date
    Sep 2008
    Posts
    13
    Rep Power
    0

    Default

    Well, Component doesn't have getBufferSrtategy though. I checked and it seems only JFrame has it. I looked at the javadoc for Component, it doesn't have it, nor does JFrame!! And also, doesn't overriding paintComponent a non active-drawing method? There's gotta be another way to do this without getBufferStrategy.

  4. #4
    ChazZeromus is offline Member
    Join Date
    Sep 2008
    Posts
    13
    Rep Power
    0

    Default

    Ok sorry about that, I found a way to do it without the horrid method! I just synced right after I drew everything with Toolkit.getDefaultToolkit().sync(), and then sleept the current thread a bit. I'd say this is one solution to the flickering and tearing problem.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by ChazZeromus View Post
    And also, doesn't overriding paintComponent a non active-drawing method?
    Yep. paintComponent override is for passive graphics. If you're doing active graphics, am I correct to assume that you're doing full-screen mode?

  6. #6
    ChazZeromus is offline Member
    Join Date
    Sep 2008
    Posts
    13
    Rep Power
    0

    Default

    Oh no, I'm making small 3d point render program where the camera can be controlled through the keyboard. So I need the window to constantly redraw so that small debug values displayed to the right of the projection can update accordingly whenever.

Similar Threads

  1. Replies: 4
    Last Post: 04-23-2009, 12:02 AM
  2. JFrame to JApplet or JApplet to JApplet
    By ramesh.8189 in forum AWT / Swing
    Replies: 13
    Last Post: 02-08-2009, 07:14 AM
  3. Replies: 0
    Last Post: 06-28-2008, 10:25 PM
  4. FreeHand Draws poorly
    By Chetanji in forum Java 2D
    Replies: 1
    Last Post: 04-24-2008, 05:26 PM
  5. help with converting to JApplet
    By Simmy in forum AWT / Swing
    Replies: 2
    Last Post: 08-09-2007, 09:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •