/*import java.text.SimpleDateFormat;
import java.util.Date;
import java.awt.*;
import javax.swing.*;
*/
/*
class TimerThread extends Thread{
JLabel timerLabel;
public TimerThread(JLabel a) {
this.timerLabel = a;
}
public void run() {
while(true) {
Date now = new Date();
// 현재 날짜/시간 출력
// System.out.println(now);
SimpleDateFormat formatter = new SimpleDateFormat("HH시 mm분 ss초"); // 포맷팅 적용
String formatedNow = formatter.format(now); // 포맷팅 현재 날짜/시간 출력
System.out.println(formatedNow); // 2021년 06월 17일 06시 57분 32초 }}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
timerLabel.setText(formatedNow);
}
}
}
public class Main extends JFrame{
String b;
public Main(){
Container c = getContentPane();
JLabel a = new JLabel();
a.setSize(800,800);
a.setFont(new Font("Gothic",Font.ITALIC,80));
c.add(a);
a.setLocation(250, 150);
TimerThread th = new TimerThread(a);
th.start();
setLayout(null);
setVisible(true);
setSize(300,300);
}
public static void main(String[] args) {
new Main();// 현재 날짜/시간
}
}
*/
/*
import java.util.*;
import java.awt.*;
import javax.swing.*;
class TimerRunnable implements Runnable{
int n=0;
public TimerRunnable(String timerlabel) {
// TODO Auto-generated constructor stub
}
@Override
public void run() {
while(true) {
try {
if(n<10) {
Thread.sleep(1000);}
else
{
System.out.println("스레드 종료");
return ;
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
return ;
}
n++;
System.out.print(n+" ");
}
// TODO Auto-generated method stub
}
}
class Main{
private static final String timerLabel = null;
public Main() {
TimerRunnable runnable = new TimerRunnable(timerLabel);
Thread th = new Thread(runnable);
Scanner sc = new Scanner(System.in);
String a = sc.next();
if(a.equals("go")) {
System.out.println("스레드 실행 시작");
th.start();
}
}
public static void main(String[] args) {
new Main();
}
}*/
import java.util.Random;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.IOException;
import java.io.InputStream;
import javax.swing.event.*;
public class Main extends JFrame{
GamblingThread th = new GamblingThread();
int att;
int btt;
int ctt;
boolean gambling = false;
Random random = new Random();
InputStream is = Main.class.getResourceAsStream("BMJUA_ttf.ttf");
JLabel a = new JLabel("1");
JLabel b = new JLabel("2");
JLabel c = new JLabel("3");
JButton bt = new JButton("Start");
public Main() {
setTitle("Casino World Online");
Container ct = getContentPane();
ct.setBackground(Color.white);
setLayout(null);
a.setFont(new Font("배달의민족 주아", Font.PLAIN,30));
b.setFont(new Font("배달의민족 주아", Font.PLAIN,30));
c.setFont(new Font("배달의민족 주아", Font.PLAIN,30));
bt.setFont(new Font("배달의민족 주아", Font.PLAIN,30));
a.setSize(100, 100);
a.setBackground(Color.LIGHT_GRAY);
a.setOpaque(true);
a.setHorizontalAlignment(SwingConstants.CENTER);
b.setSize(100, 100);
b.setBackground(Color.LIGHT_GRAY);
b.setOpaque(true);
b.setHorizontalAlignment(SwingConstants.CENTER);
c.setSize(100, 100);
c.setBackground(Color.LIGHT_GRAY);
c.setOpaque(true);
c.setHorizontalAlignment(SwingConstants.CENTER);
a.setLocation(50, 50);
b.setLocation(210,50);
c.setLocation(370, 50);
bt.setLocation(190, 200);
bt.setSize(150, 50);
bt.addActionListener(new MyActionListener());
ct.add(a);
ct.add(b);
ct.add(c);
ct.add(bt);
setVisible(true);
setSize(553, 325);
th.start();
}
public static void main(String[] args) {
new Main();
}
class GamblingThread extends Thread{
synchronized public void waitForGambling() {
if(!gambling)
{
try {
System.out.println("waiting...");
this.wait();
} catch (InterruptedException e) {
// TODO: handle exception
return;
}
}
}
synchronized public void startGambling() {
gambling = true;
this.notify();
}
public void run() {
while(true) {
waitForGambling();
System.out.println("thread start... ");
att=random.nextInt(5);
String as = Integer.toString(att);
btt=random.nextInt(5);
String bs = Integer.toString(btt);
ctt=random.nextInt(5);
String cs = Integer.toString(ctt);
if(att == btt)
{
if(btt == ctt) {
ctt=random.nextInt(5);
cs = Integer.toString(ctt);
}
}
try {
Thread.sleep(300);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
a.setText(as);
try {
Thread.sleep(300);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
b.setText(bs);
try {
Thread.sleep(300);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
c.setText(cs);
gambling = false;
System.out.println("thread end");
bt.setEnabled(true);
}
}
}
class MyActionListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
System.out.println("click");
bt.setEnabled(false);
th.startGambling();
gambling = true;
}
}
}