//CirclesQ.java //add a LinkedList queue import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.LinkedList; public class CirclesQ extends JApplet implements ActionListener { public static final int STARTINGCIRCLES=12; public static final int DELAYDIFF=50; public static final String delayLabelPrefix="Delay in ms: "; private JTextField numCirclesText; private JLabel delayLabel; private int circles=STARTINGCIRCLES; private int animationDelay = 1000; // millisecond delay private Timer animationTimer; // Timer drives animation private LinkedList queue; //Colors of the rings public void init() { JButton fasterButton; JButton slowerButton; queue = new LinkedList(); //fill the queue of Colors for (int i=0; icircles; i--) queue.removeFirst(); //dequeue if ( ! animationTimer.isRunning() ) animationTimer.restart(); repaint(); } } ); fasterButton = new JButton( "Faster!" ); container.add( fasterButton ); fasterButton.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent event ) { if (animationDelay > DELAYDIFF) animationDelay -= DELAYDIFF; restartAnimation(); delayLabel.setText( delayLabelPrefix + animationDelay ); } } ); slowerButton = new JButton( "Slower!" ); container.add( slowerButton ); slowerButton.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent event ) { animationDelay += DELAYDIFF; restartAnimation(); delayLabel.setText( delayLabelPrefix + animationDelay ); } } ); delayLabel = new JLabel( delayLabelPrefix + animationDelay ); container.add( delayLabel ); } public void start() { startAnimation(); // begin animation } public void paint( Graphics g ) { super.paint( g ); int x1=0, y1=30, width, height, gap, appletSize; appletSize = Math.min(getWidth(),getHeight()); //width = getWidth()-10; //height = getHeight()-30; width = appletSize-20; height = appletSize-20; gap = appletSize/circles/2; queue.removeFirst(); //dequeue queue.addLast( new Color((int)(Math.random()*256), //enqueue (int)(Math.random()*256), (int)(Math.random()*256))); for (int i=0; i