Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.  
  2. /**
  3.  * Jam digital dengan blueJ.
  4.  *
  5.  * @author (Ghannie Wijaya)
  6.  * @version (1.0)
  7.  */
  8. import java.awt.Font;  
  9.  import java.awt.Color;  
  10.  import java.awt.GridLayout;  
  11.  import java.awt.event.ActionEvent;  
  12.  import java.awt.event.ActionListener;  
  13.  import javax.swing.JFrame;  
  14.  import javax.swing.JLabel;  
  15.  import javax.swing.Timer;  
  16.  import javax.swing.SwingConstants;  
  17.  import java.util.*;  
  18.  import java.text.*;  
  19.  class ClockLabel extends JLabel implements ActionListener {  
  20.   String type;  
  21.   SimpleDateFormat sdf;  
  22.   public ClockLabel(String type) {  
  23.    this.type = type;  
  24.    setForeground(Color.blue);  
  25.    switch (type) {  
  26.     case "time" : sdf = new SimpleDateFormat("hh:mm:ss a");  
  27.            setFont(new Font("sans-serif", Font.PLAIN, 40));  
  28.            setHorizontalAlignment(SwingConstants.CENTER);  
  29.            break;  
  30.     case "day"  : sdf = new SimpleDateFormat("EEEE  ");
  31.            setFont(new Font("sans-serif", Font.PLAIN, 16));
  32.            setHorizontalAlignment(SwingConstants.RIGHT);
  33.            break;
  34.     default     : sdf = new SimpleDateFormat();  
  35.             break;  
  36.    }  
  37.    Timer t = new Timer(1000, this);  
  38.    t.start();  
  39.   }  
  40.   public void actionPerformed(ActionEvent ae) {  
  41.    Date d = new Date();  
  42.    setText(sdf.format(d));  
  43.   }  
  44.  }