/*
import java.awt.*;
import javax.swing.*;
class TimerThread extends Thread {
int n = 0;
private JLabel timerLabel;
public TimerThread(JLabel timerLabel,int n) {
this.timerLabel = timerLabel;
this.n=n;
}
public void run() {
while (true) {
timerLabel.setText(Integer.toString(n));
n+=2;
try {
Thread.sleep(1000);
}
catch(InterruptedException e) {
return;
}
}
}
}
public class Main extends JFrame {
public Main() {
setTitle("에제13-1");
Container c = getContentPane();
c.setLayout(new FlowLayout());
JLabel timerLabel1 = new JLabel();
timerLabel1.setFont(new Font("Gothic",Font.ITALIC,80));
c.add(timerLabel1);
JLabel timerLabel2 = new JLabel();
timerLabel2.setFont(new Font("Gothic",Font.ITALIC,80));
c.add(timerLabel2);
TimerThread th1 = new TimerThread(timerLabel1,0);
TimerThread th2 = new TimerThread(timerLabel2,1);
setSize(300,170);
setVisible(true);
th1.start();
th2.start();
}
public static void main(String[] args) {
new Main();
}
}
import java.awt.*;
import javax.swing.*;
class TimerRunnable implements Runnable {
int n=0;
private JLabel timerLabel;
public TimerRunnable(JLabel timerLabel,int n) {
this.timerLabel=timerLabel;
this.n=n;
}
public void run() {
while(true) {
timerLabel.setText(Integer.toString(n));
n+=2;
try {
Thread.sleep(1000);
}
catch(InterruptedException e) {
return;
}
}
}
}
public class Main extends JFrame {
public Main(){
setTitle("예제 13-2");
Container c = getContentPane();
c.setLayout(new FlowLayout());
JLabel timerLabel1 = new JLabel();
timerLabel1.setFont(new Font("Gothic",Font.ITALIC,80));
c.add(timerLabel1);
JLabel timerLabel2 = new JLabel();
timerLabel2.setFont(new Font("Gothic",Font.ITALIC,80));
c.add(timerLabel2);
TimerRunnable runnable1 = new TimerRunnable(timerLabel1,0);
TimerRunnable runnable2 = new TimerRunnable(timerLabel2,1);
Thread th1 = new Thread(runnable1);
Thread th2 = new Thread(runnable2);
setSize(250,150);
setVisible(true);
th1.start();
th2.start();
}
public static void main(String[] args) {
new Main();
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class TimerRunnable implements Runnable {
int n=0;
private JLabel timerLabel;
public TimerRunnable(JLabel timerLabel) {
this.timerLabel=timerLabel;
}
public void run() {
while(true) {
timerLabel.setText(Integer.toString(n));
n++;
try {
Thread.sleep(1000);
}
catch(InterruptedException e) {
return;
}
}
}
}
public class Main extends JFrame{
private Thread th;
JButton b = new JButton("Stop!!");
public Main() {
setTitle("예제13-5");
setSize(300,170);
setVisible(true);
Container c = getContentPane();
c.setLayout(new FlowLayout());
JLabel timerLabel= new JLabel();
timerLabel.setFont(new Font("Gothic",Font.ITALIC,80));
TimerRunnable runnable = new TimerRunnable(timerLabel);
th = new Thread (runnable);
c.add(timerLabel);
th.start();
c.add(b);
b.addActionListener(new MyActionListener());
}
class MyActionListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
th.interrupt(); // 쓰레드 종료
b.setEnabled(false); //버튼 못누르게
}
}
public static void main(String[] args) {
new Main();
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class RandomThread extends Thread {
private Container contentPane;
private boolean flag=false;
public RandomThread(Container contentPane) {
this.contentPane = contentPane;
}
public void finish() {
flag = true;
}
public void run(){
while(true) {
int x = ((int)(Math.random()*contentPane.getWidth()));
int y = ((int)(Math.random()*contentPane.getHeight()));
JLabel label = new JLabel("coding");
label.setSize(80,30);
label.setLocation(x,y);
contentPane.add(label);
contentPane.repaint();
try {
Thread.sleep(300);
if(flag==true) {
contentPane.removeAll();
label = new JLabel("finish");
label.setSize(80,30);
int x1 = ((int)(Math.random()*contentPane.getWidth()));
int y1= ((int)(Math.random()*contentPane.getHeight()));
label.setLocation(x1,y1);
label.setForeground(Color.CYAN);
contentPane.add(label);
contentPane.repaint();
return;
}
}
catch(InterruptedException e) {return; }
}
}
}
public class Main extends JFrame {
private RandomThread th;
public Main() {
setTitle("예제13-6");
Container c = getContentPane();
c.setLayout(null);
c.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
th.finish();
}
});
setSize(300,200);
setVisible(true);
th = new RandomThread(c);
th.start();
}
public static void main(String[] args) {
new Main();
}
}
public class Main {
public static void main(String [] args) {
SharedBoard board = new SharedBoard();
Thread th1 = new StudentThread("Kitae", board);
Thread th2 = new StudentThread("hyosoo", board);
th1.start();
th2.start();
}
}
class SharedBoard {
private int sum = 0;
synchronized public void add() {
int n = sum;
Thread.yield();
n += 10;
sum = n;
System.out.println(Thread.currentThread().getName()+":" + sum);
}
public int getSum() {return sum;}
}
class StudentThread extends Thread{
private SharedBoard board;
public StudentThread(String name,SharedBoard board) {
super(name);
this.board = board;
}
public void run() {
for(int i=0;i<10;i++) {
board.add();
}
}
}*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class MyLabel extends JLabel {
private int barSize = 0;
private int maxBarSize;
public void paintComponent (Graphics g) {
}
}



