{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

SimpleClock - timer = new Timer/TimerTask 0-start...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 import javax.swing.JFrame import java.util.* //import java.text.* import java.awt.* public class SimpleClock extends TimerTask { final static long MillSecondsPerSecond = 1000 private JFrame window private Container cont private Timer timer private String clockFace public SimpleClock() { window = new JFrame("Clock") window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) window.setSize(200,60) cont = window.getContentPane() cont.setBackground(Color.white) window.setVisible(true) clockFace = ""
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: timer = new Timer() //TimerTask, 0-start immediately, every second timer.schedule(this, 0, 1*MillSecondsPerSecond) // schedule method works with TimerTask, not Thread object. } public void run() { Date time = new Date() Graphics g = cont.getGraphics() //delete the previous time g.setColor(Color.white) g.drawString(clockFace, 10, 20) //get a new time and draw it clockFace = time.toString() g.setColor(Color.blue) g.drawString(clockFace, 10, 20) } }...
View Full Document

{[ snackBarMessage ]}