Results 1 to 4 of 4
  1. #1
    varesa is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default 2D Graphics "flashing"

    I have been writing a java app, which is supposed to draw a line that changes.

    However I'm having some kind of weird "flashing". What is odd about this, it doesnt do this on my old linux machine. It happens only on my W7. I have not tried any other machines than these two.

    My code:
    This is the main loop:
    Java Code:
    PaintWindow window = new PaintWindow();
    while(true) {
    	Do some stuff();
    	window.repaint();
    	Wait.wait(4);
    }
    paint() of class PaintWindow:
    Java Code:
    	public void paint(Graphics g) {
    		int xOrigin = this.getInsets().left;
    		int yOrigin = this.getInsets().bottom;
    		int yOffset = this.getHeight();
    		int[] cannonPos = Control.getCannon();
    		g.drawLine(this.getWidth()/2, yOffset-yOrigin, this.getWidth()/2+cannonPos[0] ,yOffset-cannonPos[1]);
    		
    		
    	}
    vid of this "flashing" (dont mind the red numbers, they were made by my recording software)

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,559
    Rep Power
    23

    Default

    What class is the paint method in? With Swing classes you'll get better results overriding the paintComponent method. Also calling super in the paint method can change the imaging.

    What execution thread is the while loop using? There will be a problem if it uses the GUIs thread.

    Can you create a small program that compiles and executes and demonstrates the problem?


    Do any of the following change between calls to the paint method? If not they could be done once outside the method.
    Java Code:
                    int xOrigin = this.getInsets().left;
    		int yOrigin = this.getInsets().bottom;
    		int yOffset = this.getHeight();
    Last edited by Norm; 08-15-2011 at 09:14 PM.

  3. #3
    varesa is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    What class is the paint method in? With Swing classes you'll get better results overriding the paintComponent method. Also calling super in the paint method can change the imaging.
    This is code I got from somewhere...

    First code I pasted, is basically what my main() {} contains. It instantiates(I think, Im not so good with the terminology) PaintWindow class, does some calculations, and tells it (PaintWindow window) to redraw.

    What is this "super"?

    What execution thread is the while loop using? There will be a problem if it uses the GUIs thread.
    I have not created any threads, or anything. It should be all running in one. I didn't know it was really important in this kind of awt-app. In SWT it was pretty tight


    Can you create a small program that compiles and executes and demonstrates the problem?
    I can't do right now, will do later, if needed.

    Do any of the following change between calls to the paint method? If not they could be done once outside the method.
    Java Code:
                    int xOrigin = this.getInsets().left;
    		int yOrigin = this.getInsets().bottom;
    		int yOffset = this.getHeight();
    Well.. The insets should not change, unless windows changes themes (I think...), but the height can change. First two lines might not be necessary.

    It runs fine on the other machine...

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,559
    Rep Power
    23

    Default

    Ok, there isn't much to do until you get a small program to demo the problem.

Similar Threads

  1. adding drawing images on a "Graphics instance"
    By imorio in forum New To Java
    Replies: 1
    Last Post: 02-19-2011, 10:30 PM
  2. Replies: 3
    Last Post: 10-12-2010, 04:21 PM
  3. Replies: 1
    Last Post: 01-21-2010, 09:20 AM
  4. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Tags for this Thread

Posting Permissions

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