0% found this document useful (0 votes)
104 views23 pages

Deccan College OF Engineering and Technology

This document is a certificate for a mini project on a digital clock application created by two students. It includes an abstract, introduction, contents section, coding in Java using methods like AWT, date, string tokenizer. The coding shows how to draw digits and symbols for the clock using variables like color, size. The algorithm and coding work together to display a digital clock in an applet that runs in sync with the system time and date.

Uploaded by

Abdullah Parvez
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views23 pages

Deccan College OF Engineering and Technology

This document is a certificate for a mini project on a digital clock application created by two students. It includes an abstract, introduction, contents section, coding in Java using methods like AWT, date, string tokenizer. The coding shows how to draw digits and symbols for the clock using variables like color, size. The algorithm and coding work together to display a digital clock in an applet that runs in sync with the system time and date.

Uploaded by

Abdullah Parvez
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 23

DECCAN COLLEGE OF ENGINEERING AND TECHNOLOGY

(Established by Dar-us-salam Educational Trust) Dar-us-salam, Hyderabad500 001 A.P,India

INFORMATION TECHNOLOGY
DEPARTMENT

CERTIFICATE

Certified that this is the bonafide record of mini project work on

DIGITAL CLOCK APPLICATION


Carried out by,

M ABDULLAH PARVEZ M NAVEED ALI KHAN

160309737050 160309737051

Students of B.E. 2/4 II SEM (I.T) during the year 2011 in the partial fulfillment of the award of Bachelor of Engineering.

Signature of Incharge

INDEX

1. ABSTRACT 2. INTRODUCTION 3. REASON FOR SELECTING THE TOPIC 4. CONTENTS


a) Theory b) Algorithm c) Coding/program d) Output

5. CONCLUSION 6. REFERENCE/BIBLOGRAPHY

ABSTRACT

This project is based on applets. It is a part of java programming language. In this program we are declaring some of the methods which are based on applets. In this project, we are developing a DIGITAL CLOCK APPLICATION which is based on java programming language. After execution of program applet will be initialized and a digital clock will be displayed on the applet screen. This clock runs on the same time of the computer. Also it has the option of showing the present day. We can change the clock format from 12 hours to 24 hours and also can change the color pattern of the numbers that are being displayed in digital clock. We are using this application so that we can set the time if also system present time is not running. This program will only be executed on java platform. Besides, it is a web based application and it needs be in .html format. This is a basic digital clock in java language that works off your operating system. It works in a multithreaded environment and can be coded to any own background .This program can be used in making mobile digital clocks using the applet code. Digital clocks are widely used in day to day life.

INTRODUCTION
This project deals with applets. A java applet is an applet delivered to the users in the form of java byte code. Java applets can run in web browser using a Java Virtual Machine (JVM) or in suns applet viewer. An applet is a program written in the Java programming language that can be included in an HTML page. When we use a Java technology enabled browser to view a page that contains an applet, the applets code is transferred to the system and executed by the browsers Java Virtual Machine (JVM). In applets we two types of applets the oe is online application applets and the other is stand alone applets. We cannot use stand alone applets because applets are purely based on web-based application and needs to be in a format of .html. They can capture mouse input and also have controls like buttons or check boxes. In response to the user action an applet can change the provided graphic content. This makes applets well suitable for demonstration, visualization, and teaching. Applets are also used to create online game collections that allow players to compete against live opponents in real-time. Applet can leave the dedicated area and run as a separate window. However, applets have very little control over web page content outside the applet dedicated area, so they are less useful for improving the site in general appearance.

In this applet program we are implementing different methods for the execution of program. We are following the simple procedure in making a simple digital clock using applet coding.

Reason for selecting the topic:

Applets and Java programming language have always fascinated me very much. We can design any type of software using these platforms. As we are in the field of computer languages we need to have a thorough and in depth idea of Java. We still hope we can design any software using Java platform. This technical paper gives an opportunity to explore some of the ideas on designing a simple java application. We are looking forward to have this opportunity in further coming years.

CONTENTS:

a) Theory:
A program designed to be executed from with in another application. Unlike an application, applets cannot be executed directly from the operating system. With the growing popularity of object linking and embedding, applets are becoming more prevalent. A well-designed applet can be invoked from many different applications. Web browsers, which are often equipped with java virtual machines , can interpret applets from Web servers. Because applets are small in files size, cross-platform compatible, and highly secure(cantbe used to access users hard drives ), they are ideal for small internet applications accessible from a browser. This is a java program that can be embedded in a web page . The difference between a standard java application and a java applet is that an applet cant access system resources on the local computer. System files and serial device cannot be called or used by the applet. This is for security reasons-nobody wants their system wiped out by a malicious applet on some web site. Applets have helped mae the web more dynamic and entertaining and have given a helpful boost to the java programming language.

We shall move to applet architecture. It is different from the console-based programs. An applet waits until an event occurs. The run time system notifies the applet about an event by calling an event handler that has been provided by an applet. After this applet must take appropriate action and then quickly return. This is a crucial point. Now applet should not enter a mode of operation in which it maintains control for an extended period. Instead, it must perform specific actions in response to events and then return control to the run-time system. In applets readline() is the main input method .

The key that allows java to solve both security and portability problems just described is that the output of a java compiler is not executable code. Rather, it is a bytecode. Bytecode is a highly optimized set of instructions designed to be executed by the java run-time system, which is called the java virtual machine. Java is

the main role playing in the applets programming. The java magic behing this is bytecode which runs on Java Virtual Machine (JVM).

b) Algorithm: Algorithm can be defined as set of instructions which is followed by a specific program. In this applet programming we are using a special feature called .awt (Abstract Window Toolkit). It is javas original platform-independent feature. It involves windowing, graphics, and user-interface widget tool kit. The other method is Date. This is declared in java util package. Date is declared for using the present date of computer system in applet program. It is divided in two data types int as well as long. This class lets you manipulate dates in a system independent way. Date d = new Date( ); System.out.println(today = +d); We are using the other method called string tokenizer. It allows an application to break a string into tokens. The tokenization method is much simpler than the one used by the StreamTokenizer class. The StringTokenizer methods do not distinguish among idenitifiers , number, and quoted strings, nor do they recognize and skip comments. We can demonstrate an example below WORD- it will break into series of alpha characters. NUMBER- converts into decimal number. SYMBOL - any symbol character.

c) Coding:

import java.awt.*; import java.util.Date; import java.util.StringTokenizer; final public class DigyClockApp extends java.applet.Applet implements Runnable { volatile boolean md, over; long startTime=System.currentTimeMillis()<<1; int drawMode, countMode; Image buff; Dimension oldSz; Color fore, shad, high, low, back; int dateVSize, fontSize; private static final int font[]={ 0x3F, 0x18, 0x76, 0x7C, 0x59, 0x6D, 0x6F, 0x38, 0x7F, 0x7D }; private static final String days[]={ "Sun", "Mon", " Tue", "Wed", "Thi", "Fri", "Sat" }; public String getAppletInfo() { return "DigyClock v1.4. Author: Ivan Boldyrev <bii714@cclib.nsu.ru>\n" +"http://members.tripod.com/~ivan_mcg\t(Eng)\n" +"http://www.halyava.ru/applet\t\t(Rus)"; } final void drawDigit(Graphics gr, int n, int x, int y, int s) { drawSymbol(gr, font[n/10], x, y, s, fore, high, null,

(drawMode>>4)&0x0F); drawSymbol(gr, font[n%10], x+s+(s>>1), y, s, fore, high, null, (drawMode>>4)&0x0F); drawSymbol(gr, font[n/10]^0xFF, x, y, s, shad, null, low, (drawMode>>8)&0x0F); drawSymbol(gr, font[n%10]^0xFF, x+s+(s>>1), y, s, shad, null, low, (drawMode>>8)&0x0F); } final void drawSymbol(Graphics gr, int map, int x, int y, int h, Color n, Color hi, Color lo, int md) { int d, x2, x3; switch(drawMode & 0x0F) { default: case 0: x3=x2=x; break; case 1: d=h>>3; x2=x+d; x3=x-d; break; case 2: x3=x2=x+(h>>2); break; case 3: x3=x2=x-(h>>2); break; }

for (int count=0; map!=0; ++count, map>>=1) { gr.setColor(n); if ((map&1) != 0) switch (count) { case 0: drawVLine(gr, x2, y, x, h, hi, lo, md); break; case 1: drawVLine(gr, x, y+h, x3, h, hi, lo, md); break; case 2: drawHLine(gr, x3, y+h+h, h, hi, lo, md); break; case 3: drawVLine(gr, x+h, y+h, x3+h, h, hi, lo, md); break; case 4: drawVLine(gr, x2+h, y, x+h, h, hi, lo, md); break; case 5: drawHLine(gr, x2, y, h, hi, lo, md); break; case 6: drawHLine(gr, x, y+h, h, hi, lo, md); } } } final private void drawVLine(Graphics gr, int x1, int y, int x2, int h, Color hi, Color lo, int mode)

{ int d=h>>3; int yy=y+d, hh=h-d-d; int[] xp=new int[7], yp=new int[7]; xp[6]=xp[0]=x1; yp[6]=yp[0]=yy; xp[1]=x1-d; yp[1]=yy+d; xp[2]=x2-d; yp[2]=yy+hh-d; xp[3]=x2; yp[3]=yy+hh; xp[4]=x2+d; yp[4]=yy+hh-d; xp[5]=x1+d; yp[5]=yy+d; if (0 == mode) { gr.fillPolygon(xp, yp, 6); gr.drawLine(xp[0], yp[0], xp[3], yp[3]); } else gr.drawPolygon(xp, yp, 7); if (null != hi) { gr.setColor(hi); gr.drawLine(xp[0], yp[0], xp[1], yp[1]); gr.drawLine(xp[1], yp[1], xp[2], yp[2]); } if (null != lo) { gr.setColor(lo); gr.drawLine(xp[3], yp[3], xp[4], yp[4]); gr.drawLine(xp[4], yp[4], xp[5], yp[5]); } } final static private void drawHLine(Graphics gr, int x, int y, int w, Color hi, Color lo, int mode) { int d=w>>3;

int xx=x+d, ww=w-d-d; int[] xp=new int[7], yp=new int[7]; xp[6]=xp[0]=xx; yp[6]=yp[0]=y; xp[1]=xx+d; yp[1]=y-d; xp[2]=xx+ww-d; yp[2]=y-d; xp[3]=xx+ww; yp[3]=y; xp[4]=xx+ww-d; yp[4]=y+d; xp[5]=xx+d; yp[5]=y+d; if (0==mode) { gr.fillPolygon(xp, yp, 6); gr.drawLine(xp[0], yp[0], xp[3], yp[3]); } else gr.drawPolygon(xp, yp, 7); if (null != hi) { gr.setColor(hi); gr.drawLine(xp[0], yp[0], xp[1], yp[1]); gr.drawLine(xp[1], yp[1], xp[2], yp[2]); } if (null != lo) { gr.setColor(lo); gr.drawLine(xp[3], yp[3], xp[4], yp[4]); gr.drawLine(xp[4], yp[4], xp[5], yp[5]); } } public void start() { fore=parceColor(getParameter("FORE"), Color.green); back=parceColor(getParameter("BACK"), Color.black);

shad=parceColor(getParameter("SHAD"), darkColor(fore, back)); high=parceColor(getParameter("HIGH"), null); low=parceColor(getParameter("LOW"), null); try { drawMode=Integer.parseInt(getParameter("MODE "), 16); } catch (Exception ex) { drawMode=0; } try { fontSize=Integer.parseInt(getParameter("FONT")); } catch (Exception ex) { fontSize=20; } if (0!=fontSize) { Font f=new Font("Courier", Font.BOLD, fontSize); FontMetrics fm=getFontMetrics(f); dateVSize=10+fm.getAscent()+fm.getDescent(); setFont(f); } else dateVSize=0; String mod=getParameter("COUNTMODE"); countMode=(mod!=null && mod.length()==1) ? mod.charAt(0)-'0' : 0; over=false; (new Thread(this)).start(); }

public void run() { while (!over) { md=true; repaint(); try { Thread.sleep(1000-System.currentTimeMillis() %1000); } catch (Exception e) {} md=false; repaint(); try { Thread.sleep(650-System.currentTimeMillis() %1000); } catch (Exception e) {} } } public void stop() { over=true; } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { Dimension s=size(); int h=Math.min(s.width/12, s.height/3); Date now; switch (countMode)

{ default: case 0: now = new Date(); break; case 1: now = new Date(startTime System.currentTimeMillis()); break; } if (buff==null || s.width!=oldSz.width || s.height! =oldSz.height) { buff=null; System.gc(); buff=createImage(s.width, s.height); oldSz=s; } Graphics bGr=buff.getGraphics(); bGr.setColor(back); bGr.fillRect(0, 0, s.width, s.height); bGr.setColor(fore); if (0!=fontSize) { String day=days[now.getDay()]; if (null != high) { bGr.setColor(high); bGr.drawString(day, 9, dateVSize-6); bGr.setColor(fore); } bGr.drawString(day, 10, dateVSize-5); } bGr.translate((oldSz.width-h*9)>>1, dateVSize); drawDigit(bGr, now.getHours(), 0, h>>1, h); drawDigit(bGr, now.getMinutes(), 4*h, h>>1, h);

drawDigit(bGr, now.getSeconds(), 7*h, h, (h>>1)+ (h>>2)); bGr.setColor((md) ? fore : shad); int r=h>>2; bGr.fillOval(3*h+r, h-r, r, r); bGr.fillOval(3*h+r, (h<<1), r, r); g.drawImage(buff, 0, 0, null); bGr.dispose(); } final static private Color parceColor(String src, Color def) { if (src==null || src.length()<2) return def; try { if (src.charAt(0)=='#') return new Color(Integer.parseInt(src.substring(1), 16) | 0xFF000000); else { StringTokenizer stt=new StringTokenizer(src, " ;,"); int res=0xFF; for (int i=0; i<3; ++i) { res <<= 8; res |= Integer.parseInt(stt.nextToken()); } return new Color(res); } } catch (Exception e) { return def; } }

final static Color darkColor(Color f, Color b) { int dr=f.getRed()-b.getRed(), dg=f.getGreen()b.getGreen(), db=f.getBlue()-b.getBlue(); return new Color(b.getRed()+(dr>>2), b.getGreen()+ (dg>>2), b.getBlue()+(db>>2)); } }

Applet viewer code: <html> <head> <title>DigyClockApp</title> </head> <body> <applet code =DigyClockApp width=400 height=300> </applet> </body> </html>

EXECUTION:

d) OUTPUT:

CONCLUSION:
By doing this project, we conclude that our aim was to create or design an application which will be useful to the users who use the application. We look forward to have an opportunity in designing a project which will be related to java platform. Besides, we are also trying to step in other languages skill to design a application other java which will be useful to the users. By doing this project we learnt how to create many different applications using simple basics of applets. By learning applets, one can easily design a program for daily life applications in which we can use it in our desktops, laptops, leaptops and else.

REFERENCE:

AUTHOR: SIR IVAN BOLDYREV E-MAIL ADDRESS: http://members.tripod.com/ivan_mcg SOURCE: INTERNET // GOOGLE // APPLETS PROGRAMMING

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy