Created
December 2, 2017 00:01
-
-
Save dragon0/742dbeb1465ba69e98a8baaad4df25ea to your computer and use it in GitHub Desktop.
Window that changes color with the time
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 groovy.swing.SwingBuilder | |
import java.awt.BorderLayout as BL | |
import javax.swing.JFrame | |
import javax.swing.ImageIcon | |
import java.awt.Color | |
import java.awt.Graphics2D | |
import java.awt.image.BufferedImage | |
import javax.imageio.ImageIO | |
import javax.swing.SwingUtilities | |
width = 200 | |
height = 200 | |
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB) | |
g = bi.createGraphics(); | |
setColor = { | |
time = System.currentTimeMillis() | |
int rgb = time & 0xFFFFFF | |
c = new Color(rgb) | |
System.out.printf("r: %x g: %x b: %x\n", c.red, c.green, c.blue) | |
g.setPaint(c) | |
g.fillRect(0, 0, width, height) | |
imagelabel.repaint() | |
} | |
new SwingBuilder().edt { | |
frame(title: 'Frame', defaultCloseOperation: JFrame.EXIT_ON_CLOSE, size: [width, height+40], show: true) { | |
borderLayout() | |
imagelabel = label(icon: new ImageIcon(bi), constraints: BL.NORTH) | |
} | |
} | |
new Thread({ | |
while(true) { | |
SwingUtilities.invokeAndWait(setColor) | |
//Thread.sleep(1000) | |
} | |
}).start() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment