Skip to content

Instantly share code, notes, and snippets.

@dragon0
Created December 2, 2017 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dragon0/742dbeb1465ba69e98a8baaad4df25ea to your computer and use it in GitHub Desktop.
Save dragon0/742dbeb1465ba69e98a8baaad4df25ea to your computer and use it in GitHub Desktop.
Window that changes color with the time
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