Hi
Can some translate this code to english, and in more details is well as i have about 5 min to explain the code and how it works.
import java.applet.Applet; import java.awt.Button; import java.awt.Color; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class HorseRace extends Applet implements ActionListener { private Button replay; private String theWinner = "click button to race"; private int horse1 = 30; private int horse2 = 30; private int horse3 = 30; public void init() { setSize(400, 200); setBackground(Color.cyan); this.replay = new Button("Move Again"); add(this.replay); this.replay.addActionListener(this); } public void paint(Graphics g) { g.setColor(Color.green); g.fillRect(20, 50, 10, 100); g.fillRect(30, 50, 300, 10); g.fillRect(30, 80, 300, 10); g.fillRect(30, 110, 300, 10); g.fillRect(30, 140, 300, 10); g.fillRect(330, 50, 10, 100); g.setColor(Color.darkGray); g.fillOval(this.horse1, 60, 20, 20); g.fillOval(this.horse2, 90, 20, 20); g.fillOval(this.horse3, 120, 20, 20); if (this.horse1 >= 310) { this.theWinner = "Horse 1 wins!"; } if (this.horse2 >= 310) { this.theWinner = "Horse 2 wins!"; } if (this.horse3 >= 310) { this.theWinner = "Horse 3 wins!"; } g.drawString(this.theWinner, 50, 170); } public void actionPerformed(ActionEvent e) { this.horse1 += (int)(Math.random() * 30.0D + 10.0D); this.horse2 += (int)(Math.random() * 30.0D + 10.0D); this.horse3 += (int)(Math.random() * 30.0D + 10.0D); repaint(); } }
ASAP Please as i don't have much time.
Thanks