Thanks loads!
Hey I am learning core java and I cannot tell you how much
this helped me. Kudos to you! You really are a genius.
import java.awt.Color; import java.awt.Container; import java.awt.FlowLayout; import java.awt.Font; import javax.swing.JFrame; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.util.Date; import javax.swing.JLabel; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; String dateToDisplay; int hr; Date d; int hour; int minute; int second; Clock clock=new Clock(); clock.setSize(200, 80); clock.setVisible(true); try { } } clock.setResizable(false); clock.start(); } private void start() { if(timer == null) { timer.start(); } } public void stop() { timer = null; } Clock() { this.add(dateLabel); this.setTitle("Clock "); this.pack(); this.setLocationRelativeTo(null); } { hour = d.getHours(); minute = d.getMinutes(); second = d.getSeconds(); amPm=(hour<12)?"AM":"PM"; hr=(hour>12)?hour-12:hour; formatedDate=formatedDate.concat(padElement(hr, '0')); formatedDate=formatedDate.concat(":"); formatedDate=formatedDate.concat(padElement(minute, '0')); formatedDate=formatedDate.concat(":"); formatedDate=formatedDate.concat(padElement(second, '0')); formatedDate=formatedDate.concat(" "+ amPm); return formatedDate; } { // I'm just padding 2 digit numbers return(result); } public void run() { // Sleep in the timer thread... while (timer != null) { try {timer.sleep(10);} dateToDisplay=getFormatedDate(d); dateLabel.setText(dateToDisplay); } timer = null; } // TODO Auto-generated method stub } } stop(); dispose(); } } } } } }