-
Notifications
You must be signed in to change notification settings - Fork 2
/
YesNoWindow.java
105 lines (94 loc) · 2.27 KB
/
YesNoWindow.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* @(#)AFrame.java
*
*
* @author Justinian
* @version 1.00 2010/11/20
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
public class YesNoWindow extends JFrame implements ActionListener
{
public boolean visible;
private final Container cp;
boolean yes;
private final JButton yesButton;
private final JButton noButton;
public YesNoWindow()
{
this.setTitle("????");
this.setSize(400,100);
this.setResizable(false);
this.setLayout(null);
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.setVisible(false);
visible = false;
this.setLocationRelativeTo(null);
cp = this.getContentPane();
yes = false;
//okButton = new JButton("Ok!");
//okButton.setBounds(110,this.getHeight()-50,80,20);
//okButton.addActionListener(this);
yesButton = new JButton("Yes!");
yesButton.setBounds(100,this.getHeight()-60,80,20);
yesButton.addActionListener(this);
noButton = new JButton("No!");
noButton.setBounds(220,this.getHeight()-60,80,20);
noButton.addActionListener(this);
cp.add(yesButton);
cp.add(noButton);
}
public static void main(String[] args)
{
YesNoWindow y1 = new YesNoWindow();
y1.addMessage("Yes or No?","This is a test");
while (y1.visible)
{
try
{
Thread.sleep(15);
}
catch(Exception ignored)
{
}
}
System.out.println(y1.getYes());
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == yesButton)
{
yes = true;
this.setVisible(false);
visible = false;
Battle.confirmEvolution(true);
}
else if (e.getSource() == noButton)
{
yes = false;
this.setVisible(false);
visible = false;
Battle.confirmEvolution(false);
}
System.out.println(yes);
}
public void addMessage(String message, String message2)
{
if (!visible)
{
visible = true;
this.setVisible(true);
}
this.setTitle(message2);
JLabel j1 = new JLabel(message);
j1.setBounds(15, 5, this.getWidth() - 30, 25);
j1.setHorizontalAlignment(JLabel.CENTER);
cp.add(j1);
}
public boolean getYes()
{
return yes;
}
}