Created
July 22, 2009 03:15
-
-
Save atnan/151772 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 java.awt.event.*; | |
public class FullScreen extends java.applet.Applet { | |
private Label label; | |
private Window window; | |
private boolean running; | |
private int clicks; | |
private String[] messages = new String[] { | |
"Scary, uh?", | |
"So you want me to go away...", | |
"You know I don't have to, but...", | |
"I'll be nice, just click me one more time :)" | |
}; | |
public synchronized void start() { | |
window = new Window(new Frame()); | |
label = new Label("PWND"); | |
label.setFont(new Font("Serif", Font.BOLD, 120)); | |
label.setAlignment(label.CENTER); | |
label.setForeground(Color.white); | |
label.addMouseListener(new MouseAdapter() { | |
public void mouseClicked(MouseEvent me) { | |
clicked(); | |
} | |
}); | |
label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); | |
window.setBackground(Color.black); | |
window.setLayout(new BorderLayout()); | |
window.add(label, BorderLayout.CENTER); | |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); | |
window.setBounds(0, -128, screenSize.width, screenSize.height + 256); | |
window.setVisible(true); | |
running = true; | |
new Thread() { | |
public void run() { | |
while(isRunning()) { | |
try { | |
EventQueue.invokeAndWait(toFront); | |
sleep(10); | |
} catch(Exception exception) { | |
exception.printStackTrace(); | |
return; | |
} | |
} | |
} | |
}.start(); | |
try { | |
window.setAlwaysOnTop(true); | |
} catch(Throwable t) { | |
// it was just an attempt, we know this should be forbidden to Applets | |
} | |
} | |
private Runnable toFront = new Runnable() { | |
public void run() { | |
window.toFront(); | |
} | |
}; | |
private synchronized boolean isRunning() { | |
return running; | |
} | |
private synchronized void clicked() { | |
if(clicks >= messages.length) { | |
running = false; | |
window.dispose(); | |
return; | |
} | |
if(clicks == 1) { | |
label.setFont(new Font("Serif", Font.BOLD, 40)); | |
} | |
label.setText(messages[clicks++]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment