Created
September 3, 2012 00:54
-
-
Save colin-haber/3605959 to your computer and use it in GitHub Desktop.
It's like you're installing Windows 8 all over again!
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
package com.n1nja.colour; | |
import java.awt.*; | |
import java.awt.event.*; | |
import java.awt.image.BufferedImage; | |
import javax.swing.*; | |
public class Colour implements KeyListener{ | |
public static void main(String[] args) { | |
new Colour(); | |
} | |
private JFrame window; | |
private JPanel colorPanel; | |
private JLabel notice; | |
private boolean isStarted; | |
private int maxChroma = 200; | |
private int minChroma = 50; | |
private int delay = 20; | |
private Colour() { | |
this.isStarted = false; | |
this.setup(); | |
this.start(); | |
} | |
private void setup() { | |
this.window = new JFrame("Colour"); | |
this.window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
this.window.setExtendedState(Frame.MAXIMIZED_BOTH); | |
this.window.setUndecorated(true); | |
this.window.addKeyListener(this); | |
/* | |
* Hide the cursor. | |
* From http://stackoverflow.com/a/1984117 | |
*/ | |
this.window.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB), new Point(0, 0), "blank")); | |
this.colorPanel = new JPanel(new BorderLayout()); | |
this.colorPanel.setBackground(new Color(maxChroma, minChroma, minChroma)); | |
this.notice = new JLabel("Setting up Windows"); | |
this.notice.setHorizontalAlignment(SwingConstants.CENTER); | |
this.notice.setVerticalAlignment(SwingConstants.CENTER); | |
this.notice.setFont(new Font("Segoe UI", Font.PLAIN, 42)); | |
this.notice.setForeground(Color.WHITE); | |
this.colorPanel.add(this.notice); | |
this.window.add(this.colorPanel); | |
} | |
private void start() { | |
this.isStarted = true; | |
this.window.setVisible(true); | |
new Thread(new Runnable() { | |
@Override | |
public void run() { | |
while (true) { | |
Color bg = colorPanel.getBackground(); | |
int red = bg.getRed(); | |
int green = bg.getGreen(); | |
int blue = bg.getBlue(); | |
if ((red == maxChroma) && (green < maxChroma) && (blue == minChroma)) { | |
green++; | |
} else if ((red <= maxChroma) && (red > minChroma) && (green == maxChroma)) { | |
red--; | |
} else if ((green == maxChroma) && (blue < maxChroma) && (red == minChroma)) { | |
blue++; | |
} else if ((green <= maxChroma) && (green > minChroma) && (blue == maxChroma)) { | |
green--; | |
} else if ((blue == maxChroma) && (red < maxChroma) && (green == minChroma)) { | |
red++; | |
} else if ((blue <= maxChroma) && (blue > minChroma) && (red == maxChroma)) { | |
blue--; | |
} | |
colorPanel.setBackground(new Color(red, green, blue)); | |
try { | |
Thread.sleep(delay); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
}).start(); | |
} | |
@Override | |
public void keyTyped(KeyEvent e) {} | |
@Override | |
public void keyPressed(KeyEvent e) { | |
if (this.isStarted && (e.getKeyCode() == KeyEvent.VK_ESCAPE)) { | |
System.exit(0); | |
} | |
} | |
@Override | |
public void keyReleased(KeyEvent e) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment