AnimatedCar - { repaint(); //each time timer fires it will...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//© A+ Computer Science - www.apluscompsci.com //Name - //Date - //Lab - import java.awt.Graphics; import java.awt.Color; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.Timer; import javax.swing.JFrame; import java.awt.Canvas; class AnimatedCar extends Canvas { private int x; private int y; private Timer timer; private final static int SLEEP = 50; //bigger # = slower animation public AnimatedCar(int width, int heigth) { setSize(width, heigth); setVisible(true); setBackground(Color.BLACK); x = 0; y = 50; ActionListener paintCaller = new ActionListener(){ public void actionPerformed(ActionEvent event)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { repaint(); //each time timer fires it will call paint } }; timer = new Timer(SLEEP, paintCaller); timer.start(); } public void update(Graphics window) { paint(window); } public void paint( Graphics window ) { window.setColor(Color.BLACK); window.fillRect(0,0,getWidth(),getHeight()); window.setColor(Color.WHITE); window.drawString("Animation Lab - Lab05c", 25, 50 ); window.setColor(Color.GREEN); window.fillRect(x,y+20,120,70); window.setColor(Color.BLUE); window.fillOval(x,y+60,50,50); window.setColor(Color.BLUE); window.fillOval(x+70,y+60,50,50); x = x +50; if (x>800) {x = 0; } } }...
View Full Document

Page1 / 2

AnimatedCar - { repaint(); //each time timer fires it will...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online