EXAMPLE: FLASHING CLOCKS in Font
CHAPTER 18 EXAMPLE: FLASHING CLOCKS Paint Data Matrix ECC200 In None Using Barcode generator for Font Control to generate, create Data Matrix 2d barcode image in Font applications. www.OnBarcode.comEAN13 Generator In None Using Barcode maker for Font Control to generate, create EAN13 image in Font applications. www.OnBarcode.comImage panelmage = getPaneImage(); setPreferredSize(new Dimension(imageWidth, imageHeight)); } //////////////////////////////////////////////// // Font //////////////////////////////////////////////// private private private private private final final final final final static static static static static String DEFAULT_FONT_NAME = "Lucida Console"; int DEFAULT_TIME_FONT_SIZE = 48; int DEFAULT_DATE_FONT_SIZE = 18; int DEFAULT_SECOND_BLOCK_HEIGHT = 8; int DEFAULT_SECOND_BLOCK_FONT_SIZE = 10; Barcode Encoder In None Using Barcode creation for Font Control to generate, create Barcode image in Font applications. www.OnBarcode.comCode 39 Extended Encoder In None Using Barcode generator for Font Control to generate, create ANSI/AIM Code 39 image in Font applications. www.OnBarcode.comprivate Font timeFont = null; private Font dateFont = null; private Font secondFont = null; private Font getFont(Graphics g, int size) { Font font = new Font(DEFAULT_FONT_NAME, Font.PLAIN, size); if (font != null) return font; return g.getFont(); } private Font getTimeFont(Graphics g) { if (timeFont == null) timeFont = getFont(g, DEFAULT_TIME_FONT_SIZE); return timeFont; } private Font getDateFont(Graphics g) { if (dateFont == null) dateFont = getFont(g, DEFAULT_DATE_FONT_SIZE); return dateFont; } private Font getSecondFont(Graphics g) { if (secondFont == null) secondFont = getFont(g, DEFAULT_SECOND_BLOCK_FONT_SIZE); return secondFont; } QR-Code Generation In None Using Barcode creator for Font Control to generate, create Denso QR Bar Code image in Font applications. www.OnBarcode.comGenerating UPC-A In None Using Barcode generator for Font Control to generate, create UPC-A image in Font applications. www.OnBarcode.comCHAPTER 18 EXAMPLE: FLASHING CLOCKS
Print PDF-417 2d Barcode In None Using Barcode drawer for Font Control to generate, create PDF417 image in Font applications. www.OnBarcode.comBritish Royal Mail 4-State Customer Code Encoder In None Using Barcode printer for Font Control to generate, create Royal Mail Barcode image in Font applications. www.OnBarcode.com//////////////////////////////////////////////// // paint //////////////////////////////////////////////// private void drawClockInfo(Graphics g) { int winWidth = getWidth(); int winHeight = getHeight(); boolean valid = false; try { valid = clockDev.isValidTime(); } catch(RemoteException e) { // valid is already false } if (valid) { g.setColor(Color.BLACK); } else { if (lastBlink == Color.WHITE) { g.setColor(Color.BLACK); lastBlink = Color.BLACK; } else { g.setColor(Color.WHITE); lastBlink = Color.WHITE; } } //// Time String //// Date now = null; try { now = clockDev.getTime(); } catch(RemoteException e) { now = new Date(0); } String timeStr = dateFormat.format(now); Font timeFont = getTimeFont(g); g.setFont(timeFont); FontMetrics timeFontMetric = g.getFontMetrics(); Rectangle2D timeStrBounds = timeFontMetric.getStringBounds(timeStr, g); int int int int int timeStrWidth = (int)timeStrBounds.getWidth(); timeStrHeight = (int)timeStrBounds.getHeight(); timeStrX = (winWidth-timeStrWidth)/2; timeStrY = (winHeight+timeStrHeight)/2; timeStrOffset = timeStrHeight/8/2; java data matrix Using Barcode creation for Java Control to generate, create DataMatrix image in Java applications. java barcode reader java data matrix www.OnBarcode.comasp.net data matrix Using Barcode generator for ASP.NET Control to generate, create DataMatrix image in ASP.NET applications. asp.net data matrix www.OnBarcode.comCHAPTER 18 EXAMPLE: FLASHING CLOCKS
java pdf 417 Using Barcode maker for Java Control to generate, create PDF 417 image in Java applications. java pdf 417 www.OnBarcode.comvb.net qr code scanner Using Barcode decoder for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications. vb.net qr code scanner www.OnBarcode.comg.drawString( timeStr, timeStrX, timeStrY); //// Date String //// String dateStr = "Time"; Font dateFont = getDateFont(g); g.setFont(dateFont); FontMetrics dateFontMetric = g.getFontMetrics(); Rectangle2D dateStrBounds = dateFontMetric.getStringBounds(dateStr, g); g.drawString( dateStr, (winWidth-(int)dateStrBounds.getWidth())/2, timeStrY-timeStrHeight-timeStrOffset); } private void clear(Graphics g) { g.setColor(Color.GRAY); g.clearRect(0, 0, getWidth(), getHeight()); } Paint Barcode In Java Using Barcode drawer for Android Control to generate, create Barcode image in Android applications. www.OnBarcode.comUPC Code Printer In None Using Barcode drawer for Word Control to generate, create GS1 - 12 image in Office Word applications. www.OnBarcode.comprivate void drawPanelImage(Graphics g) { if (getPaneImage() == null) { return; } g.drawImage(getPaneImage(), 0, 0, null); } public void paint(Graphics g) { clear(g); drawPanelImage(g); drawClockInfo(g); } } asp.net pdf 417 Using Barcode maker for ASP.NET Control to generate, create PDF-417 2d barcode image in ASP.NET applications. asp.net pdf 417 www.OnBarcode.comvb.net code 39 generator open source Using Barcode generator for .NET framework Control to generate, create Code 3/9 image in Visual Studio .NET applications. vb.net code 39 generator open source www.OnBarcode.comCHAPTER 18 EXAMPLE: FLASHING CLOCKS
java ean 128 Using Barcode drawer for Java Control to generate, create EAN / UCC - 13 image in Java applications. java ean 128 www.OnBarcode.comCreating Barcode In Objective-C Using Barcode generation for iPhone Control to generate, create Barcode image in iPhone applications. www.OnBarcode.comHere s a clock frame: /** * Copyright (C) Satoshi Konno 2002-2003 * Minor changes Jan Newmarch */ package clock.clock; import clock.device.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ClockFrame extends JFrame implements Runnable, WindowListener { private final static String DEFAULT_TITLE = "Sample Clock"; private ClockDevice clockDev; private ClockPane clockPane; public ClockFrame(ClockDevice clockDev) { this(clockDev, DEFAULT_TITLE); } public ClockFrame(ClockDevice clockDev, String title) { super(title); this.clockDev = clockDev; getContentPane().setLayout(new BorderLayout()); clockPane = new ClockPane(clockDev); getContentPane().add(clockPane, BorderLayout.CENTER); addWindowListener(this); pack(); setVisible(true); } public ClockPane getClockPanel() { return clockPane; } public ClockDevice getClockDevice() { return clockDev; } //////////////////////////////////////////////// // run //////////////////////////////////////////////// ECC200 Generator In VS .NET Using Barcode generator for ASP.NET Control to generate, create Data Matrix 2d barcode image in ASP.NET applications. www.OnBarcode.comBarcode Printer In None Using Barcode creator for Software Control to generate, create Barcode image in Software applications. www.OnBarcode.comCHAPTER 18 EXAMPLE: FLASHING CLOCKS
private Thread timerThread = null; public void run() { Thread thisThread = Thread.currentThread(); while (timerThread == thisThread) { // getClockDevice().update(); getClockPanel().repaint(); try { Thread.sleep(1000); } catch(InterruptedException e) {} } } public void start() { // clockDev.start(); timerThread = new Thread(this); timerThread.start(); } public void stop() { // clockDev.stop(); timerThread = null; } //////////////////////////////////////////////// // main //////////////////////////////////////////////// public void windowActivated(WindowEvent e) { } public void windowClosed(WindowEvent e) { } public void windowClosing(WindowEvent e) { stop(); System.exit(0); } CHAPTER 18 EXAMPLE: FLASHING CLOCKS
public void windowDeactivated(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowIconified(WindowEvent e) { } public void windowOpened(WindowEvent e) { } } TickerTimer Driver
A driver for the ticker timer in the preceding frame is as follows: package clock.clock; import clock.device.*; import clock.service.*; public class TickerClock { public static void main(String args[]) { ClockDevice clockDev = new ClockDevice(); clockDev.setTimer(new TickerTimer()); ClockFrame clock; if (args.length > 0) { clock= new ClockFrame(clockDev, args[0]); } else { clock = new ClockFrame(clockDev); } clock.start(); } } This driver can be run with the following: java clock.clock.TickerClock "Ticking Clock" CHAPTER 18 EXAMPLE: FLASHING CLOCKS
ComputerTimer Driver
A driver for the computer timer in the preceding frame is as follows: package clock.clock; import clock.device.*; import clock.service.*; public class ComputerClock { public static void main(String args[]) { ClockDevice clockDev = new ClockDevice(); clockDev.setTimer(new ComputerTimer()); ClockFrame clock; if (args.length > 0) { clock= new ClockFrame(clockDev, args[0]); } else { clock = new ClockFrame(clockDev); } clock.start(); } } This driver can be run with the following: java clock.clock.ComputerClock "Computer Clock"
|
|