import java.awt.*; import Ticket; public class TicketHolder extends java.applet.Applet implements Runnable { private int ticket = 1; Thread runner; public void init() { Ticket.setTicket(ticket); } public void start() { if (runner == null) { runner = new Thread(this); runner.start(); } } public void stop() { if (runner != null) { runner.stop(); runner = null; } } public void run() { while (true) { if (++ticket > 100) { ticket = 1; } Ticket.setTicket(ticket); repaint(); pause(1000); } } public void pause(int time) { try { Thread.sleep(time); } catch (InterruptedException e) {} } public void paint(Graphics g) { Font font = new Font("Times Roman", Font.PLAIN, 20); FontMetrics fm = getFontMetrics(font); g.setFont(font); String s = "The ticket is set to " + ticket; int x = (this.size().width - fm.stringWidth(s)) / 2; int y = (this.size().height - fm.getHeight()) / 2; g.drawString(s, x, y); } }