nightscene, Java applet - bluej Programming

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
1,598
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Oct 8, 2009

This applet draws a series of stars, random in color and size (1 to 6 pixesl about), all over the screen. It then draws the moon in a random place, and the horizon. Since the paint method is automatically called whenever an applet needs to redraw itself, I moved the window around a little bit to show the effect.

A fun project might be to move the moon around the screen (as if rising or going behind the horizon) while the stars are continuously changing.

Category:

Education

Tags:

License:

Standard YouTube License

  • likes, 3 dislikes

Link to this comment:

Share to:

Uploader Comments (successfulbuild)

  • y = this.getHeight() - 50;

    g.setColor(Color.BLUE);

  • for(x = 0; x < this.getWidth(); x++)

    {

    g.setColor(Color.BLUE)

    g.fillRect(x,y,1,1);

    g.setColor(Color.BLACK);

    g.fillRect(x, y+1, 1, this.getHeight());

    y += rand.nextInt(5) - 2

    }

  • hi, i'm trying to code the horizon using the random object. but i can't get it to work. it only gives me a bunch of scattered lines within a certain range.

  • @bingin15 post the variable initializations and then the for loop, at the end of the code, and let me know if it works.

see all

All Comments (7)

Sign In or Sign Up now to post a comment!
  • @successfulbuild hi, i should have posted this a while ago, but i received the answer i needed from someone in my class. i needed to just add whatever the random number was to the y value each time.

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more