woensdag 28 december 2011

Rotating Line Example



I was preparing a swinning ball example that I once made in a one level remake of the adams family. But I had not worked with cos and sin yet. In Java the commands work with radians in stead of degrees so I needed to take that into account to. I looked up cos and sin and toTadians and quickly made this applet example. A rotating line.

 


import java.awt.*;
import java.applet.*;

public class RotatingLineExample extends Applet implements Runnable{

 Graphics bufferGraphics;
    Image offscreen;
 double x1;
 double y1;
 double x2;
 double y2;
 int angle;

 public void init() {
        setBackground(Color.black);
        offscreen = createImage(getSize().width,getSize().height);
        bufferGraphics = offscreen.getGraphics();
  x1 = getSize().width / 2;
  y1 = getSize().height / 2;
  new Thread(this).start();

 }

 public void rotateline(){
  x2 = Math.cos(Math.toRadians(angle)) * 100 + x1;
  y2 = Math.sin(Math.toRadians(angle)) * 100 + y1;
  angle++;
  if ( angle > 360 ) angle = 0;
 }

    public void run() {
        for(;;) { // animation loop never ends
   rotateline();
         repaint();
         try {
             Thread.sleep(10);
             }
             catch (InterruptedException e) {
             }
     }
    }

     public void update(Graphics g){
     bufferGraphics.clearRect(0,0,getSize().width,getSize().height);
     bufferGraphics.setColor(Color.red);
        bufferGraphics.drawString("Rotating Line Example.",10,10);
  bufferGraphics.drawLine((int)x1,(int)y1,(int)x2,(int)y2);
        g.drawImage(offscreen,0,0,this);
     }

}

Blinking Unit Example



Press the mouse on th applet to activate. Then use wsad to move the blinking unit across the applet screen.
I was preparing a turn based example but I felt it was a little bit to much to do in one time. So I decided to make a part of that example as this example. In this applet you can move a unit across the field. It stops blinking and becomes visible if you move it. It then after one second becomes invisible to become visible again after another second.

 


import java.awt.*;
import java.applet.*;

public class BlinkingUnitExample extends Applet implements Runnable{
 Graphics bufferGraphics;
 Image offscreen;

 int unitx;
 int unity;
 int unitsize = 16;
 boolean unitvisible = false;
 long blinktime;

 public void init() {
        setBackground(Color.black);
        offscreen = createImage(getSize().width,getSize().height);
        bufferGraphics = offscreen.getGraphics();
  unitx = getSize().width / 2 / unitsize - 1;
  unity = getSize().height / 2 / unitsize - 1;
  new Thread(this).start();
 }

    public void run() {
        for(;;) { // animation loop never ends
         repaint();
         try {
          doblinktime();
             Thread.sleep(10);
             }
             catch (InterruptedException e) {
             }
     }
    }

 public void doblinktime(){
  if ( System.currentTimeMillis() > blinktime ){
   if ( unitvisible == true ) {
    unitvisible=false;
   } else {
    unitvisible=true;
   }
   blinktime = System.currentTimeMillis() + 1000;
  }
 }

     public void update(Graphics g){
     bufferGraphics.clearRect(0,0,getSize().width,getSize().height);
     bufferGraphics.setColor(Color.red);
        bufferGraphics.drawString("Blinking Unit Example.",10,10);
        bufferGraphics.drawString("w/s/a/d to move unit.",10,220);
  if ( unitvisible == true ){
   bufferGraphics.fillRect(unitx * unitsize , unity * unitsize , unitsize , unitsize);
  }
        g.drawImage(offscreen,0,0,this);
     }

 public void resetblink(){
   blinktime = System.currentTimeMillis() + 1000;
   unitvisible = true;
 }


 public boolean keyUp (Event e, int key){
    if( key == 119 ) // w key
        {
         if( unity > 1 ) unity--;
         resetblink();
        }
        if( key == 97 ) // a key
        {
         if( unitx > 1 ) unitx--;
         resetblink();
        }
        if( key == 100 ) // d key
        {
         if( unitx < 18 ) unitx++;
         resetblink();
        }
        if( key == 115 ) // s key
        {
         if( unity < 12 ) unity++;
         resetblink();
        }

  return true;
 }

}

zondag 25 december 2011

ScrollText Example



A simple Scrolltext Example made in Java. The sourcecode is below. I can see some flickering by the scrolltext and I have no idea what causes it. I am a little rusty with Java.


 


import java.awt.*;
import java.applet.*;

public class ScrollTextExample extends Applet implements Runnable{

 Graphics bufferGraphics;
    Graphics scrolltextGraphics;
    Image offscreen;
 Image scrolltextimage;
 String message = "This is a scroll text message made in java. There is not much to report...      ";
 int scrolltextloc =0;
 int scrolltextoffset = 0;


 public void init() {
        setBackground(Color.black);
        offscreen = createImage(getSize().width,getSize().height);
        scrolltextimage = createImage(getSize().width+12, 12);
        scrolltextGraphics = scrolltextimage.getGraphics();
        bufferGraphics = offscreen.getGraphics();
  new Thread(this).start();

 }
    public void run() {
        for(;;) { // animation loop never ends
         repaint();
         try {
    scrolltext();
             Thread.sleep(10);
             }
             catch (InterruptedException e) {
             }
     }
    }

    public void scrolltext(){
  scrolltextoffset--;
  if ( scrolltextoffset < 0 ) {
   scrolltextoffset = 12;
   scrolltextloc++;
   if ( scrolltextloc > message.length()-1) scrolltextloc = 0;
  }
     scrolltextGraphics.clearRect(0,0,getSize().width+12,12);
  scrolltextGraphics.setColor(Color.white);
  int stloc = scrolltextloc;
  String temp;
  for ( int i = 0 ; i < 30 ; i++)
  {
   temp = message.substring(stloc,stloc+1);
   scrolltextGraphics.drawString(temp,i*12+scrolltextoffset,10);
   stloc++;
   if(stloc > message.length()-1) stloc = 0;
  }

    }

     public void update(Graphics g){
     bufferGraphics.clearRect(0,0,getSize().width,getSize().height);
     bufferGraphics.setColor(Color.red);
        bufferGraphics.drawString("ScrollText Example",10,10);

  //scrolltextGraphics.clearRect(0,0,getSize().width+12,12);
  //scrolltextGraphics.setColor(Color.white);
  //scrolltextGraphics.drawString(message,0,10);




  bufferGraphics.drawImage(scrolltextimage,0,100,this);

        g.drawImage(offscreen,0,0,this);
     }

}

Fog of War Example



Fog of War in games is hidden terrain and usually covered with black tiles. The player moves his unit across the map and the map around him gets visible. I programmed this a couple of times however I did not include the nice border finishings. I recreated the fog of war in Java this time. In the code the map is drawn if the fogmap on the draw position has a value of 1. It starts out as 0. I use a brush array to draw ontop of the player position that sets the fogmap to value 1.
Use r to reset the map and wsad keys to move.

I will see if I can program another couple of examples. I wanted to do a scrolltext example and am thinking about it tonight. I also had a turn based example planned and a bomberman example and a swinging bal platformer example. But I have no idea if these will be finished this weekend.

Well Merry christmas from me and if I do not post anymore till next year a happy new year.

 


import java.applet.*;
import java.awt.*;
import java.util.Random;
import java.awt.image.BufferedImage;


public class FogOfWarExample extends Applet implements Runnable {

 Random r = new Random();
 Graphics bufferGraphics;
    Image offscreen;
    Image image2;
    Image image3;
    Image image4;

 private short fogbrush[][]={
 {0,0,1,0,0},
 {0,1,1,1,0},
 {1,1,1,1,1},
 {0,1,1,1,0},
 {0,0,1,0,0},
 };

 private short map[][]={
 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1},
 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,2,0,1,1,1,1,1,1},
 {1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,1,1,0,0,0,2,2,2,0,0,0,0,1,1,1},
 {1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,2,2,2,0,0,0,1,1,1},
 {1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,1,1},
 {1,1,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,1},
 {1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
 {1,1,1,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
 {1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,0,1},
 {1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,1,1},
 {1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1},
 {1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1},
 {1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1},
 {1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1},
 {1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
 {1,1,1,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
 {1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
 {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
 {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
 {1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,1},
 {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
 {1,1,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
 {1,1,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,1,1},
 {1,0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,1,1},
 {2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
 {2,2,2,2,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
 {1,1,1,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,1},
 {1,1,1,1,1,1,0,0,0,0,0,1,0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,1,1},
 {1,1,1,1,1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,1,1},
 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
 };
    // Here I have stored a sprite that will be drawn onto the screen.
 // Note : you have to switch the x and y in the create sprite part to get
 // the right sprite view since the layout of array data has switched x and y view.
 private short tree1[][]={
       {0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0},
       {0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0},
       {0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0},
       {0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
       {0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
       {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
       {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
       {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
       {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
       {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
       {0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
       {0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0},
       {0,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0}
       };
 private short mountain1[][]={
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,3,3,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,3,3,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,3,3,3,3,0,0,0,0,0,0},
       {0,0,0,0,0,0,3,3,3,3,0,0,0,0,0,0},
       {0,0,0,0,0,3,3,3,3,3,3,0,0,0,0,0},
       {0,0,0,0,0,3,3,3,3,3,3,0,0,0,0,0},
       {0,0,0,0,3,3,3,3,3,3,3,3,0,0,0,0},
       {0,0,0,0,3,3,3,3,3,3,3,3,0,0,0,0},
       {0,0,0,3,3,3,3,3,3,3,3,3,3,0,0,0},
       {0,0,0,3,3,3,3,3,3,3,3,3,3,0,0,0},
       {0,0,3,3,3,3,3,3,3,3,3,3,3,3,0,0},
       {0,0,3,3,3,3,3,3,3,3,3,3,3,3,0,0},
       {0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0},
       {0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0},
       {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
       };

 private short ground1[][]={
       {4,4,4,4,5,5,4,4,4,4,4,4,5,4,4,4},
       {4,5,4,4,4,4,4,4,4,4,4,4,5,5,4,4},
       {4,4,5,4,4,4,4,4,4,4,4,4,5,5,4,4},
       {4,4,5,5,5,5,4,4,4,4,4,4,4,5,5,4},
       {4,4,5,5,5,5,4,4,4,5,4,4,4,4,5,4},
       {5,4,4,4,5,5,4,4,4,5,4,4,4,4,4,5},
       {5,4,4,4,4,4,4,4,4,5,4,4,4,4,4,4},
       {4,4,4,4,5,4,4,4,4,5,5,4,4,4,4,4},
       {4,4,4,4,4,5,4,4,4,5,5,5,4,4,4,4},
       {4,4,4,4,4,4,4,4,4,5,5,5,5,4,4,4},
       {4,4,5,4,4,4,4,4,4,4,5,5,5,4,4,4},
       {4,4,5,5,4,4,4,4,4,4,5,5,5,5,4,4},
       {4,5,5,5,4,4,4,4,5,4,4,5,5,5,4,4},
       {4,5,5,5,5,5,4,4,5,5,4,4,5,5,4,4},
       {4,4,4,4,5,5,5,4,4,4,4,4,4,5,4,4},
       {4,4,4,4,4,5,5,5,4,4,4,4,5,4,4,4},
       };

 int playerx;
 int playery;
 short[][] fogmap = new short[16][10];

     public void init(){
        setBackground(Color.black);
        offscreen = createImage(getSize().width,getSize().height);
        bufferGraphics = offscreen.getGraphics();

   image2 = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
    Graphics test1 = image2.getGraphics();
      for( int y = 0 ; y < 16 ; y++ ){
       for ( int x = 0 ; x < 16 ; x++ ){
    test1.setColor(getcolor(tree1[x][y]));
        test1.fillRect(y,x,1,1);
       }
      }
   image3 = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
    Graphics test2 = image3.getGraphics();
      for( int y = 0 ; y < 16 ; y++ ){
       for ( int x = 0 ; x < 16 ; x++ ){
    test2.setColor(getcolor(mountain1[x][y]));
        test2.fillRect(y,x,1,1);
       }
      }

   image4 = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
    Graphics test3 = image4.getGraphics();
      for( int y = 0 ; y < 16 ; y++ ){
       for ( int x = 0 ; x < 16 ; x++ ){
    test3.setColor(getcolor(ground1[x][y]));
        test3.fillRect(y,x,1,1);
       }
      }

  playerx = 16 / 2;
  playery = 10 / 2;
  unfog();
  new Thread(this).start();

     }

    public void run() {
        for(;;) { // animation loop never ends
         repaint();
         try {
             Thread.sleep(10);
             }
             catch (InterruptedException e) {
             }
     }
    }

 public Color getcolor(int c){
  if (c ==  0 ) return new Color(0,0,0,0);
  if (c ==  1 ) return new Color(0,240,0,255);
  if (c ==  2 ) return new Color(200,100,0,255);
  if (c ==  3 ) return new Color(200,200,200,255);
  if (c ==  4 ) return new Color(30,200,10,255);
  if (c ==  5 ) return new Color(50,220,20,255);
  return new Color(0,0,0,0);
 }

     public void update(Graphics g){
     bufferGraphics.clearRect(0,0,getSize().width,getSize().height);
     bufferGraphics.setColor(Color.red);
        bufferGraphics.drawString("Fog of War Example",10,10);
        bufferGraphics.drawString("Use w/s/a/d to move - r to reset",10,230);
        for( int y = 0 ; y < 10 ; y++){
         for( int x = 0 ; x < 16 ; x++){
          if (fogmap[x][y] == 1 ) {
           bufferGraphics.drawImage(image4,32+x*16,32+y*16,this);
          }
         }
        }

    int r1 = 0;
        for( int y = 0 ; y < 10 ; y++){
         for( int x = 0 ; x < 16 ; x++){
    if (map[y][x] == 1 && fogmap[x][y] == 1 ) {
       bufferGraphics.drawImage(image2,32+x*16,32+y*16,this);
      }
      if (map[y][x] == 2 && fogmap[x][y] == 1 ){
       bufferGraphics.drawImage(image3,32+x*16,32+y*16,this);
      }
         }
        }
      bufferGraphics.setColor(Color.white);
        bufferGraphics.fillRect(playerx * 16 , playery * 16 , 16 , 16);

        g.drawImage(offscreen,0,0,this);
     }

  public boolean keyDown (Event e, int key){

    if( key == 119 ) // w key
        {
        }
        if(key == 97) // a key
        {
        }
        if( key == 100 ) // d key
        {
        }
        if( key == 115 ) // s key
        {
        }


        System.out.println (" Integer Value: " + key);

   return true;
  }

 public void unfog(){
  for ( int y = 0 ; y < 5 ; y++){
  for ( int x = 0 ; x < 5 ; x++){
  if (fogbrush[x][y] == 1){
   if ( playerx - x > -1 && playerx - x < 16 ){
   if ( playery - y > -1 && playery - y < 10 ){
    fogmap[playerx - x][playery - y] = 1;
   }
   }
  }
  }
  }
 }

 public boolean keyUp (Event e, int key){
    if( key == 119 ) // w key
        {
         if( playery > 2 ) playery--;
         unfog();
        }
        if( key == 97 ) // a key
        {
         if( playerx > 2 ) playerx--;
         unfog();
        }
        if( key == 100 ) // d key
        {
         if( playerx < 17 ) playerx++;
         unfog();
        }
        if( key == 115 ) // s key
        {
         if( playery < 11 ) playery++;
   unfog();
        }
  if ( key == 114 ) // r key
  {
   // reset the fogmap
   for(int y = 0 ; y < 10 ; y++)
   {
    for ( int x = 0 ; x < 16 ; x++)
    {
     fogmap[x][y] = 0;
    }
   }
   unfog();
  }

  return true;
 }


 }



donderdag 22 december 2011

This weekend - and steam sale

I think I will be programming this weekend. I think I will make the fog of war example and maybe other things that I have had on a list.

I have been playing a lot of games recently. There is a steam end of year things sale and I bought the quake pack and the Unreal pack and the game gta san andreas. I have been playing some quake 1 online and was totally humiliated. I could stay alive for a couple of seconds before I was fragged. I played quake 1 in the 90's and got pretty good at it but now I play on a notepad and this is harder.

I also have been thinking on a game example while I was lying on my bed. The game Rampage, I want to keep the example simple and short so I have been going though the features.

I am cooking at the moment. The patatoes are not done yet. I am eating peas, goulash and patatoes. This is what I eat a lot. It is cheap and done pretty quickly. I am saving money for next december so I can buy a new notepad. This time I will buy a more expensive model. I think I will pay up to 800 euro's for a notepad then. As long as it has a big hard disk.

zondag 4 december 2011

Not that much activity

I have not been coding a lot the last couple of weeks. I made something in another language but that was about it. I do think about what I want to code but never sit and make something. I have been looking through the Java ebook I bought to learn things.
Some ideas that I had I have written down for if I feel like coding again. I have been playing games and surfing news and programming sites. I wonder if I will get that motivation to code again. I have been sleeping a lot the last months to.

Starfield example



I was looking through sourcecode and found code that made a starfield. It was using the build in java points. I copied / retyped the code from the source and made my own starfield example. It is only a one speed per star example.

 


import java.awt.*;
import java.applet.*;

public class StarField01 extends Applet implements Runnable{

 int         numStars;
 Point[]     stars;
 Graphics     bufferGraphics;
    Image      offscreen;


 public void init() {
  setBackground(Color.black);
     numStars = 100;
     stars = new Point[numStars];
     for (int i = 0; i < numStars; i++)
       stars[i] = new Point((int) (Math.random() * getSize().width), (int) (Math.random() * getSize().height));
    offscreen = createImage(getSize().width,getSize().height);
     bufferGraphics = offscreen.getGraphics();
  new Thread(this).start();

 }

    public void run() {
     for(;;) { // animation loop never ends
         repaint();
         try {
                for (int i = 0; i < numStars; i++)
                {
                 stars[i].x -= 1;
                 if (stars[i].x < 0) stars[i].x = getSize().width;
                }

             Thread.sleep(10);
             }
             catch (InterruptedException e) {
             }
     }
    }

    public void update(Graphics g){
     bufferGraphics.clearRect(0,0,getSize().width,getSize().width);
        bufferGraphics.setColor(Color.red);
        bufferGraphics.drawString("Starfield Example.",20,30);
      bufferGraphics.setColor(Color.white);
      for (int i = 0; i < numStars; i++)
        bufferGraphics.drawLine(stars[i].x, stars[i].y, stars[i].x, stars[i].y);

      g.drawImage(offscreen,0,0,this);
    }


}

MathRandom


Math.Random() gives you a random floating point number. If you place (int) before it then it rounds the number to a integer value. To get a number above one then you must multiply the Math.Random() times a value.

 


import java.awt.*;
import java.applet.*;

public class MathRandom extends Applet {

 public void init() {
 }

 public void paint(Graphics g) {

  g.drawString("Math random example",50,40);
  g.drawString("(int)(Math.Random() * 100) = "+(int)(Math.random()*100), 50, 60 );

 }
}


CurrentTimeMilliseconds


I could not remember it so I decided to make a little example of it. currentTimeMillis() returns the milliseconds time to you. If I remember it correctly it gives the time passed since 1972 or so.


 


import java.awt.*;
import java.applet.*;

public class CurrentTimeMilliseconds01 extends Applet {

 public void init() {
 }

 public void paint(Graphics g) {
  g.drawString("Getting the milliseconds.",20,40);
  g.drawString("System.currentTimeMillis() : " + System.currentTimeMillis(), 20, 60 );

 }
}