Search Here

Java program for creating Sand-clock


/* Sand Clock using applet*/

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

/*
 <applet code="sand_clock" width=500 height=500>
 </applet>
*/

public class sand_clock extends Applet
{
 public void paint(Graphics g)
 {
  int xa[] = {100,200,300};
  int ya[] = {50,200,50};

  g.fillRoundRect(100,40,200,10,10,10);
  g.fillRoundRect(100,348,200,10,10,10);
  
  g.setColor(Color.gray);
  g.fillPolygon(xa,ya,3);
  int m=350;
  for(int i=50; i<=200; i++)
  {
   g.setColor(Color.white);
   g.drawLine(100,i,300,i);
   
   g.setColor(Color.gray);
   g.drawLine(200,200,200,350);
   int x[] = {100,200,300};
   int y[] = {350,m--,350};   
   g.fillPolygon(x,y,3);
   
   
   g.setColor(Color.gray);
   g.drawLine(100,50,200,200);
   g.drawLine(300,50,200,200);   
   g.drawLine(200,200,100,350);
   g.drawLine(200,200,300,350);
   

   try
   {
    Thread.sleep(200);
   }
   catch(Exception e)
   {}
  }
 }
}

No comments:

Post a Comment