document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /**
  2.  * Kode tampilan waktu
  3.  * Kode ini dibuat untuk menampilkan visualisasi waktu yang terletak di bawah traffic light
  4.  */
  5. import java.awt.*;  
  6. import javax.swing.*;
  7.  
  8. public class DigitPane extends JPanel
  9. {
  10.     private int second;
  11.    
  12.     public Dimension getPrefereedSize()
  13.     {
  14.         FontMetrics fm = getFontMetrics(getFont());
  15.         return new Dimension(fm.stringWidth("00"), fm.getHeight());
  16.     }
  17.    
  18.     public void setValue(int newVal)
  19.     {
  20.         if (second != newVal)
  21.         {
  22.             second = newVal;
  23.             repaint();
  24.         }
  25.     }
  26.    
  27.     public int getValue()
  28.     {
  29.         return second;
  30.     }
  31.    
  32.     private String pad(int value)
  33.     {
  34.         return String.format("%02d", value);
  35.     }
  36.    
  37.     protected void paintComponent(Graphics g)
  38.     {
  39.         super.paintComponent(g);
  40.         g.setFont(new Font("LCD", Font.PLAIN, 24));
  41.         FontMetrics fm = getFontMetrics(g.getFont());
  42.         String text = pad(getValue());
  43.         int x = (getWidth() - fm.stringWidth(text)) / 2;
  44.         int y = ((getHeight() - fm.getHeight()) / 2) + fm.getAscent();
  45.         g.drawString(text, x, y);
  46.     }
  47. }
');