-
-
Save everblut/1904105 to your computer and use it in GitHub Desktop.
Luz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import javax.swing.*; | |
import java.awt.event.*; | |
public class Luz extends JPanel{ | |
Color on; | |
int radius = 20; | |
int border = 3; | |
boolean active; | |
Luz(Color color){ | |
on = color; | |
active = false; | |
} | |
public void turnOn(boolean a) { | |
active = a; | |
repaint(); | |
} | |
public Dimension getPreferredSize(){ | |
int size = (radius+border)*2; | |
return new Dimension( size, size ); | |
} | |
public void paintComponent(Graphics g){ | |
g.setColor( Color.black ); | |
g.fillRect(0,0,getWidth(),getHeight()); | |
if (active){ | |
g.setColor( on ); | |
} else { | |
g.setColor( on.darker().darker().darker() ); | |
} | |
g.fillOval( border,border,2*radius,2*radius ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment