Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //--------------------------------------------------------------
- // Start a race between blue and red, track the winner
- // Use threads to manage each rectangle's movement
- // Allow for user interaction, like stopping and starting
- //--------------------------------------------------------------
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class ConcurrencyPanel extends JPanel
- {
- class runnerThread extends Thread {
- public void run() {
- // while width of both rectangle < 250 px
- // redraw by random increments of 1-10
- // use timer? or sleep?
- }
- }
- public ConcurrencyPanel ()
- {
- setPreferredSize(new Dimension(600,250));
- JButton startRace = new JButton("Start The Race!");
- JButton stopRace = new JButton("Stop The Race!");
- JLabel winnerText = new JLabel("Winner: ");
- add (startRace);
- add (stopRace);
- add (winnerText);
- }
- public void paintComponent (Graphics page)
- {
- super.paintComponent(page);
- page.setColor(Color.blue);
- page.fillRect(0,80,0,20);
- page.setColor(Color.red);
- page.fillRect(0,120,0,20);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement