document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.  /**  
  2.   * Class untuk menggambar Lampu Traffic Light  
  3.   */  
  4.  import java.awt.*;  
  5.  import javax.swing.*;  
  6.  class SignalPane extends JPanel{  
  7.    Color on;  
  8.    int radius = 50;  
  9.    int border = 10;  
  10.    boolean isOn;  
  11.    SignalPane(Color color){  
  12.      on = color;  
  13.      isOn = false;  
  14.    }  
  15.    public void turnOn(boolean a){  
  16.      isOn = a;  
  17.      repaint();    
  18.    }  
  19.    public Dimension getPreferredSize(){  
  20.      int size = (radius+border)*2;  
  21.      return new Dimension( size, size );  
  22.    }  
  23.    protected void paintComponent(Graphics graphics){  
  24.      graphics.setColor( Color.black );  
  25.      graphics.fillRect(0,0,getWidth(),getHeight());  
  26.      if (isOn){  
  27.        graphics.setColor( on );  
  28.      } else {  
  29.        graphics.setColor( on.darker().darker().darker() );  
  30.      }  
  31.      graphics.fillOval( border,border,2*radius,2*radius );  
  32.    }  
  33.  }
');