Results 1 to 6 of 6
  1. #1
    Unome is offline Member
    Join Date
    Oct 2008
    Posts
    44
    Rep Power
    0

    Default Remove Flashing in Applet

    Hi everybody,

    I usually draw to an offscreen image to solve this problem. But AffineTransform doesn't work with offscreen images so I have to find an alternative way to get rid of stupid flashing. Any ideas would be appreciated.

    thanks

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

    Default

    AffineTransform doesn't work with offscreen images
    It doesn't? This would surprise me if true.

  3. #3
    Unome is offline Member
    Join Date
    Oct 2008
    Posts
    44
    Rep Power
    0

    Default

    let me clarify WHY it doesn't.

    There are two ways (I know of) to use affine transform to modify objects.

    The first is to set the transform such as this:

    Java Code:
    AffineTransform at = new AffineTransform();
    		 at.setToIdentity();
    		 at.rotate(angle1,cx+15,cy+15);
    and then set the transform:

    Java Code:
    g2.setTransform(at);
    		g2.drawImage(pistol,cx+15,cy-18,null);
    		g2.setTransform(origXform);
    after which reseting it to the standard transform.
    This works fine for Graphics2D. but on offscreen images the method .setTransform does not exist thus nullifying this method of use.

    The second way is to set a transform such as the above... and then create an object with it such as:

    Java Code:
    Shape shape1 = at.createTransformedShape(Ellipse1)
    Once again this method would work, but has two flaws. The first... I'm trying to rotate an image. I can't create convert Image to a Shape so for one the above code can't help me rotate my image. The second problem is offscreen images can't draw "Shape" types. They can draw Rectangle's, Ellipse's, ect... but the type "Shape" is undefined.

    So as you can see... from what I know about affineTransform's and offscreen images. I need to find another way.... My other way was to remove the offscreen image altogether, and transform in a Graphics object which works perfectly. My new problem is that without the offscreen image I have the uncontrollable flickering and flashing to deal with now.

  4. #4
    leB
    leB is offline Member
    Join Date
    Apr 2009
    Posts
    1
    Rep Power
    0

    Default

    // double buffering
    put this in bigining part

    Image dbImage;
    Graphics dbg;

    and then put his at the end
    public void update (Graphics g)
    {
    if (dbImage == null)
    {
    dbImage = createImage (this.getSize().width, this.getSize().height);
    dbg = dbImage.getGraphics ();
    }

    dbg.setColor (getBackground ());
    dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);

    dbg.setColor (getForeground());
    paint (dbg);

    g.drawImage (dbImage, 0, 0, this);
    }

  5. #5
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    Quote Originally Posted by leB View Post
    // double buffering
    put this in bigining part

    Image dbImage;
    Graphics dbg;

    and then put his at the end
    public void update (Graphics g)
    {
    if (dbImage == null)
    {
    dbImage = createImage (this.getSize().width, this.getSize().height);
    dbg = dbImage.getGraphics ();
    }

    dbg.setColor (getBackground ());
    dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);

    dbg.setColor (getForeground());
    paint (dbg);

    g.drawImage (dbImage, 0, 0, this);
    }
    I usually draw to an offscreen image to solve this problem. But AffineTransform doesn't work with offscreen images so I have to find an alternative way to get rid of stupid flashing.
    I must say I'm surprised it doesn't work...
    I die a little on the inside...
    Every time I get shot.

  6. #6
    quickfingers is offline Member
    Join Date
    Dec 2007
    Posts
    21
    Rep Power
    0

    Default

    Well lets bufferG the paint function

    (1)Add these to your declarations
    Image buffer;
    Graphics bufferG;

    (2)Next Add this to your init
    buffer=createImage(this.getWidth(),this.getHeight( ));
    bufferG=buffer.getGraphics();

    (3)Now in your paint rename the g.whatever to bufferG.whatever

    (4) at the end of paint add this line
    g.drawImage(buffer,0,0,this);

    (5)Add this to the end of your code before the last bracket
    public void update(Graphics g)
    {
    paint(g);
    }



    This code will take away all of that annoying flashing

Similar Threads

  1. How to remove border in JComboBox
    By tiro in forum AWT / Swing
    Replies: 2
    Last Post: 03-08-2009, 06:45 PM
  2. how do i remove this line?
    By eyal1983 in forum NetBeans
    Replies: 6
    Last Post: 01-01-2009, 03:55 AM
  3. Remove headline
    By amarelv in forum New To Java
    Replies: 4
    Last Post: 11-07-2008, 05:36 AM
  4. how to remove this error
    By ravinder64 in forum Java Servlet
    Replies: 1
    Last Post: 11-01-2008, 08:04 AM
  5. how to remove an old version of JDK
    By tommy in forum New To Java
    Replies: 2
    Last Post: 07-30-2007, 09:59 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
  •