Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. //--------------------------------------------------------------
  2. //    Start a race between blue and red, track the winner
  3. //    Use threads to manage each rectangle's movement
  4. //    Allow for user interaction, like stopping and starting
  5. //--------------------------------------------------------------
  6.  
  7.  
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import javax.swing.*;
  11.  
  12. public class ConcurrencyPanel extends JPanel
  13. {
  14.     class runnerThread extends Thread {
  15.        
  16.         public void run() {
  17.             // while width of both rectangle < 250 px
  18.             // redraw by random increments of 1-10
  19.             // use timer? or sleep?
  20.         }
  21.     }
  22.    
  23.     public ConcurrencyPanel ()
  24.     {
  25.         setPreferredSize(new Dimension(600,250));
  26.        
  27.         JButton startRace = new JButton("Start The Race!");
  28.         JButton stopRace = new JButton("Stop The Race!");
  29.         JLabel winnerText = new JLabel("Winner: ");
  30.        
  31.         add (startRace);
  32.         add (stopRace);
  33.         add (winnerText);
  34.        
  35.     }
  36.    
  37.     public void paintComponent (Graphics page)
  38.     {
  39.         super.paintComponent(page);
  40.         page.setColor(Color.blue);
  41.         page.fillRect(0,80,0,20);
  42.        
  43.         page.setColor(Color.red);
  44.         page.fillRect(0,120,0,20);
  45.     }
  46.        
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement