SliderProgram

SliderProgram - // create a new slider Slider slider = new...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * File: SliderProgram.java * ------------------------- * This programs shows an example of threads. */ import acm.program.*; import acm.graphics.*; import acm.util.*; import java.awt.event.*; import javax.swing.*; i public class SliderProgram extends GraphicsProgram { p public void run() { add(new JButton("Slide"), SOUTH); addActionListeners(); } public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (cmd.equals("Slide")) {
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // create a new slider Slider slider = new Slider(SIZE, rgen.nextColor()); add(slider, 0, rgen.nextDouble(0, 300)); a // run the slider on a new thread Thread sliderThread = new Thread(slider); sliderThread.start(); } } /* constants */ private static final int SIZE = 20; /* private instance variables */ private RandomGenerator rgen = RandomGenerator.getInstance(); }...
View Full Document

This note was uploaded on 02/18/2010 for the course CS 106A taught by Professor Sahami,m during the Fall '08 term at Stanford.

Ask a homework question - tutors are online