Home E-Books Special Effects and Game Development in Java The Applet RisingSun

Special Effects and Game Development in Java(TM) - The Applet RisingSun


 import java.applet.*;

 import java.awt.*;



 public class risingsun extends Applet {



 public void paint(Graphics g)

 {

     //Create the sky.

     g.setColor(Color.blue);

     g.fillRect( 0, 0, 200, 100);



     //Create the sun.

     g.setColor(Color.yellow);



     //The method fillOval() draws a filled oval

     //in the middle of the screen with the height and

     //width 50.

     g.fillOval(25,25,50,50);



     //Create the sun beams with fillArc(),

     //setColor() is not needed because the pen's

     //color will be the same.

     g.fillArc(0,0,100,100,180,10);

     g.fillArc(0,0,100,100,160,10);

     g.fillArc(0,0,100,100,140,10);

     g.fillArc(0,0,100,100,120,10);

     g.fillArc(0,0,100,100,100,10);

     g.fillArc(0,0,100,100,800,10);

     g.fillArc(0,0,100,100,60,10);

     g.fillArc(0,0,100,100,40,10);

     g.fillArc(0,0,100,100,20,10);

     g.fillArc(0,0,100,100,0,10);



     //Create the ground

     //Create brown color, there is no default brown color

     Color ground = new Color(128,64,0);

     g.setColor(ground);



     //Fill the bottom part of the screen with brown

     g.fillRect( 0, 50, 200, 50);



     //Create a black text

     g.setColor(Color.black);

     g.drawString("Hello Sweden!",70,50);

 }



 }