import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Main extends JFrame{
JLabel la=new JLabel("0");
JLabel la2=new JLabel("0");
JLabel la3=new JLabel("0");
JLabel la4=new JLabel("시작합니다.");
Container c;
public Main() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
c=getContentPane();
c.setLayout(null);
// int -> String
la.setSize(20, 20);
la2.setSize(20,20);
la3.setSize(20, 20);
la4.setSize(100,20);
Font font=new Font("Serif", Font.BOLD, 30);
la.setLocation(100,100);
la2.setLocation(200,100);
la3.setLocation(300, 100);
la4.setLocation(150, 200);
c.add(la3);
c.add(la2);
c.add(la);
c.add(la4);
c.addKeyListener(new MyKeyListener());
c.setFocusable(true);
c.requestFocus();
setSize(400,400);
setVisible(true);
}
class MyKeyListener extends KeyAdapter{
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()!=KeyEvent.VK_ENTER) { return ;}
int x=0, y=0, z=0;
x=(int)(Math.random()*10);
y=(int)(Math.random()*10);
z=(int)(Math.random()*10);
la.setText(Integer.toString(x));
la2.setText(Integer.toString(y));
la3.setText(Integer.toString(z));
c.repaint();
c.revalidate();
System.out.println(x+" "+y+" "+z);
try {
Thread.sleep(300);
}catch
(InterruptedException ee) {
ee.printStackTrace();
}
x=(int)(Math.random()*10);
y=(int)(Math.random()*10);
z=(int)(Math.random()*10);
la.setText(Integer.toString(x));
la2.setText(Integer.toString(y));
la3.setText(Integer.toString(z));
c.repaint();
c.revalidate();
System.out.println(x+" "+y+" "+z);
try {
Thread.sleep(300);
}catch
(InterruptedException ee) {
ee.printStackTrace();
}
if(x==y&&y==z) {
la4.setText("축하드립니다.");
}
else {
la4.setText("아쉽군요.");
}
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
public class Main {
}
*/
/***************************** teacher ver.
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class MyLabel extends JLabel{
int x;
public MyLabel(Container c) {
c.add(this);
this.setVisible(true);
for(int i=0;i<10;i++) {
x=(int)(Math.random()*10);
this.setText(Integer.toString(x));
System.out.println(x);
try {
Thread.sleep(300);
}catch
(InterruptedException ee) {
ee.printStackTrace();
}
}
}
}
public class Main extends JFrame{
Container c;
public Main() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
c=getContentPane();
c.setLayout(new FlowLayout());
c.addKeyListener(new MyKeyListener());
c.setFocusable(true);
c.requestFocus();
setSize(400,400);
setVisible(true);
}
class MyKeyListener extends KeyAdapter{
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()!=KeyEvent.VK_ENTER) { return ;}
MyLabel ml = new MyLabel(getContentPane());
}
}
public static void main(String[] args) {
}
}
**************/