13.07.2015 Views

Multithreaded Graphics - Custom Training Courses - Coreservlets.com

Multithreaded Graphics - Custom Training Courses - Coreservlets.com

Multithreaded Graphics - Custom Training Courses - Coreservlets.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Redraw Everything in paint• Idea– Have user actions change non-graphical data structures,then call repaint.– The repaint method sets a flag that tells the eventhandlingprocess to call update.– The standard update method clears the screen and thencalls paint.– The paint method <strong>com</strong>pletely redraws everything.• Advantage– Easy• Disadvantages– Flickers, slow.7Redrawing Everything in paint:Exampleimport java.applet.Applet;import java.awt.*;import java.awt.event.*;import java.util.*;/** An applet that draws a small circle where you click.*/public class DrawCircles extends Applet {private ArrayList circles;public void init() {circles = new ArrayList();addMouseListener(new CircleDrawer());setBackground(Color.WHITE);}...8

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!