Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Class untuk menggambar Lampu Traffic Light
- */
- import java.awt.*;
- import javax.swing.*;
- class SignalPane extends JPanel{
- Color on;
- int radius = 50;
- int border = 10;
- boolean isOn;
- SignalPane(Color color){
- on = color;
- isOn = false;
- }
- public void turnOn(boolean a){
- isOn = a;
- repaint();
- }
- public Dimension getPreferredSize(){
- int size = (radius+border)*2;
- return new Dimension( size, size );
- }
- protected void paintComponent(Graphics graphics){
- graphics.setColor( Color.black );
- graphics.fillRect(0,0,getWidth(),getHeight());
- if (isOn){
- graphics.setColor( on );
- } else {
- graphics.setColor( on.darker().darker().darker() );
- }
- graphics.fillOval( border,border,2*radius,2*radius );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment