Internet Systems Design:
|
Example Applets IINote: If you find that Java Applets aren't working correctly (you will usually just see a gray rectangle) on your browser, download the JRE. /* print the date */ import java.awt.Graphics; import java.awt.Font; import java.util.Date; public class DigitalThreads extends java.applet.Applet implements Runnable { Font theFont = new Font("TimesRoman",Font.BOLD,24); Date theDate; Thread runner; public void start() { if (runner == null); { runner = new Thread(this); runner.start(); } } public void stop() { runner = null; } public void run() { while (true) { theDate = new Date(); repaint(); try { Thread.sleep(1000); } catch (InterruptedException e) { } } } public void paint(Graphics g) { g.setFont(theFont); g.drawString(theDate.toString(),10,50); } }
/* swirly colors */ import java.awt.Graphics; public class ColorSwirl2 extends java.applet.Applet implements Runnable { Font f = new Font("TimesRoman",Font.BOLD,48); public void start() { public void stop() { public void run() { // cycle through the colors public void update(Graphics g) { public void paint(Graphics g) { |
|