Skip to content

Instantly share code, notes, and snippets.

@yusuke
Created December 8, 2010 11:37
Show Gist options
  • Save yusuke/733169 to your computer and use it in GitHub Desktop.
Save yusuke/733169 to your computer and use it in GitHub Desktop.
カウントアップしていく
import javax.swing.*;
import java.awt.*;
public class MyFrame extends JFrame {
public static void main(String[] args) {
new MyFrame().setVisible(true);
}
JTextArea text = new JTextArea();
MyThread thread = new MyThread();
MyFrame() {
setSize(100, 100);
setLayout(new BorderLayout());
add(text, BorderLayout.CENTER);
thread.start();
}
class MyThread extends Thread {
public void run() {
int count = 0;
while (true) {
synchronized (this) {
try {
this.wait(1000);
} catch (InterruptedException ignore) {
}
}
count++;
text.append(count + "\n");
System.out.println(count);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment