/* * This project is an applet to draw a face * and put the date, time and comment on an * HTML page. Project completed 10/29/97. * * Written by Bill Richardson. */ import java.applet.Applet; import java.util.*; import java.awt.*; public class FaceTime extends Applet { int a; //day of the week 0 to 6 int b; // month 0 to 11 int c; // day number of the month int y; // year minus 1900 int h; // hour 0-23 int newHour; // adjust to regular time int min; // minutes int sec; // seconds int day; int newy; // adjsts to y2k String ampm; //identify AM or PM String newSec; // creates filler 0 when needed String s; // Day of the week String month; // month String newMin; // create filler 0 when needed Date d; Image im; public void init() { im=createImage(size().width, size().height); d=new Date(); a=d.getDay(); b=d.getMonth(); c=d.getDate(); y=d.getYear(); h=d.getHours(); min=d.getMinutes(); sec=d.getSeconds(); newy=y+1900; if (sec<10) newSec="0"; else newSec=""; if (min<10) newMin="0"; else newMin=""; if (h>11) { newHour=h-12; ampm=" PM"; } else { newHour=h; ampm=" AM"; } if (a==0) day=10; else day=a; if (b==0) month="January"; if (b==1) month="February"; if (b==2) month="March"; if (b==3) month="April"; if (b==4) month="May"; if (b==5) month="June"; if (b==6) month="July"; if (b==7) month="August"; if (b==8) month="September"; if (b==9) month="October"; if (b==10) month="November"; if (b==11) month="December"; } public void paint(Graphics g) { g.setColor(Color.white); g.fillRect(0, 0, size().width, size().height); g.setFont(new Font("TimesRoman",Font.BOLD+Font.ITALIC,17)); g.setColor(Color.yellow); g.fillOval(10,5,100,100); g.setColor(Color.black); g.fillOval(30,35,20,20); g.fillOval(70,35,20,20); g.drawOval(10,5,100,100); g.drawString("The time is "+ newHour+":"+newMin+min+":"+newSec+sec+ampm,120,60); if (day==10) { s="Sunday"; g.drawArc(25,20,70,70,-30,-120); //best smile g.setColor(Color.orange); g.drawOval(20,1,80,8); g.setColor(Color.yellow); g.drawOval(21,2,80,8); g.setColor(Color.orange); g.drawOval(22,3,80,8); g.setColor(Color.black); g.drawString("Today is "+s+", "+month + " " +c+", 19"+y,120,40); g.drawString("Enjoy the last of the weekend",120,80); } else if (day==1) { s="Monday"; g.setColor(Color.yellow); g.fillOval(20,14,38,38); g.fillOval(60,14,38,38); g.setColor(Color.black); g.drawArc(25,65,70,70,30,120); //best frown g.drawString("Oh no!, it's Monday again",120,80); g.drawString("Today is "+s+", "+month + " " +c+", " + newy,120,40); } else if (day==2) { s="Tuesday"; g.setColor(Color.yellow); g.fillOval(25,14,30,30); g.fillOval(65,14,30,30); g.setColor(Color.black); g.drawArc(30,70,60,45,30,120); //best frown g.drawString("Today is "+s+", "+month + " " +c+", "+ newy,120,40); g.drawString("Tuesday is not much better than Monday.",120,80); } else if (day==3) { s="Wednesday"; g.setColor(Color.yellow); g.fillOval(30,20,20,20); g.fillOval(70,20,20,20); g.setColor(Color.black); g.drawArc(25,75,70,10,30,120); //best frown g.drawString("Today is "+s+", "+month + " " +c+", "+newy,120,40); g.drawString("Wednesday is halfway there.",120,80); } else if (day==4) { s="Thursday"; g.setColor(Color.yellow); g.fillOval(32,22,16,16); g.fillOval(72,22,16,16); g.setColor(Color.black); g.drawArc(25,58,70,20,-30,-120); //best frown g.drawString("Today is "+s+", "+month + " " +c+", "+newy,120,40); g.drawString("Thursday, we're getting there.",120,80); } else if (day==5) { s="Friday"; g.drawArc(25,20,70,70,-30,-120); //best smile g.drawString("Today is "+s+", "+month + " " +c+", "+newy,120,40); g.drawString("Friday is here at last!",120,80); } else if (day==6) { s="Saturday"; g.drawArc(25,20,70,70,-30,-120); //best smile g.drawString("Today is "+s+", "+month + " " +c+", "+newy,120,40); g.drawString("Saturday is couch potato day!",120,80); } //repaint(); } }