import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class GamblingThread extends Thread
{
JLabel la = new JLabel();
boolean gambling = false;
synchronized public void waitforGambling()
{
if(!gambling)
{
try
{
this.wait();
}
catch(InterruptedException e)
{
return;
}
}
}
synchronized public void startGambling()
{
gambling = true;
this.notify();
}
public void run()
{
while(true)
{
waitforGambling();
try
{
Thread.sleep(200);
if(gambling == true)
{
la.setText("성공");
}
else
{
la.setText("실패");
}
}
catch (InterruptedException e) {
// TODO: handle exception
return;
}
gambling = false;
}
}
}
class MyMouseListener extends MouseAdapter
{
public void mouseClicked(MouseEvent e)
{
JLabel la = (JLabel)e.getSource();
GamblingThread g = new GamblingThread();
Thread th = new Thread(g);
th.start();
}
}
public class Main extends JFrame
{
public Main()
{
setTitle("스레드가 가진 겜블링");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
setSize(1000,1000);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}