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++);

Similar Messages

  • Cant get ipad out of recovery mode

    I tried to update my ipad and it put it into recovery mode and i cant get it out. I tried to hook it up to itunes and it wont  let me restore it either. Help!!

    FORCE IPAD INTO RECOVERY MODE
    1. Turn off iPad
    2. Turn on computer and launch iTunes (make sure you have the latest version of iTune)
    3. Plug USB cable into computer's USB port
    4. Hold Home button down and plug the other end of cable into docking port.
    DO NOT RELEASE BUTTON until you see picture of iTunes and plug
    5. Release Home button.
    ON COMPUTER
    6. iTunes has detected iPad in recovery mode. You must restore this iPad before it can be used with iTunes.
    7. Select "Restore iPad"...
    Note:
    1. Data will be lost if you do not have backup
    2. You must follow step 1 to step 4 VERY CLOSELY.

  • Headphone jack (the very end) is stuck in my iphone 4 and i cant get it out. How much would it cost to get it out?:/

    Headphone jack (the very end) is stuck in my iphone 4 and i cant get it out. How much would it cost to get it out?:/

    i have tried to restore via itunes as i would have usually, half way through i get an error code 3194 pop up.....and yes i do back up.
    Thanks for your help but i've already tried this a couple of times.

  • I was in the process of jailbreaking and updating my ipod and when i was updating it,it went into recovery mode and now i cant get it out of recovery mode so what can i do??

    i was in the process of jailbreaking and updating my ipod and when i was updating it,it went into recovery mode and now i cant get it out of recovery mode so what can i do??

    Go elsewhere:
    Jailbreaking voids the Apple warranty and also means that you will not get any support from Apple, including from this Apple forum. Jailbreaking can't be discussed in this Apple forum.
    Unauthorized modification of iOS has been a major source of instability, disruption of services, and other issues

  • My Headphone jack in my iphone has a peice of headphone plug stuck inside so it constantly thinks theres headphones plugged in and i cant get it out!! what do i do?!?!!? please help!

    My Headphone jack in my iphone has a peice of headphone plug stuck inside so it constantly thinks theres headphones plugged in and i cant get it out!! what do i do?!?!!? please help!

    Make an appointment at the genius bar. They may be able to help you.

  • We put a camcorder dvd into the our mac book and it doesn't recognize it and we cant get it out.  what can we do???

    we put a camcorder dvd into the our mac book and it doesn't recognize it and we cant get it out.  what can we do???

    Apple drives in MacBooks do not support mini DVDs. They cannot be injected or ejected properly. Some of them work in tray-loaders like on the Mac Pro.
    Yes, make an appointment and take it to the Genius Bar.

  • Cant get tv out working

    im trying to get tv out working on my ati x300.
    i connected it to my main display and noticed the framebuffer kicked in during boot. it changed the console res to 1680x1050. i cant see anything on my crappy little crt tv.
    looking through the wiki it says to run xrandr but i believe i would need to be connected through svideo for that to work.
    if im using vesa i can see whats going on and log in without any problems. i cant run xbmc though.
    if i use the radeo driver i get nothing. and again, it looks like the res is being set too high even though i defined 800x600 in xorg.conf.
    removing xorg.conf i still get nothing.
    you guys have any ideas?

    Wow, I'm glad I found this topic, I was beginning to think it was just me. Just like you guys, I have tried everything, and have received the same results. I really hope we can get an answer to this soon, because I need to run Sax 'N Dottys Karaoke presenter, (via Windows Vista/BootCamp) next week!! Without a video out, Im screwed. (Unless anyone knows of a comparable MAC Karaoke presenter that will read MP3G's)
    Message was edited by: petevspete

  • Cant get midi out signals

    I use a Yamaha Disklavier as a keyboard connected to Garageband. I can send midi data from the keyboard to Garageband. When I playback the recorded track, I cant get any midi out data to play the Disklavier. When I use other home studio software, it works perfectly. When I use "Test Setup" in the "Audio MIDI Setup" utility, the Disklavier receives the test signals and plays perfectly the notes. What am I doing wrong? Thank you for your help.

    GB doesn't send any Midi out.
    There is a plugin called MidiO set you can use to send the Midi of one track out to a Midi instrument.

  • Theres something in my iPhone 5 jack and i cant get it out, what do i do?

    i usually keep my phone in the front pocket of my jeans, as people do, i think a piece of pocket fluff must have gotten inside the jack and when i plugged my headphones in it must've pushed it in making it stuck. i've tried getting the hoover to suck it out and used a small tooth pick to get it out but its still stuck in pretty good. i really dont know what to do, do i go to apple? will they take it apart and take it out?

    Get a paperclip & unfold it. Now, get the stickest tape you can find and wrap then end, sticky side out...make sure it is FIRMLY atached to the paperclip end. Insert into headphone jack, rotate & it should get everything out. Repeat as necessary.
    Finish with compressed air.

  • Have new MacBook pro tried to install windows 7 failed cant get DVD out of drive

    Tried to install windows 7 using boot camp message said can't install on any of the partitions can't get DVD out to restore eject button doesn't have any effect is there a key combination to eject dvd

    First try the normal methods to remove the disc. Drag its icon to the Trash can in the Dock or select 'Eject' from the File menu.
    If you are running a virtual machine, e.g. VMFusion, ensure that the CD is disconnected from the virtual machine. This will sometimes allow the CD to now show up in Mac OS X.
    Shut down the computer and start up whilst holding down the mouse button. This may take some time, but keep your finger on the mouse button right up until the disc comes out or the log-in screen has appeared.
    If you have Toast Titanium installed on your computer, choose EJECT DISC from the menubar.
    Sometimes you can successfully use the eject disc button in iTunes even if the disc is not visible to the Finder
    Open Disk Utility and choose the disc you wish to eject in the left-hand pane, then click on the Eject button.
    Some Macintoshes have a paperclip hole that you can insert a straightened paperclip into, manually triggering the eject mechanism.
    Open Terminal and type "drutil tray eject" to eject the disc/tray, and "drutil tray close" to close the tray.
    Restart the computer while holding down Command-Option-O-F, to enter the Open Firmware prompt. Type "eject cd" without the quotes, and press return. The disk ought to eject. To start into OS X, type "mac-boot" without the quotes. Press return, and the computer will continue with the startup. (This will not work on an Intel Mac. There is no Open Firmware on Intel Macs. )
    If your computer has an eject button on the keyboard, restart the computer holding down the Option key. When the startup disk selection screen appears, let go of the option key and press the keyboard's eject button.
    http://guides.macrumors.com/Force_Eject_a_Stuck_CD_or_DVD

  • My iphone 4 is suck in recovery mode tried after an update and i cant get it out, tried the usual

    i had an up date on my phone this morning so i updated it as usual.
    it then went into recovery mode and has stayed in it ever since.
    I have done the usual to reboot it by pressing the on/off button along with the home button but it doesnt want to know, it doesnt even have the slider off at the top of the screen appear.
    Just keeps showing the screen with the itunes logo and connection lead underneth.
    I want to restore with out loosing any data what so ever, i've also tried Dr.Fone which only scans for lost data, i dont not want to pay for trying to retrieve my lost data for this dam update........can anyone help me please.
    I think the update for for IOS 7 something but not sure which one, i generally update to what ever comes through at the time
    Many Thanks

    i have tried to restore via itunes as i would have usually, half way through i get an error code 3194 pop up.....and yes i do back up.
    Thanks for your help but i've already tried this a couple of times.

  • Cant get sound out of gstreamer apps

    Hey Gang,
    well I ran through the alsa wiki pages, the pulseaduio wiki pages and sound works great for everything.
    except for gstreamer. I'm running the gnome desktop enviorment, and everything that uses gstreamer doesnt get any sound output at all.
    Now I've gone and installed the gstreamer plugins, they're all in. youtube and other flash player sounds work, VLC player works, games work, everything except gstreamer.
    Any ideas?

    skottish wrote:
    nebri wrote:It's not that I'm missing codecs, because simply put other media players that do not use gstreamer can play the media properly and I can hear it.
    gstreamer doesn't use any of the codecs that other applications do. You have to install more than just gstreamer to get things to work. Check out pacman -Ss gstreamer for all of the goodies if you haven't yet.
    I've already installed the gstreamer-plugins group which I figured would have done the job as it seems to do it for most others. But I'm still not hearing a single thing from gstreamer apps :s.

  • Cant get audio out from iPad airplay on optical audio

    I have an apple tv in school for streaming video of drama classes to big screen. Apple tv is plugged into HDMI on projector and i airplay the videos from iPad. My issue is getting sound - the projector has no speaker in it so no sound is currently playing. I purchased an optical audio to 3.5mm jack lead to go from the rear of the apple tv to a set of speakers on my desk. Nothing seems to be happening - will this setup just not work or is there a way for my classes to hear the soound as i airplay it?
    Any help GREATLY appreaciated!
    Thanks

    Where did you get the lead - it would ordinarily require a D/A converter between the optical connector and the 3.5mm jack...

  • Cant get voices out of my external keyboard

    Just hooked up my Yamaha Motif to my I mac via USB Port. I can play logic internal sounds thru my keyboard but I want to use my motif sounds. clueless!
    My situation, I've been writing songs in the Motif workstation and would like to down load the information into Logic. The songs are multi tracks. Is their an easy way?
    Just Getting Started. Any suggestions!

    Hi,
    sequencer Data is Data, which means it is MIDI or is reproducible with MIDI. I don't know if there's direct way of exporting the Motif's sequencer parts as MIDI (.SMF or .MID files). If all else fails, you could simply play the patterns back and record the playback with Logic, which gets the MIDI data into Logic for sure. I would look up the Motif's Manual if there is an export function that provides you with a set of SMF files, which you could then import into Logic and save as Apple Loops.
    Fox

  • Cant get 2 out of 3 Flash buttons to work!

    I have a school project and our teacher can't even figure out whats wrong. We have to make a movie/mini site for our final project and we have an intro layer/scene that stops and three buttons fade in to navigate to the respective sections (forensics, web dev, and business). The forensics button goes to the forensics page and the home button brings you back to nav page, perfect. However when I try to do the exact same commands for the other two buttons it doesn't work. Can anyone clue me in on what I am doing wrong? Its due Thursday and I am freaking out!
    Here is the file... https://dl.dropbox.com/u/9832993/final.fla

    Try to find all of the gotoAndWhatever commands that you use and you will find you have at least one making things go where you do not want them to go. 
    Putiing code on() objects such as the way you did with your buttons is bad practice.  If that is what you were taught, you are being taught bad practices. 
    On your buttons you are putting code like...
    on(release){
        gotoAndPlay(15);
    Instead of doing that, assign that button an instance name in the properties panel where it says <Instance Name>.  Let's say you name it "businessBtn"... if so, then in the timeline, in a layer you reserve for actionscript, you would use the following code...
    businessBtn.onRelease = function(){
        gotoAndPlay(15)
    And all the rest of your buttons' code would be there in that same frame of the timeline where you can see it all at once.  Then go collect the other tidbits of code that you have along the timeline in different layers and move it to corresponding frames of that one actionscript layer.  Now you have all your code in one layer where it is easy to find and easier to look thru to track down any problems with it.

Maybe you are looking for