import javax.swing.*; import java.awt.event.*; import java.awt.*; class TimerShow extends JPanel implements ActionListener { int size_x = 20; int pos_x = 5; int pos_y = 5; int c = 0; int i = 1; Timer timer1 = new Timer(1500, this); Timer timer2 = new Timer(100, this); TimerShow( ) { JFrame f = new JFrame(); f.setSize(300, 300); f.setLocation( 1400, 300 ); f.add( this ); f.setVisible( true ); } public void paintComponent(Graphics g) { super.paintComponent( g ); g.fillOval(pos_x, pos_y, size_x, size_x); } public void actionPerformed(ActionEvent e) { if ( e.getSource() == timer1 ) { pos_x = (pos_x + 10) % getWidth(); ; } else { pos_y = (pos_y + 5) % getHeight(); Color k = new Color( c%256, (255-c)%256, c%256 ); if (c >= 255) i = - 1 ; if (c == 0) i = 1; c = c + i; setBackground( k ); } repaint(); } public static void main(String a[]) { new TimerShow(); } }