$35.00 Java threads program: hare vs tortoise
- This tutorial was purchased 1 time and hasn't been rated yet.
- Posted on Nov 24, 2008 at 11:51:57PM
A:
Preview: ... /panel for buttons<br> a1 = new Button("Start Race"); //set up for the buttons<br> q.add(a1);<br> contentPane.add(BorderLayout.SOUTH, q);<br> Handler handler = new Handler();<br> a1.addActionListener(handler);<br>} // end of constructor<br><br>class Display extends Canvas{<br><br> public void paint(Graphics g)<br> //EFFECTS: displays the graphics for the racer tracks and the racer as represented by a letter<br><br> {<br> g.setColor(Color.blue);<br> g.drawLine(0,200,500,200);<br> g.drawLine(0,215,500,215); //track a1<br> g.drawLine(0,315,500,315); //track b1<br> g.drawLine(0,300,500,300);<br> g.drawString("H", a1_x, a1_y);<br> g.drawString("T", a2_x, a2_y);<br> g.drawString(s_a1, 10,10);<br> g.drawString(s_a2, 10, 30);<br> }<br>}<br><br> public void move(int x, int y, int track)<br> //REQUIRES: x,y and track must not be null<br> //MODIFIES: this<br> //EFFECTS: changes the cooridinates of our racer to (x,y);<br><br> {<br> if(track == 1){<br> a1_x = x;<br> a1_y = y;<br> if (x >= 500)<br> {<br> ...
The full tutorial is about 1895 words long plus attachments.
Attachments:
Screenshot-Hare vs Tortoise Race.png (7K)