The following code snippet shows how to implement an on-screen clock applet.
import java.applet.*; import java.awt.*; import java.util.*; import java.text.*; public class MyClock extends Applet { MyPanel mp; public void init() { mp = new MyPanel(getParameter("format")); add(mp); } } class MyPanel extends Panel { MyClockThread mct; Color b, f; SimpleDateFormat formatter; String previousDateText = ""; String dateText; MyPanel(String df) { super(); formatter = new SimpleDateFormat(df); validate(); setBackground(new Color(0).black); setForeground(new Color(0).yellow); b = this.getBackground(); f = this.getForeground(); mct = new MyClockThread(this); mct.start(); } public Dimension getPreferredSize() { return new Dimension (this.getFontMetrics(this.getFont()).stringWidth(getNow()) + 25, 30); } public void paint(Graphics g) { if (g != null) { g.setColor(b); g.drawString(previousDateText,10,15); g.setColor(f); dateText = get Related Tips A custom combobox editor for use with the EditableComboBox class A demonstration of Java2D transformations A game of Tic-Tac-Toe that can be played between two client applets A Label that uses inline HTML to format its text A program to print limits of the primitive types A sample of inline DTD definition A sample of linked DTD definition A sample XML file
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.