import java.awt.*; import java.applet.*; import java.util.Date; import java.awt.event.*; public class DigitalClockApp extends Applet implements ActionListener, Runnable { Label lbClock=new Label("000000000000"); Button b1 =new Button("Update Time"); Choice ch=new Choice(); Label lbZone=new Label("Time Zone"); Button bClose =new Button("Close"); Panel pW=new Panel(new GridLayout(2,0,10,10)); Panel pE=new Panel(new GridLayout(2,0,10,10)); Panel pC=new Panel(new FlowLayout()); Panel pS=new Panel(new FlowLayout(FlowLayout.CENTER,10,30)); Panel pN=new Panel(); Thread clock_thread; Date d=new Date(); public void init() { this.setLayout(new BorderLayout()); this.setBackground(Color.orange); ch.addItem("القدس"); ch.addItem("بغداد"); ch.addItem("GMT"); pC.add(lbClock); pS.add(lbZone); pS.add(ch); pS.add(bClose); add("South",pS); add("Center",pC); //add("West",pW); //add("East",pE); //pN.setSize(400,300); b1.addActionListener(this); bClose.addActionListener(this); lbClock.resize(300,100); lbClock.setFont(new Font("TimesRoman",Font.BOLD,48)); lbClock.setForeground(Color.orange); lbClock.setBackground(Color.black); lbZone.setForeground(Color.white); lbZone.setBackground(Color.black); bClose.setForeground(Color.white); bClose.setBackground(Color.black); //int h=d.getSeconds(); pS.setSize(200,200); //label1.setText(String.valueOf(h) +"AM"); if (clock_thread == null) { clock_thread = new Thread(this); clock_thread.start(); } } public void actionPerformed(ActionEvent e) { if(e.getSource()==b1) { lbClock.resize(100,100); d.setTime(System.currentTimeMillis()); int h=d.getSeconds(); lbClock.setText(String.valueOf(h)+"PM"); } else if(e.getSource()==bClose) { this.show(false); } } public void updateClock() { d.setTime(System.currentTimeMillis()); int timeoffest=d.getTimezoneOffset(); String pm; int h=d.getHours()+timeoffest/60; switch(ch.getSelectedIndex()) { case 0: h=h+2; break; case 1 : h=h+3; break; case 2: h=h; break; default: h=h; } if(h<12) pm="صباحاً"; else pm="مساءاً"; h=(h>12?h-12:h); h=(h==0?12:h); int s=d.getSeconds(); int m=d.getMinutes(); long t=d.getTime(); String T=(h<10? "0":"")+h+":"+(m<10? "0":"")+ m +":"+(s<10? "0":"")+s+" "+pm; lbClock.setText(T);//String.valueOf(t)+"PM"); } public void run() { while(true) { try { Thread.sleep(990); } catch (InterruptedException e) { } updateClock(); } } }