Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Translate Java Code Into English

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Translate Java Code Into English

    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


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Translate Java Code Into English

    It's already in english

    Or did you mean "Can someone write an essay on how this piece of code works for me"?

    // Json

  3. #3
    Junior Member
    Join Date
    Nov 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Translate Java Code Into English

    Quote Originally Posted by Json View Post
    It's already in english

    Or did you mean "Can someone write an essay on how this piece of code works for me"?

    // Json
    why not, little support from java community

  4. #4
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Translate Java Code Into English

    Cash or card?

    // Json

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Translate Java Code Into English

    In a quick glance, it looks like the code is setting up an applet that has several "lanes" and spheres that I suspect represent horses in a race. Everytime the "Move Again" button is pressed, it advances the 3 horses by a random distance. When the first horse reaches a certain point, it declares it the winner.

    I take either cash, credit card, or paypal fyi

Similar Threads

  1. Convert C/C++ code to Java
    By cristianll in forum What's Wrong With My Code?
    Replies: 13
    Last Post: November 14th, 2009, 01:43 AM
  2. Convert Java Program to Java ME code
    By rinchan11 in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: October 5th, 2009, 10:18 PM
  3. Java Code Help - Calling Method
    By KevinGreen in forum Object Oriented Programming
    Replies: 5
    Last Post: September 18th, 2009, 12:55 AM
  4. Replies: 5
    Last Post: September 6th, 2009, 04:39 AM