//import java.awt.*;
//import java.awt.event.*;
//import javax.swing.*;
//
//class Gamble extends Thread {
// JLabel l;
//
// public Gamble(JLabel l) {
// this.l = l;
// }
//
// public void run() {
// int n = 0;
// int count = 0;
// while (count < 30) {
// l.setText(Integer.toString(n));
// n++;
// if (n >= 10) {
// n = 0;
// }
//
// try {
// sleep(50);
// } catch (InterruptedException e) {
// return;
// }
//
// count++;
// }
//
// int ran = (int) (Math.random() * 10);
// l.setText(Integer.toString(ran));
//
//
// }
//}
//
//
//
//
//class Main extends JFrame {
// JLabel l1 = new JLabel("?");
// JLabel l2 = new JLabel("-");
// JLabel l3 = new JLabel("-");
// JLabel underl = new JLabel("시작합니다");
//
// int keyCount=0;
//
// JLabel li=new JLabel("");
//
//
// Main() {
//
// Container cp = getContentPane();
// cp.setLayout(null);
//
// cp.addKeyListener(new key());
// cp.setFocusable(true);
// cp.requestFocus();
//
// l1.setOpaque(true);
// l2.setOpaque(true);
// l3.setOpaque(true);
//
// l1.setBackground(Color.green);
// l2.setBackground(Color.green);
// l3.setBackground(Color.green);
//
// underl.setLocation(160, 90);
// underl.setSize(100, 30);
//
// l1.setSize(70, 40);
// l1.setLocation(50, 30);
// l1.setHorizontalAlignment(SwingConstants.CENTER);
//
// l2.setSize(70, 40);
// l2.setLocation(150, 30);
// l2.setHorizontalAlignment(SwingConstants.CENTER);
//
// l3.setSize(70, 40);
// l3.setLocation(250, 30);
// l3.setHorizontalAlignment(SwingConstants.CENTER);
//
// cp.add(underl);
// cp.add(l1);
// cp.add(l2);
// cp.add(l3);
//
// setSize(400, 300);
// setDefaultCloseOperation(EXIT_ON_CLOSE);
// setVisible(true);
//
//
//
//
// }
//
//
// class key implements KeyListener {
//
// public void keyTyped(KeyEvent e) {
// }
//
// public void keyPressed(KeyEvent e) {
//
// Gamble g1 = new Gamble(l1);
// Gamble g2 = new Gamble(l2);
// Gamble g3 = new Gamble(l3);
//
//
// if (e.getKeyCode() == KeyEvent.VK_ENTER) {
//
// keyCount++;
//
// if (l1.getText().equals("?")) {
// g1.start();
// l2.setText("?");
// }
//
// else if (l2.getText().equals("?")) {
// g2.start();
// l3.setText("?");
// }
//
// else if (l3.getText().equals("?")) {
// g3.start();
//
// }
//
// else if(underl.getText().equals("시작합니다")) {
// if(l1.getText().equals(l2.getText())&&l2.getText().equals(l3.getText())){
// underl.setText("축하합니다!!");
// }
// else {
// underl.setText("아쉽네요");
// }
// }
//
// else if (!(l1.getText().equals("?"))) {
// underl.setText("시작합니다");
// l1.setText("?");
// l2.setText("-");
// l3.setText("-");
// }
//
// }
//
// }
//
// public void keyReleased(KeyEvent e) {
// }
//
// }
//
// public static void main(String[] args) {
//
// new Main();
//
// }
//
//}
//////////////////////////////
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Main extends JFrame {
JLabel l1 = new JLabel("?");
JLabel l2 = new JLabel("-");
JLabel l3 = new JLabel("-");
JLabel underl = new JLabel("시작합니다");
int keyCount=0;
JLabel li=new JLabel("");
class Gamble extends Thread {
JLabel[] la;
public Gamble(JLabel a, JLabel b, JLabel c) {
la = new JLabel[3];
la[0]=a;
la[1]=b;
la[2]=c;
}
public void run() {
for(int i=0;i<3;i++) {
int n = 0;
int count = 0;
while (count < 30) {
la[i].setText(Integer.toString(n));
n++;
if (n >= 10) {
n = 0;
}
try {
sleep(50);
} catch (InterruptedException e) {
return;
}
count++;
}
int ran = (int) (Math.random() * 10);
la[i].setText(Integer.toString(ran));
}
if(la[0].getText().equals(la[1].getText()) && la[1].getText().equals(la[2].getText())){
underl.setText("축하합니다!!");
}
else {
underl.setText("아쉽네요");
}
}
}
Main() {
Container cp = getContentPane();
cp.setLayout(null);
cp.addKeyListener(new key());
cp.setFocusable(true);
cp.requestFocus();
l1.setOpaque(true);
l2.setOpaque(true);
l3.setOpaque(true);
l1.setBackground(Color.green);
l2.setBackground(Color.green);
l3.setBackground(Color.green);
underl.setLocation(160, 90);
underl.setSize(100, 30);
l1.setSize(70, 40);
l1.setLocation(50, 30);
l1.setHorizontalAlignment(SwingConstants.CENTER);
l2.setSize(70, 40);
l2.setLocation(150, 30);
l2.setHorizontalAlignment(SwingConstants.CENTER);
l3.setSize(70, 40);
l3.setLocation(250, 30);
l3.setHorizontalAlignment(SwingConstants.CENTER);
cp.add(underl);
cp.add(l1);
cp.add(l2);
cp.add(l3);
setSize(400, 300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
class key implements KeyListener {
public void keyTyped(KeyEvent e) { }
public void keyPressed(KeyEvent e) {
Gamble g = new Gamble(l1, l2, l3);
g.start();
}
public void keyReleased(KeyEvent e) { }
}
public static void main(String[] args) {
new Main();
}
}
//////////////////
/*
* class TimerThread extends Thread{ int n=0;
*
* public void run() { while(true) { System.out.println(n); n++; try {
* sleep(1000); } catch (InterruptedException e) {
*
* e.printStackTrace(); } } }
*
*
* }
*
* class Main{ public static void main(String[] args) { TimerThread th=new
* TimerThread(); th.start(); } }
*/
/*
import java.awt.; import javax.swing.*;
*
*
* class TimerThread extends Thread { private JLabel timerLabel;
*
* public TimerThread(JLabel timerJLabel) { this.timerLabel = timerJLabel; }
*
* public void run() { int n = 0; while (true) {
* timerLabel.setText(Integer.toString(n)); n++; try { Thread.sleep(0); } catch
* (InterruptedException e) { return ; } } } }
*
* public class Main extends JFrame{ public Main() {
* setTitle("Thread를 상속받은 타이머 스레드 예제"); setDefaultCloseOperation(EXIT_ON_CLOSE);
* Container c = getContentPane(); c.setLayout(new FlowLayout());
*
*
* JLabel timerLable = new JLabel(); timerLable.setFont(new Font("Gothic",
* Font.ITALIC, 80)); c.add(timerLable);
*
* TimerThread th = new TimerThread(timerLable);
*
* setSize(300,170); setVisible(true);
*
* th.start(); }
*
* public static void main(String[] args) { new Main(); } }
*/