Clock Program By Applet

  • Uploaded by: Partha Gayen
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Clock Program By Applet as PDF for free.

More details

  • Words: 150
  • Pages: 2
import java.awt.*; import java.awt.event.*; import java.applet.*; public class Clock extends Applet { int i,j,x,y,ym,xm,xs,ys; Label l1,l2,l3; TextField tf1,tf2,tf3,tf4; Button b1; Panel p1,p2,p3; String hours[]={"3","4","5","6","7","8","9","10","11","12","1","2"}; String m[]={"15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","3 0","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46" ,"47","48","49","50","51","52","53","54","55","56","57","58","59","0","1","2","3", "4","5","6","7","8","9","10","11","12","13","14"}; double degree[]={0,30,60,90,120,150,180,210,240,270,300,330}; public void init() { x=425; y=350; xm=350; ym=455; xs=225; ys=350; setLayout(new BorderLayout()); p1=new Panel(); p2=new Panel(); p3=new Panel(); l1=new Label("Hour"); l1=new Label("Hour"); l2=new Label("Minutes"); l3=new Label("Second"); tf1=new TextField(15); tf2=new TextField(15); tf3=new TextField(15); tf4=new TextField(400); b1=new Button("Clock"); p1.add(l1); p1.add(tf1); p1.add(l2); p1.add(tf2); p1.add(l3); p1.add(tf3); p2.add(b1); p3.add(p1); p3.add(p2); add(p3,BorderLayout.NORTH); b1.addActionListener(new MyClass()); } class MyClass implements ActionListener { public void actionPerformed(ActionEvent ae) { for (i=0;i<12;i++) {

if(hours[i].equals(tf1.getText())) { x =350+(int)(75*Math.cos(Math.toRadians(degree[i]))); y=350+(int)(75*Math.sin(Math.toRadians(degree[i]))); repaint(); }

} for (i=0;i<60;i++) { if(m[i].equals(tf2.getText())) { int md=i*6; xm =350+(int)(105*Math.cos(Math.toRadians(md))); ym=350+(int)(105*Math.sin(Math.toRadians(md))); repaint(); } } for (i=0;i<60;i++) { if(m[i].equals(tf3.getText())) { int sd=i*6; xs =350+(int)(125*Math.cos(Math.toRadians(sd))); ys=350+(int)(125*Math.sin(Math.toRadians(sd))); repaint(); } } }

}

public void paint(Graphics g) { g.setColor(Color.magenta); for(i=0;i<12;i++) { g.drawString(hours[i],350+(int)(140*Math.cos(Math.toRadians(degree[i]))),350+(int) (140*Math.sin(Math.toRadians(degree[i])))); } g.setColor(Color.blue); g.drawOval(200,200,300,300); g.setColor(Color.red); g.drawLine(350,350,x,y); g.setColor(Color.cyan); g.drawLine(350,350,xm,ym); g.setColor(Color.green); } }

g.drawLine(350,350,xs,ys);

Related Documents

Clock
October 2019 46
Clock
November 2019 49
Athipathy Applet
April 2020 16
Applet Browser
April 2020 8
Java Applet
June 2020 2

More Documents from ""

Josephus Problem
June 2020 9
Fudcon3gbenson
June 2020 6
Chatt
June 2020 5
Client Frame
June 2020 8