package Views; /* * SWView.java * This file contains a Digital Display of a Stopwatch2 * Created on February 9, 2002 * * @author Stuart Hansen * @version */ import javax.swing.*; import java.awt.*; import java.awt.event.*; // The DigitalDisplay display's the watch's time in a textField public class DigitalDisplay extends SWView { private JTextField display; // the digital display // The constructor public DigitalDisplay () { super("Digital Display"); display = new JTextField("00:00:0"); display.setEditable(false); display.setBounds(110, 25, 55, 30); getContentPane().add(display); setSize(300, 100); show(); } // setDisplayTime has to translate the parameter to a string // and place it in the textField protected void setDisplayTime (long timeArg) { long displayTime = timeArg; String minutes = Long.toString((displayTime/600)%60); if ((displayTime/600)%60 < 10) minutes = "0"+ minutes; String seconds = Long.toString((displayTime/10%60)); if ((displayTime/10%60) < 10) seconds = "0" + seconds; String tenths = Long.toString(displayTime%10); display.setText( minutes + ":" + seconds + ":" + tenths); } }