L28 - Computer Science 101 SS C Lecture 28 Contents! 2 Ex01...

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

View Full Document Right Arrow Icon
CompSci 101 Lecture 31 1 Computer Science 101 SS C Lecture 28 Contents Using Timers for Animation Rectangles to store object positions Boundary Conditions ‘Moving object’ classes Ex01 – Using a Timer object The JPanel should have a Rectangle falling diagonally towards the left. Its colour alternates between red and blue. 2 When the user clicks the mouse the box resets to its initial position 3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Ex01 - Using a Timer import java.awt.*;import javax.swing.*;import java.awt.event.*; public class L28JPanelEx01 extends JPanel { public static final int SIZE = 20; public static final Rectangle INITIAL_POS = new Rectangle(600,0,20,20); private Timer t; private int count = 0; private Rectangle area; public L28JPanelEx01() { t = new Timer(200, this); } public void actionPerformed(ActionEvent e) { } public void paintComponent(Graphics g) { super.paintComponent(g); } public void mousePressed(MouseEvent e) { } //Other MouseListener methods omitted Ex02 – Using a Timer object The box should move along the line, alternating between the top and bottom of it.
Background image of page 1

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

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

This note was uploaded on 03/01/2012 for the course COMPSCI 101 taught by Professor Adrianaferraro during the Summer '12 term at Auckland.

Page1 / 2

L28 - Computer Science 101 SS C Lecture 28 Contents! 2 Ex01...

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