Applet flickering

I will award more Duke Dollars to the one/ones that give me an answer that will help solve my problem. Which is:
I have an applet that displays some images. On IExplorer there is a visible flicker of one of the images (the largest one but i don't know if size has anything to do with it). The rest of the images do not flicker at all. On Netscape there is no such problem.
The image is aquired from a gif file by clipping it, so doubble buffering is not the answer (at least as far as i know). I have tried drawing it with the drawImage() of java.awt.Graphics and i also tried to draw the image in a panel thus not having the drawImage() method called each time there is a repaint(). It did not help. The flickering seemed to be less frequent but it still is there and is very anoying. Again, that is only on IExplorer.
Thank you,
Calin

As far as I know double buffering is used when drawing lots of stuff. When this happens the drawing can actually take some time so you would see a flicker on the screen as stuff is getting drawn. To make it all get on the screen at once, you use double buffering which means that you draw to an off-screen location, and then copy that to an on-screen location.
As for my problem:
1) i don't destroy the graphics context (or at least that's what i think); anyway, how can i destroy it ?? please give me an example and tell me how to avoid that
2) Please give me an example of how to give it some sleep time, if it's something else then just calling sleep() on the current thread
3) Most important, and no one addressed this: the problem i encounter is ONLY IN MS INTERNET EXPLORER
Thank you,
Calin

Similar Messages

  • Applet flickers

    Hai,
    I developed an applet which works perfectly in appletviewer
    but flickers in IE browser. These problem arises when I dynamically
    set the components in various locations.
    regards,
    s.radhakrishnan

    call the setInvalidate() method before changing the postion or resizing of the components.

  • Flickering in applets

    Hi
    I have this problem. My applet flickers everytime I scroll down the page. I have used update(Graphics). What do I do about this?
    Thanks

    the problem is that u make a huge image processing in the paint or update method like
    Graphics offScreenGraphics = offScreenImage.getGraphics();
    offScreenGraphics.setColor(getBackground());
    offScreenGraphics.fillRect(0,0,getSize().width,getSize().height);
    offScreenGraphics.setColor(g.getColor());
    so put them in Init() method in any place of your code
    then make the image processing you want, for example draw you game interface to the offScreenGraphics variable
    after that use the method paint(Graphics g)
    just to draw your "offScreenImage" to applet graphics
    this for sure will distribute the time and effort of your graphics processing over many parts of your code
    and for flickering when scrolling, scroll makes your app call the paint(Graphics g) method, and it will flicker for ever except if made
    an advanced high level code that can get the region of your graphics surface to update, example just update Rectangle (10,10,50,50) not all the Rectangle(0,0,500,500)
    to do this see some topics in java 2D, 3D or game programming, or java advanced imaging APIs those are more concerned of the fast processing and high quality image presenting on screen.
    hope this help,
    mnmmm

  • Can anybody help in Flickering prob in Applet

    Hi there,
    I am having problem that my applet flickers a very often . actually i have a function which call repaint on mouse over. but i wanna reduce that. If anybody can help me in this matter would be greatful.
    thank u

    If you want to call repaint() method again and again, then you should redifine update method so that it should not paint the whole background. Better solution for this type of problem is to use getGraphics() method to get a Graphics object and paint any thing as you like with this Graphics object without needing paint or repaint method.

  • Flickering problem with applet

    After doing a programming lab assignment, with no work, I decided to modify one of the completed programs, which was a pong-like game. Anyways, after changing it to a white on black setup, I now get major flickering. One of the previous programs was to animate something without it flickering using a buffered image. So I converted it over, but it had no effect.
    import java.applet.Applet;
    import java.awt.*;
    public class PongGame2 extends Applet
         int paddleX, paddleY, ballX, ballY, incX, incY, score, appletWidth, appletHeight;
         Image virtualMem;
         Graphics gBuffer;
         public void init()
              ballX = 10;
              ballY = 10;
              incX  = 3;
              incY  = 3;
              score = 0;
              appletWidth = getWidth();
              appletHeight = getHeight();
              virtualMem = createImage(appletWidth, appletHeight);
              gBuffer = virtualMem.getGraphics();
         public void paint(Graphics g)
              draw(g, paddleX, paddleY, ballX, ballY);
              ballX += incX;
              ballY += incY;
              if (incY > 0 && ballY > 580-incY)
                  incY = -incY;
              else if (incY < 0 && ballY < 2*incY)
                  incY = -incY;
              if (ballY < paddleY && ballY >= paddleY-20 && ballX > paddleX && ballX < paddleX+100)
                   incY = -incY;
              if (ballY > paddleY + 10 && ballY < paddleY + 20 && ballX > paddleX && ballX < paddleX+100)
                  incY = -incY;
              if (incX > 0 && ballX > 780-incX)
                  incX = -incX;
              else if (incX < 0 && ballX < 2*incX)
                  incX = -incX;
              if (ballY < 1)
                   score++;
               try
                    Thread.sleep(7);
               catch(InterruptedException ex)
              repaint();     
         public boolean mouseMove(Event e, int x, int y)
              paddleX = x-50;
              paddleY = y-10;          
              repaint();
              return true;
         public boolean mouseIdle(Event e, int x, int y)
              repaint();
              return true;
         public void createBackground(Graphics g)
              gBuffer.setColor(Color.black);
              gBuffer.fillRect(0,0,800,600);
              gBuffer.setColor(Color.white);   
              gBuffer.drawString("Score: " + score/5,200,20);
         public void draw(Graphics g, int paddleX, int paddleY, int ballX, int ballY)
              createBackground(g);
              gBuffer.setColor(Color.white);
              gBuffer.fillRect(paddleX,paddleY,100,20);
              gBuffer.fillOval(ballX,ballY,20,20);
              g.drawImage(virtualMem,0,0,this);
    }

    Petes1234, thanks!
    It works perfectly now, and without having warnings of using deprecated features. It took me a while though to find how to set this up, and proper methods.
    Here's the code right now:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    public class JavaPongGame1 extends JApplet implements MouseMotionListener
         int paddleX, paddleY, ballX, ballY, incX, incY, score;
         public void init()
              ballX = 10;
              ballY = 10;
              incX  = 3;
              incY  = 3;
              score = 0;
              addMouseMotionListener(this);
         public void paint(Graphics g)
              draw(g, paddleX, paddleY, ballX, ballY);
              ballX += incX;
              ballY += incY;
              if (incY > 0 && ballY > 580-incY)
                  incY = -incY;
              else if (incY < 0 && ballY < 2*incY)
                  incY = -incY;
              if (ballY < paddleY && ballY >= paddleY-20 && ballX > paddleX && ballX < paddleX+100)
                   incY = -incY;
              if (ballY > paddleY + 10 && ballY < paddleY + 20 && ballX > paddleX && ballX < paddleX+100)
                  incY = -incY;
              if (incX > 0 && ballX > 780-incX)
                  incX = -incX;
              else if (incX < 0 && ballX < 2*incX)
                  incX = -incX;
              if (ballY < 1)
                   score++;
              try
                    Thread.sleep(7);
               catch(InterruptedException ex)
              repaint();
         public void mouseMoved(MouseEvent e)
              paddleX = e.getX()-50;
              paddleY = e.getY()-10;          
              repaint();
              e.consume();
         public void mouseDragged(MouseEvent e)
         public void createBackground(Graphics g)
              g.setColor(Color.black);
              g.fillRect(0,0,800,600);
              g.setColor(Color.white);   
              g.drawString("Score: " + score/5,200,20);
         public void draw(Graphics g, int paddleX, int paddleY, int ballX, int ballY)
              createBackground(g);
              g.setColor(Color.white);
              g.fillRect(paddleX,paddleY,100,20);
              g.fillOval(ballX,ballY,20,20);
    }

  • Flickering text print applet

    my news applet scrolls text across the screen, the text however is flickering. my draw code is below.
              screen2D.clearRect(0,0,getSize().width,getSize().height);
    screen2D.drawString(obj.news[obj.currentItem],obj.x,obj.y);
              repaint();
    your help would be much appreciated
    Arnold Oree

    Double Buffering would seem to be the answer to your problems. I'm no expert but the following worked for me where I previous was drawing directly to the screen. Do all your drawing in the offscreen buffer area and then transfer it to the screen with the last statement in your paint method.
    I've lifted some code for an applet I created a while back. Hopefully you can see what's going on.
    Override the update method
    as noted.
    // buffer stuff
    Graphics bufferGraphics;
    Image offScreen;
    Dimension dim;
    public void paint (Graphics g)
    bufferGraphics.clearRect(0,0,dim.width, dim.height);
    bufferGraphics.setFont(new Font ("serif", Font.BOLD,18));
    // set up board
    for (int row = 0; row <=7; ++ row)
    for (int column = 0; column <=7; ++ column)
    // white squares
    if ((row+column)%2 == 0)
    bufferGraphics.setColor (new Color(0,0,0));
    // black squares
    if ((row+column)%2 == 1)
    bufferGraphics.setColor (new Color (255,255,255));
    // attacked squares
    bufferGraphics.fillRect (40+(column*40), 75+(row*40), 40, 40);
    if (board [row][column] !=0)
    bufferGraphics.setColor (new Color(255,0,0));
    bufferGraphics.drawString("X", 52 +(column*40), 101 +(row*40));
    } // end row loop
    } // end column loop
    bufferGraphics.setColor (new Color (255,0,0));
    bufferGraphics.drawLine (38,73,360,73); // top
    bufferGraphics.drawLine (38,74,360,74); // top
    bufferGraphics.drawLine (38,75,360,75); // top
    bufferGraphics.drawLine (40,75,40,395); // left
    bufferGraphics.drawLine (39,75,39,395); // left
    bufferGraphics.drawLine (38,75,38,395); // left
    bufferGraphics.drawLine (38,395,360,395); // bottom
    bufferGraphics.drawLine (38,396,360,396); // bottom
    bufferGraphics.drawLine (38,397,360,397); // bottom
    bufferGraphics.drawLine (360,75,360,395); // right
    bufferGraphics.drawLine (361,73,361,397); // right
    bufferGraphics.drawLine (362,73,362,397); // right
    bufferGraphics.setColor (new Color (255,0,0));
    g.drawImage (offScreen, 0, 0, this);
    } // end paint
    public void update (Graphics g)
    paint (g);
    } // end update

  • Paint(), update(), reducing flickering of applets.., not repaint()ing

    I made an applet which moves a square from one end to other end, but i used the public void paint(Graphics c)
    To reduce flickering one has to use the update() in place of paint() and call paint() at the end...well, when i do this the update() method doesnt repaint...
    Heres the code..
    import java.awt.*;
    import java.applet.*;
              public class appAniBox extends Applet implements Runnable{
                   int x = 0;
                                       public void init(){
                                            Thread t = new Thread(this);
                                                 t.start();
                                  public void run(){
                                       for(;;){
                                                 repaint();
                                                 try{
                                                 Thread.sleep(6);
                                            catch(Exception e){ }
                                       [u]public void update(Graphics g){
                                            g.setColor(Color.green);
                                                 g.fillRect(x,50,50,50);
                                                 x ++;
                                                 super.paint(g);
                                                 }[/u]                                             
              //<applet code = appAniBox height = 150 width = 700></applet>

    handy-dandy double buffering code...
    // Usage
    DoubleBuffer db = new DoubleBuffer(theComponent);
    public void paint(Graphics g) {
       Graphics dbg = this.db.getBuffer();
       // ... add painting code performed on dbg ...
       this.db.paint(g);
    // Class
    import java.awt.*;
    * <code>DoubleBuffer</code> is a utility class for creating and managing
    * a double buffer for drawing on a component.  For a given component,
    * create a DoubleBuffer object, call getBuffer to get the graphics object
    * to draw on, then call paint with the component's graphics object to
    * draw the buffer. 
    * @author sampbe
    public class DoubleBuffer
        //~ Instance fields --------------------------------------------------------
         * The component.
        private Component comp = null;
         * The buffer width.
        private int bufferWidth = -1;
         * The buffer height.
        private int bufferHeight = -1;
         * The buffer image.
        private Image bufferImage = null;
         * The buffer graphics.
        private Graphics bufferGraphics = null;
        //~ Constructors -----------------------------------------------------------
         * Creates a new <code>DoubleBuffer</code> object for the specified
         * component.
         * @param comp the component
        public DoubleBuffer(Component comp)
            if(comp == null)
                throw new NullPointerException();
            this.comp = comp;
        //~ Methods ----------------------------------------------------------------
         * Paints the buffer on the graphics object.
         * @param g the graphics object to paint on
        public void paint(Graphics g)
            paint(g, 0, 0);
         * Paints the buffer on the graphics object.
         * @param g the graphics object to paint on
         * @param x the x-coordinate
         * @param y the y-coordinate
        public void paint(Graphics g, int x, int y)
            if(bufferImage != null)
                g.drawImage(bufferImage, 0, 0, comp);
         * Gets the width.
         * @return the width
        public int getWidth()
            return bufferWidth;
         * Gets the height.
         * @return the height
        public int getHeight()
            return bufferHeight;
         * Gets the buffer's graphics object.
         * @return the buffer's graphics
        public Graphics getBuffer()
            // checks the buffersize with the current panelsize
            // or initialises the image with the first paint
            if ((bufferWidth != comp.getSize().width)
                    || (bufferHeight != comp.getSize().height)
                    || (bufferImage == null)
                    || (bufferGraphics == null))
                // always keep track of the image size
                bufferWidth = comp.getSize().width;
                bufferHeight = comp.getSize().height;
                // clean up the previous image
                if (bufferGraphics != null)
                    bufferGraphics.dispose();
                    bufferGraphics = null;
                if (bufferImage != null)
                    bufferImage.flush();
                    bufferImage = null;
                // create the new image with the size of the panel
                bufferImage = comp.createImage(bufferWidth, bufferHeight);
                bufferGraphics = bufferImage.getGraphics();
            return bufferGraphics;
    }

  • Flickering in swing Applet

    I'm using swing applet.My applet is getting flickering only when i embed it in html
    I heard that,swing 'll handle flickering on its own.But i see it in appeltviewer it okie..My
    panel's size is also very big its,17040 pixel...what should i have to do avoid flickering

    My crystalball tells me that you are painting the entire screen with each call to paint and your are also making a call to super.paintComponent(g) when you do so... hence much flickering exists with your application even though it's double buffered.
    To avoid this problem do the following:
    take 3 whole slottered chickens, put them in a bag and ... oh that was for array problems... let me see for flickering....
    Well, you need to do offscreen rendering to an image and call repaint when done, but in your paintComponent(Graphics g) do this:
    public void paintComponent(Graphics g){
      drawImage(myOffscreenImage4Rendering, 0, 0, this); //notice 1 liner--no other code needed or wanted here.
    }I do this with 1600x1200 on an AMD 2GHz with 500+ objects being drawn and no flicker. I've had up to 10,000 objects with no flicker, but yes, the animation speed was severely impacted due to the number of objects being rendered each cycle.

  • I need some help with my java game using applets, CAN SOMEBODY PLEASE HELP

    Hi,
    I am in the process of creating a RPG program using Java. I am not very experienced with java, however the problem i am currently facing is something i can't seem to figure out. I would like to draw a simple grid where a character (indicated by a filled circle) moves around this grid collecting items (indicated by a red rectangle). When the character moves on top of the grid with the item, i would like it to disappear. Right now i am not worrying about the fact that the item will reappear after the character moves away again, because sometimes, when the character moves over the item, nothing happens/another item disappears. i have been at this for 4 days and still cannot figure out what is goign on. can somebody please help me? it would be most appreciated.
    Thanks
    PS if i needed to send you my code, how do i do it?

    Thank you for replying.
    The thing is, I am taking java as a course, and it is necessary for me to start off this way (this is for my summative evaluation). i agree with you on the fact, however, that i should go in small steps. i have been doing that until this point, and my frustration caused me to jump around randomly for an answer. I also think that it may just be a bug, but i have no clue as to how to fix it, as i need to show my teacher at least a part of what i was doing by sometime next week. Here is my code for anybody willing to go through it:
    // The "Keys3" class.
    import java.applet.*;
    import java.awt.*;
    import java.awt.Event;
    import java.awt.Font;
    import java.awt.Color;
    import java.applet.AudioClip;
    public class Keys3 extends java.applet.Applet
        char currkey;
        int currx, curry, yint, xint;
        int itmval [] = new int [5],
            locval [] = new int [5],
            tempx [] = new int [5], tempy [] = new int [5],
            tot = 0, score = 0;
        boolean check = true;
        AudioClip bgSound, bgSound2;
        AudioClip hit;
        private Image offscreenImage;
        private Graphics offscreen;     //initializing variables for double buffering
        public void init ()  //DONE
            bgSound = getAudioClip (getCodeBase (), "sound2_works.au");
            hit = getAudioClip (getCodeBase (), "ah_works.au");
            if (bgSound != null)
                bgSound.loop ();
            currx = 162;
            curry = 68;
            setBackground (Color.white);
            for (int count = 0 ; count < 5 ; count++)
                itmval [count] = (int) (Math.random () * 5) + 1;
                locval [count] = (int) (Math.random () * 25) + 1;
            requestFocus ();
        public void paint (Graphics g)  //DONE
            resize (350, 270);
            drawgrid (g);
            if (check = true)
                pickitems (g);
                drawitems (g);
            g.setColor (Color.darkGray);
            g.fillOval (currx, curry, 25, 25);
            if (currkey != 0)
                g.setColor (Color.darkGray);
                g.fillOval (currx, curry, 25, 25);
            if (collcheck () != true)
                collision (g);
            else
                drawitems (g);
        } // paint method
        public void update (Graphics g)  //uses the double buffering method to overwrite the original
                                         //screen with another copy to reduce flickering
            if (offscreenImage == null)
                offscreenImage = createImage (this.getSize ().width, this.getSize ().height);
                offscreen = offscreenImage.getGraphics ();
            } //what to do if there is no offscreenImage copy of the original screen
            //draws the backgroudn colour of the offscreen
            offscreen.setColor (getBackground ());
            offscreen.fillRect (0, 0, this.getSize ().width, this.getSize ().height);
            //draws the foreground colour of the offscreen
            offscreen.setColor (getForeground ());
            paint (offscreen);
            //draws the offscreen image onto the main screen
            g.drawImage (offscreenImage, 0, 0, this);
        public boolean keyDown (Event evt, int key)  //DONE
            switch (key)
                case Event.DOWN:
                    curry += 46;
                    if (curry >= 252)
                        curry -= 46;
                        if (hit != null)
                            hit.play ();
                    break;
                case Event.UP:
                    curry -= 46;
                    if (curry <= 0)
                        curry += 46;
                        if (hit != null)
                            hit.play ();
                    break;
                case Event.LEFT:
                    currx -= 66;
                    if (currx <= 0)
                        currx += 66;
                        if (hit != null)
                            hit.play ();
                    break;
                case Event.RIGHT:
                    currx += 66;
                    if (currx >= 360)
                        currx -= 66;
                        if (hit != null)
                            hit.play ();
                    break;
                default:
                    currkey = (char) key;
            repaint ();
            return true;
        public boolean collcheck ()  //DONE
            if (((currx == tempx [0]) && (curry == tempy [0])) || ((currx == tempx [1]) && (curry == tempy [1])) || ((currx == tempx [2]) && (curry == tempy [2])) || ((currx == tempx [3]) && (curry == tempy [3])) || ((currx == tempx [4]) && (curry == tempy [4])))
                return false;
            else
                return true;
        public void collision (Graphics g)
            drawgrid (g);
            for (int count = 0 ; count < 5 ; count++)
                if ((currx == tempx [count]) && (curry == tempy [count]))
                    g.setColor (Color.darkGray);
                    g.fillOval (currx, curry, 25, 25);
                else if ((currx != tempx [count]) && (curry != tempy [count]))
                    g.setColor (Color.red);
                    g.fillRect (tempx [count], tempy [count], 25, 25);
        public void drawitems (Graphics g)
            for (int count = 0 ; count < 5 ; count++)
                g.setColor (Color.red);
                g.fillRect (tempx [count], tempy [count], 25, 25);
        public void pickitems (Graphics g)
            check = false;
            for (int count = 0 ; count < 5 ; count++)
                if (locval [count] <= 5)
                    tempy [count] = 22;
                else if (locval [count] <= 10)
                    tempy [count] = 68;
                else if (locval [count] <= 15)
                    tempy [count] = 114;
                else if (locval [count] <= 20)
                    tempy [count] = 160;
                else if (locval [count] <= 25)
                    tempy [count] = 206; //this determines the y-position of the item to be placed
                if (locval [count] % 5 == 0)
                    tempx [count] = 294;
                else if ((locval [count] == 1) || (locval [count] == 6) || (locval [count] == 11) || (locval [count] == 16) || (locval [count] == 21))
                    tempx [count] = 30;
                else if ((locval [count] == 2) || (locval [count] == 7) || (locval [count] == 12) || (locval [count] == 17) || (locval [count] == 22))
                    tempx [count] = 96;
                else if ((locval [count] == 3) || (locval [count] == 8) || (locval [count] == 13) || (locval [count] == 18) || (locval [count] == 23))
                    tempx [count] = 162;
                else if ((locval [count] == 4) || (locval [count] == 9) || (locval [count] == 14) || (locval [count] == 19) || (locval [count] == 24))
                    tempx [count] = 228;
        public void drawgrid (Graphics g)  //DONE
            g.drawRect (10, 10, 330, 230); //draws the outer rectangular border
            int wi = 10; //width of one square on the board
            int hi = 10; //height of one square on the board
            for (int height = 1 ; height <= 5 ; height++)
                for (int row = 1 ; row <= 5 ; row++)
                    if (((height % 2 == 1) && (row % 2 == 1)) || ((height % 2 == 0) && (row % 2 == 0)))
                        g.setColor (Color.gray);
                        g.fillRect (wi, hi, 66, 46);
                    else /*if (((height % 2 == 0) && (row % 2 == 1)) || ((height % 2 == 0) && (row % 2 == 0)))*/
                        g.setColor (Color.lightGray);
                        g.drawRect (wi, hi, 66, 46);
                        g.setColor (Color.lightGray);
                        g.drawRect (wi, hi, 66, 46); //drawn twice to make a shadow effect
                    wi += 66;
                wi = 10;
                hi += 46;
            } //this draws the basic outline of the game screen
    } // Keys3 class

  • How can i stop the screen from flickering in this program?

    Hi, i just wanted to know if anybody knows why my screen keeps flickering when i move.
    * @(#)CarWKeys.java
    * CarWKeys Applet application
    * @author
    * @version 1.00 2008/11/29
    import java.awt.*;
    import java.applet.*;
    import java.awt.image.*;
    public class CarWKeys extends Applet implements Runnable
          private Image dbImage;
         private Graphics dbg;
          Image img,CarWKeys1,cup;
          // This Field is to Trace out the User's CarWKeys position
          static int position=235;
          static int points = 0;
          // You can change this delay to any value which effects in the speed of the game
          static int delay = 100;
          road rd;
          Thread thr;
          static int pts=50;
          boolean msg=true;
          // If this field is true then the 'road' thread will be stopped
          static boolean kill=false;
          public void init()
         int x[] = { 15, 15, 0, 60, 45, 45 };
         int y[] = { 45, 50, 58, 58, 50, 45 };
         setBackground(Color.black);
                // Drawing the CarWKeys Image
                img = createImage(60,60);
                Graphics g = img.getGraphics();
                g.setColor(Color.black);
                g.fillRect(0,0,60,60);
                g.setColor(Color.green);
                g.fillRect(12,20,36,7);
                g.fillRect(8,15,4,17);
                g.fillRect(48,15,4,17);
                g.fillRect(5,40,50,7);
                g.fillRect(0,35,5,17);
                g.fillRect(55,35,5,17);
                g.setColor(Color.red);
                g.fillRect(20,0,20,15);
                g.fillRect(15,15,30,40);
                g.setColor(Color.blue);
                g.fillRect(20,20,7,10);
                g.fillRect(33,20,7,10);
                g.setColor(Color.red);
                g.fillRect(22,22,3,6);
                g.fillRect(35,22,3,6);
                g.setFont(new Font("TimesRoman",Font.PLAIN,7));
                g.setColor(Color.white);
                g.fillPolygon(x,y,6);
                g.setColor(Color.black);
                g.drawString("YAMAHA",15,52);
                // Drawing the CarWKeys Image
                CarWKeys1 = createImage(60,60);
                Graphics g1 = CarWKeys1.getGraphics();
                g1.setColor(Color.black);
                g1.fillRect(0,0,60,60);
                g1.setColor(Color.green);
                g1.fillRect(12,20,36,7);
                g1.fillRect(8,15,4,17);
                g1.fillRect(48,15,4,17);
                g1.fillRect(5,40,50,7);
                g1.fillRect(0,35,5,17);
                g1.fillRect(55,35,5,17);
                g1.setColor(Color.blue);
                g1.fillRect(20,0,20,15);
                g1.fillRect(15,15,30,40);
                g1.setColor(Color.red);
                g1.fillRect(20,20,7,10);
                g1.fillRect(33,20,7,10);
                g1.setColor(Color.blue);
                g1.fillRect(22,22,3,6);
                g1.fillRect(35,22,3,6);
                g1.setFont(new Font("TimesRoman",Font.PLAIN,7));
                g1.setColor(Color.white);
                g1.fillPolygon(x,y,6);
                g1.setColor(Color.black);
                g1.drawString(" B.M.W ",15,52);
                thr = new Thread(this); thr.start(); rd = new road(getGraphics(),CarWKeys1,this); rd.start();
                // Cup Image
                int a[] = {20,5,35};
                int b[] = {150,160,160};
                cup = createImage(50,165);
                Graphics handle = cup.getGraphics();
                handle.setColor(Color.black);
                handle.fillRect(0,0,50,165);
                handle.setColor(Color.red);
                handle.fillArc(0,40,40,30,0,180);
                handle.setColor(Color.yellow);
                handle.fillArc(0,15,40,80,180,180);
                handle.setColor(Color.red);
                handle.drawLine(20,95,20,150);
                handle.fillPolygon(a,b,3);
          public void update (Graphics g)
              // DoubleBuffers
              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);
          public void run()
                // If you cross the 50 mark you will get a Cup of Java
                while(points <= 15)
             if(points == 50 || kill == true)
             rd.stop();
             repaint();
             thr.stop();
             if((points%4)==0)
               rd.j = 0;
               pts = points;
                points++;
                            delay--;
                            if(delay <= 0)
                                  delay = 0;
                            rd.flag=1;
                            repaint();
                      try
                            Thread.sleep(delay);
                      }catch(InterruptedException exp){}
          public void destroy()
                thr.stop();
                rd.stop();
          //If User presses mouse the the CarWKeys is shifted to opposite side of the road
               public boolean keyDown(Event evt, int key) {
        if (key==Event.LEFT){
        // left arrow key pressed
        if(position == 355)
           position = 235;
        else if(key== Event.RIGHT){
        // right arrow key pressed
        if(position == 235)
           position = 355;
       repaint();
      return true;
          public void paint(Graphics gr)
                if(!kill)
                      if(msg)
                            // This is the opening message
                    gr.setColor(Color.black);
                    gr.fillRect(0,0,640,400);
                            gr.setColor(Color.yellow);
                            gr.setFont(new Font("TimesRoman",Font.BOLD,16));
                            gr.drawString("TO START THE GAME CLICK THE SCREEN",140,100);
                            gr.drawString("USE THE ARROW KEYS TO MOVE THE CAR",140,200);
                            gr.drawString("WAIT A MINUTE......",230,240);
                            msg = false;
                            try{
                                  Thread.sleep(3000);
                            }catch(Exception exp){}
                            gr.setColor(Color.black);
                            gr.fillRect(0,0,640,400);
                      gr.setColor(Color.white);
                      gr.fillRect(200,0,10,400);
                      gr.fillRect(440,0,10,400);
                      gr.drawImage(img,position,300,this);
                      gr.setColor(Color.yellow);
                      gr.fillRect(550,5,637,25);
                      gr.setColor(Color.blue);
                      gr.setFont(new Font("TimesRoman",Font.BOLD,20));
                      gr.drawString("Score :"+pts,557,22);
                      if(points >= 16)
                            for(int xyz=0;xyz<3;xyz++)
                                  gr.setColor(Color.yellow);
                                  gr.drawString("Have a Cuppa Java",240,100);
                                  gr.drawImage(cup,300,100,this);
                                  gr.setColor(Color.yellow);
                                  gr.fillRect(550,5,637,25);
                                  gr.setColor(Color.blue);
                                  gr.setFont(new Font("TimesRoman",Font.BOLD,20));
                                  gr.drawString("Score :50",557,22);
                                  try
                                        Thread.sleep(500);
                                  }catch(InterruptedException exp){}
                else
                      gr.setColor(Color.yellow);
                      gr.drawString("YOU HAVE LOST THE GAME",250,200);
    class road extends Thread
          int i;
          public static int j = 0;
          Graphics g;
          Image CarWKeys2;
          ImageObserver io;
          public static int flag = 0;
          boolean msg=true;
          road(Graphics g,Image CarWKeys2,ImageObserver io)
                this.g = g;
                this.io = io;
                this.CarWKeys2 = CarWKeys2;
          public void run()
                drawRoad(g);
          // The actual logic i.e Moving of CarWKeyss is here
          public void drawRoad(Graphics gr)
                if(msg)
                      gr.setColor(Color.black);
                      gr.fillRect(0,0,640,400);
                      gr.setColor(Color.yellow);
                      gr.setFont(new Font("TimesRoman",Font.BOLD,16));
                            gr.drawString("TO START THE GAME CLICK THE SCREEN",140,100);
                            gr.drawString("USE THE ARROW KEYS TO MOVE THE CAR",140,200);
                            gr.drawString("WAIT A MINUTE......",230,240);
                      msg = false;
                      try
                            Thread.sleep(3000);
                      }catch(Exception exp){}
                      gr.setColor(Color.black);
                      gr.fillRect(0,0,640,400);
                for(;j<=1000;j+=10)
                      for(i=-1000;i<=479;i+=60)
                            gr.setColor(Color.black);
                            gr.fillRect(320,i+j,10,i+j+50);
                            gr.setColor(Color.white);
                            gr.fillRect(320,i+j+10,10,i+j+60);
                      gr.clearRect(235,j-10,60,60);
                      gr.drawImage(CarWKeys2,235,0+j,io);
                      gr.clearRect(355,-150+(j-10),60,60);
                      gr.drawImage(CarWKeys2,355,-150+j,io);
                      gr.clearRect(235,-300+(j-10),60,60);
                      gr.drawImage(CarWKeys2,235,-300+j,io);
                      gr.clearRect(355,-450+(j-10),60,60);
                      gr.drawImage(CarWKeys2,355,-450+j,io);
                      if( (CarWKeys.position == 235 && (j >= 250 && j <= 360)) || (CarWKeys.position == 355 && (j >= 400 && j <= 510)) || (CarWKeys.position == 235 && (j >= 550 && j <= 660)) || (CarWKeys.position == 355 && (j >= 700 && j <= 810)) )
                            try
                                  Thread.sleep(2000);
                                  CarWKeys.kill = true;
                            }catch(InterruptedException exp){}
                      if (j >= 360 ) { if( (( j - 360 ) % 150 ) == 0 )
                            if(flag == 1)
                                  CarWKeys.points--;
                                  flag = 0;
                            CarWKeys.points++;
                            gr.setColor(Color.yellow);
                            gr.fillRect(550,5,637,25);
                            gr.setColor(Color.blue);
                            gr.setFont(new Font("TimesRoman",Font.BOLD,20));
                            gr.drawString("Score :"+CarWKeys.points,557,22);
                try
                      Thread.sleep(CarWKeys.delay);
                }catch(InterruptedException exp){}
    }

    Look at the link I posted, you aren't double buffering correctly.
    I saw the other post you mistakenly made before you edited it. Not really a big deal, I was just wondering why you did that.

  • DoubleBuffering problem with applet

    Hi,
    We are developing an applet with multiple screens. CardLayout is being used to flip between different panels in the systems. The applet contains huge JTable and chart components and huge amount of data, which makes the refreshing of the applet very slow. We tried the DoubleBuffering concept to reduce the flickering in the JApplet class.
    Now the questions are:
    1) Do we need to do double buffering for all the panels that are used in the system ?
    2) Is there any other better way that Sun suggests to avoid flickering problems ?
    Any help will be much appreciated. Also with the email content and problem definition thread is going on, any feedback about this email is also welcomed.
    Thanks
    Anoop

    One solution is to put all the packages in a jar file.

  • Double buffering still gives flickering graphics.

    I copied code from a tutorail which is supposed to illustrate double buffering.
    After I run it, it still flickers though.
    I use applet viewer, which is part of netbeans to run my applet.
    Link to tutorial: http://www.javacooperation.gmxhome.de/TutorialStartEng.html
    My questions are:
    Is the strategy used for double buffering correct?
    Why does it flicker?
    Why does the program change the priority a couple of times?
    Can you make fast games in JApplets or is there a better way to make games? (I think C++ is too hard)
    Here is the code:
    package ballspel;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Image;
    import javax.swing.JApplet;
    //import java.applet.*;
    * @author Somelauw
    public class BallApplet extends /*Applet*/ JApplet implements Runnable {
    private Image dbImage;
    private Graphics dbg;
    private int radius = 20;
    private int xPos = 10;
    private int yPos = 100;
    * Initialization method that will be called after the applet is loaded
    * into the browser.
    @Override
    public void init() {
    //System.out.println(this.isDoubleBuffered()); //returns false
    // Isn't there a builtin way to force double buffering?
    // TODO start asynchronous download of heavy resources
    @Override
    public void start() {
    Thread th = new Thread(this);
    th.start();
    public void run() {
    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
    while (true) {
    xPos++;
    repaint();
    try {
    Thread.sleep(20);
    } catch (InterruptedException ex) {
    ex.printStackTrace();
    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
    @Override
    public void paint(Graphics g) {
    super.paint(g);
    //g.clear();//, yPos, WIDTH, WIDTH)
    g.setColor(Color.red);
    g.fillOval(xPos - radius, yPos - radius, 2 * radius, 2 * radius);
    @Override
    public void update(Graphics g) {
    super.update(g);
    // initialize buffer
    if (dbImage == null) {
    dbImage = createImage(this.getSize().width, this.getSize().height);
    dbg = dbImage.getGraphics();
    // clear screen in background
    dbg.setColor(getBackground());
    dbg.fillRect(0, 0, this.getSize().width, this.getSize().height);
    // draw elements in background
    dbg.setColor(getForeground());
    paint(dbg);
    // draw image on the screen
    g.drawImage(dbImage, 0, 0, this);
    // TODO overwrite start(), stop() and destroy() methods
    }

    Somelauw wrote:
    I copied code from a tutorail which is supposed to illustrate double buffering.
    After I run it, it still flickers though.
    I use applet viewer, which is part of netbeans.. AppletViewer is part of the JDK, not NetBeans.
    ..to run my applet.
    Link to tutorial: http://www.javacooperation.gmxhome.de/TutorialStartEng.html
    Did you specifically mean the code mentioned on this page?
    [http://www.javacooperation.gmxhome.de/BildschirmflackernEng.html]
    Don't expect people to go hunting around the site, looking for the code you happen to be referring to.
    As an aside, please use the code tags when posting code, code snippets, XML/HTML or input/output. The code tags help retain the formatting and indentation of the sample. To use the code tags, select the sample and click the CODE button.
    Here is the code you posted, as it appears in code tags.
    package ballspel;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Image;
    import javax.swing.JApplet;
    //import java.applet.*;
    * @author Somelauw
    public class BallApplet extends /*Applet*/ JApplet implements Runnable {
        private Image dbImage;
        private Graphics dbg;
        private int radius = 20;
        private int xPos = 10;
        private int yPos = 100;
         * Initialization method that will be called after the applet is loaded
         * into the browser.
        @Override
        public void init() {
            //System.out.println(this.isDoubleBuffered()); //returns false
            // Isn't there a builtin way to force double buffering?
            // TODO start asynchronous download of heavy resources
        @Override
        public void start() {
            Thread th = new Thread(this);
            th.start();
        public void run() {
            Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
            while (true) {
                xPos++;
                repaint();
                try {
                    Thread.sleep(20);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
        @Override
        public void paint(Graphics g) {
            super.paint(g);
            //g.clear();//, yPos, WIDTH, WIDTH)
            g.setColor(Color.red);
            g.fillOval(xPos - radius, yPos - radius, 2 * radius, 2 * radius);
        @Override
        public void update(Graphics g) {
            super.update(g);
            // initialize buffer
            if (dbImage == null) {
                dbImage = createImage(this.getSize().width, this.getSize().height);
                dbg = dbImage.getGraphics();
            // clear screen in background
            dbg.setColor(getBackground());
            dbg.fillRect(0, 0, this.getSize().width, this.getSize().height);
            // draw elements in background
            dbg.setColor(getForeground());
            paint(dbg);
            // draw image on the screen
            g.drawImage(dbImage, 0, 0, this);
        // TODO overwrite start(), stop() and destroy() methods
    }Edit 1:
    - For animation code, it would be typical to use a javax.swing.Timer for triggering updates, rather than implementing Runnable (etc.)
    - Attempting to set the thread priority will throw a SecurityException, though oddly it occurs when attempting to set the Thread priority to maximum, whereas the earlier call to set the Thread priority to minimum passed without comment (exception).
    - The paint() method of that applet is not double buffered.
    - It is generally advisable to override paintComponent(Graphics) in a JPanel that is added to the top-level applet (or JFrame, or JWindow, or JDialog..) rather than the paint(Graphics) method of the top-level container itself.
    Edited by: AndrewThompson64 on Jan 22, 2010 12:47 PM

  • JtextField Flickering

    Hi All
    I am facing a flickering problem in applet which is having a Swing component.I am using SwingWorker class from sun to do some background processing in event thread i tried SwingUtilities.invokeLater did help me but not that much GUI used to get freeze to prevent that i have used SwingWorker seems to be everything is working fine but some flickering is happening in JtextField whenever it's value gets changed
    can somebidy tell me why is it happening and what is the solution for the same
    pls note This problem arise when applet is loaded with huge data
    pls help required urgently
    Rishi

    For more clearance
    I am sending u a chunk of code that is as follows :
    on JTextField focusLost()
    settting Object attributes which in turn firing a
    a state changed event
    public void stateChanged()
    //doing some processing which was taking a long time
    e so i added SwingWorker for the same now gui is not
    getting freeze out but JtextField flickers
    At least post the code that modifies the textfield. From
    what i know it should not flicker when done properly.

  • Flickering and cpufreq

    I have been playing around with arch for a week and I'm very impressed.  Indeed it is a great distribution.  It gives the user the power and flexibility to do anything while keeping things simple.
    Now on to my problem!  I get flickering on the screen whenever my cpu goes below its max.  It's not something terrible but it is annoying.  I thought it was casued by the refresh rates so I searched this forum and went to some websites to calculate the refresh rate for my laptop.  I edited xorg.conf and I put in the correct refresh rates so I stopped getting the flickering as long as the cpu was at its max.
    This cannot be right.  I also can't control the cpufreq.  I tell it to stay on performance with the max cpu but it keeps going back to powersave thereby causing the annoying flickering.
    Any help would be much appreciated.

    the following governors show up on the gnome-applet:
    ondemand
    userspace
    powersave
    performance
    these are the ones rc.conf:
    cpufreq_powersave cpufreq_userspace
    freq_table powernow_k8 cpufreq_ondemand)

  • Cant get flickering out of animation

    Hello all,
    please take a look at following Applet:
    www.coskuns-castle.de/rotation
    It is a rotating animation. It is realtime, means you can rotate the scene with your mouse. It is not bad at all, but I cant get the damn flickering out of the animation. Here is the full code (2 files) of the application version:
    file RotatingPanel.java
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class RotatingPanel extends JPanel
    private Graphics2D g2D;
    private int freq;
    private int startFreq;
    private double theta;
    private Point rotationCenter;
    private Timer timer;
    private boolean frozen;
    public RotatingPanel()
    this(false);
    public RotatingPanel(boolean activateMouse)
    this(5, Math.PI/25.0, activateMouse);
    public RotatingPanel(int freq, double theta, boolean activateMouse)
    super();
    this.freq = freq;
    startFreq = freq;
    this.theta = theta;
    UniversalListener uL = new UniversalListener();
    timer = new Timer(freq, uL);
    if (activateMouse)
    {   this.addMouseMotionListener(uL);
    this.addMouseListener(uL);
    public void startRotation()
    g2D = (Graphics2D) this.getGraphics();
    rotationCenter = new Point(this.getWidth()/2, this.getHeight()/2);
    timer.start();
    private void rotate(double theta)
    g2D.rotate(theta, rotationCenter.getX(), rotationCenter.getY());
    paintComponent((Graphics)g2D);
    private class UniversalListener extends MouseAdapter implements MouseMotionListener, ActionListener
    private int x, altx;
    boolean toleft = false;
    public void mouseDragged(MouseEvent event)
    if (x < event.getX())
    rotate(theta);
    else if (x > event.getX())
    rotate(-theta);
    altx = x;
    x = event.getX();
    public void mousePressed(MouseEvent event)
    x = event.getX();
    timer.stop();
    public void mouseMoved(MouseEvent event)
    public void mouseReleased(MouseEvent event)
    timer.setDelay(freq = startFreq);
    timer.start();
    if (altx>event.getX() && !toleft)
    {   theta=-theta;
    toleft = true;
    else if (altx>event.getX() && toleft)
    {   theta=-theta;
    toleft = false;
    public void actionPerformed(ActionEvent event)
    rotate(theta);
    timer.setDelay(freq++);
    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    file Rotation.java
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    import java.awt.*;
    import javax.swing.*;
    public class Rotation extends JFrame
    public static void main(String[] args)
    new Rotation();
    public Rotation()
    MyRotatingPanel rP = new MyRotatingPanel();
    rP.setDoubleBuffered(true);
    this.setContentPane(rP);
    this.setBounds(200,50,500,500);
    this.setTitle("2D Rotation by Fatih Coskun");
    this.show();
    rP.startRotation();
    private class MyRotatingPanel extends RotatingPanel
    private int x;
    private int y;
    private Font f;
    public MyRotatingPanel()
    super(true);
    f = new Font("Serif", Font.PLAIN, 18);
    this.setBackground(Color.black);
    public void paintComponent(Graphics g)
    x = ((int) this.getBounds().getWidth())/2;
    y = ((int) this.getBounds().getHeight())/2;
    g.setColor(Color.white);
    g.setFont(f);
    super.paintComponent(g);
    g.drawString("Fatih", x-40, y-10);
    g.drawString("Coskun", x-10, y+20);
    g.drawRect(x-50,y-50,100,100);
    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    I thank all, who took the time to look 10 seconds on my Applet. If you have any suggestions, please tell. I have already tried to draw first to an off screen image. But that will not solve the problem.
    thx, Fatih

    I done some more changes:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Rotation extends JFrame
    public Rotation()
         addWindowListener(new WindowAdapter()
        {     public void windowClosing(WindowEvent ev)
                   dispose();     
                   System.exit(0);
         MyRotatingPanel rP = new MyRotatingPanel();
         setContentPane(rP);
         setBounds(200,50,500,500);
         setTitle("2D Rotation by Fatih Coskun");
         show();
         rP.startRotation();
    private class MyRotatingPanel extends RotatingPanel
         private int    x;
         private int    y;
         private Font   f;
    public MyRotatingPanel()
         super(true);
         f = new Font("Serif", Font.PLAIN, 18);
         setBackground(Color.black);
    public void paintComponent(Graphics g)
         super.paintComponent(g);
         x = rotationCenter.x;
         y = rotationCenter.y;
         Graphics2D g2 = (Graphics2D)g;
         g2.rotate(ror,x-50+100/2,y-50+100/2);
         g2.setColor(Color.white);
         g2.setFont(f);
         g2.drawString("Fatih", x-40, y-10);
         g2.drawString("Coskun", x-10, y+20);
         g2.drawRect(x-50,y-50,100,100);
         g2.dispose();
    public static void main (String[] args) 
         new Rotation();
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class RotatingPanel extends JPanel
         private Graphics2D g2D;
         private int     freq;
         private int     startFreq;
                double  theta;
                   double  ror = 0;
                   Point   rotationCenter;
         private Timer   timer;
         private boolean frozen;
    public RotatingPanel()
         this(false);
    public RotatingPanel(boolean activateMouse)
         this(5, Math.PI/25.0, activateMouse);
    public RotatingPanel(int freq, double theta, boolean activateMouse)
         super();
         this.freq  = freq;
         startFreq  = freq;
         this.theta = theta;
         UniversalListener uL = new UniversalListener();
         timer = new Timer(freq, uL);
         if (activateMouse)
              this.addMouseMotionListener(uL);
              this.addMouseListener(uL);
    public void startRotation()
         rotationCenter = new Point(this.getWidth()/2, this.getHeight()/2);
         timer.start();
    private void rotate(double theta)
         ror = ror + theta;
         repaint(rotationCenter.x-80,rotationCenter.y-80,160,160);
    private class UniversalListener extends MouseAdapter implements MouseMotionListener, ActionListener
         private int x, altx;
         boolean toleft = false;
    public void mouseDragged(MouseEvent event)
         if (x < event.getX()) rotate(theta);
         if (x > event.getX()) rotate(-theta);
         altx = x;
         x = event.getX();
    public void mousePressed(MouseEvent event)
         x = event.getX();
         timer.stop();
    public void mouseMoved(MouseEvent event)
    public void mouseReleased(MouseEvent event)
         timer.setDelay(freq = startFreq);
         if (altx > event.getX() && !toleft)
              theta  =-theta;
              toleft = true;
         else if (altx > event.getX() && toleft)
                    theta  =-theta;
                   toleft = false;
         rotationCenter = new Point(event.getX(),event.getY());
         repaint();     
         timer.start();
    public void actionPerformed(ActionEvent event)
         rotate(theta);
         timer.setDelay(freq++);
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Rotation extends JFrame
    public Rotation()
         addWindowListener(new WindowAdapter()
    {     public void windowClosing(WindowEvent ev)
                   dispose();
                   System.exit(0);
         MyRotatingPanel rP = new MyRotatingPanel();
         setContentPane(rP);
         setBounds(200,50,500,500);
         setTitle("2D Rotation by Fatih Coskun");
         show();
         rP.startRotation();
    private class MyRotatingPanel extends RotatingPanel
         private int x;
         private int y;
         private Font f;
    public MyRotatingPanel()
         super(true);
         f = new Font("Serif", Font.PLAIN, 18);
         setBackground(Color.black);
    public void paintComponent(Graphics g)
         super.paintComponent(g);
         x = rotationCenter.x;
         y = rotationCenter.y;
         Graphics2D g2 = (Graphics2D)g;
         g2.rotate(ror,x-50+100/2,y-50+100/2);
         g2.setColor(Color.white);
         g2.setFont(f);
         g2.drawString("Fatih", x-40, y-10);
         g2.drawString("Coskun", x-10, y+20);
         g2.drawRect(x-50,y-50,100,100);
         g2.dispose();
    public static void main (String[] args)
         new Rotation();
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class RotatingPanel extends JPanel
         private Graphics2D g2D;
         private int freq;
         private int startFreq;
    double theta;
                   double ror = 0;
                   Point rotationCenter;
         private Timer timer;
         private boolean frozen;
    public RotatingPanel()
         this(false);
    public RotatingPanel(boolean activateMouse)
         this(5, Math.PI/25.0, activateMouse);
    public RotatingPanel(int freq, double theta, boolean activateMouse)
         super();
         this.freq = freq;
         startFreq = freq;
         this.theta = theta;
         UniversalListener uL = new UniversalListener();
         timer = new Timer(freq, uL);
         if (activateMouse)
              this.addMouseMotionListener(uL);
              this.addMouseListener(uL);
    public void startRotation()
         rotationCenter = new Point(this.getWidth()/2, this.getHeight()/2);
         timer.start();
    private void rotate(double theta)
         ror = ror + theta;
         repaint(rotationCenter.x-80,rotationCenter.y-80,160,160);
    private class UniversalListener extends MouseAdapter implements MouseMotionListener, ActionListener
         private int x, altx;
         boolean toleft = false;
    public void mouseDragged(MouseEvent event)
         if (x < event.getX()) rotate(theta);
         if (x > event.getX()) rotate(-theta);
         altx = x;
         x = event.getX();
    public void mousePressed(MouseEvent event)
         x = event.getX();
         timer.stop();
    public void mouseMoved(MouseEvent event)
    public void mouseReleased(MouseEvent event)
         timer.setDelay(freq = startFreq);
         if (altx > event.getX() && !toleft)
              theta =-theta;
              toleft = true;
         else if (altx > event.getX() && toleft)
                   theta =-theta;
                   toleft = false;
         rotationCenter = new Point(event.getX(),event.getY());
         repaint();     
         timer.start();
    public void actionPerformed(ActionEvent event)
         rotate(theta);
         timer.setDelay(freq++);

Maybe you are looking for

  • ISight not working after update

    Im in a remote area of Puerto Rico and relying on skype to talk to family back home. It was working just fine the first few weeks but now it seems that after my most recent update the iSight wont work on Skype, PhotoBooth, iChat or anything. (when in

  • Need ATI XP driver on Satellite Pro A200-15G

    Hi, I'm italian so my english will be not very well :) I've installed XP on my toshiba Satellite Pro A200-15G. I've searched the display driver for this model of notebook on this toshiba site, but i didn't find it. Where i can find it? Ah, another th

  • Upgrading from PageMaker 7 to InDesign CS4

    Okay - My PageMaker 7.0 went a little nuts this week. A few weeks ago I had installed my daughter's InDesign CS2  that she no longer uses (since she moved to MAC) to see if I could handle an upgrade to InDesign. Was planning on purchasing CS4 if I fe

  • Change BarCode from Trip number to Pernr and Trip Number

    Hi Gurus, My client wants the Expense report bar code to be changed from Trip number to Personnel number and Trip number. The technical team has been able to merge the two entries, but the report displays only 10 characters. They are unable to extend

  • Oracle self-training

    Hi all, I use Oracle 8.1.6 in work a little but I'd like to learn alot more about it especially troubleshooting and system administration. Hopefully I'd like to do exams in this one day. Therefore, I'm going to download Oracle 9i for home PC to play