-
Notifications
You must be signed in to change notification settings - Fork 2
/
ErrorWindow.java
152 lines (126 loc) · 3.43 KB
/
ErrorWindow.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/**
* @(#)AFrame.java
*
*
* @author
* @version 1.00 2010/11/20
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextPane;
import java.net.*;
public class ErrorWindow extends JFrame implements ActionListener
{
private int aNum;
private boolean visible;
private final Container cp;
private final JButton okButton;
public ErrorWindow()
{
aNum = 0;
this.setTitle("ERROR!");
this.setSize(300,120);
this.setResizable(false);
this.setLayout(null);
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
URL iconU=JokemonDriver.class.getResource("icon.png");
Image icon=Toolkit.getDefaultToolkit().getImage(iconU);
this.setIconImage(icon);
this.setVisible(false);
visible = false;
//Gets the resolution of the screen in pixels
Toolkit toolkit=Toolkit.getDefaultToolkit();
Dimension screensize=toolkit.getScreenSize();
this.setLocation(screensize.width/2-150,screensize.height/4);
cp = this.getContentPane();
okButton = new JButton("Ok!");
okButton.setBounds(110,this.getHeight()-50,80,20);
okButton.addActionListener(this);
cp.add(okButton);
this.toFront();
}
public static void main(String[] args)
{
ErrorWindow af = new ErrorWindow();
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == okButton)
{
this.setVisible(false);
Battle.forceToFront();
visible = false;
aNum = 0;
cp.removeAll();
cp.add(okButton);
}
}
public void addMessage(String message)
{
this.setTitle("ERROR!");
if (!visible)
{
visible = true;
this.setVisible(true);
}
JLabel j1 = new JLabel(message);
int height = (25*aNum)+5;
this.setSize(300,100 + (aNum*25));
okButton.setBounds(110,this.getHeight()-50,80,20);
aNum++;
j1.setBounds(15,height,this.getWidth() - 30,25);
j1.setHorizontalAlignment(JLabel.CENTER);
cp.add(j1);
this.toFront();
}
public void addMessage(String message, String title)
{
this.setTitle(title);
if (!visible)
{
visible = true;
this.setVisible(true);
}
//JLabel j1 = new JLabel(message);
JTextPane j1=new JTextPane();
j1.setText(message);
j1.setBackground(null);
j1.setEditable(false);
j1.setBorder(null);
int height = (25*aNum)+5;
this.setSize(300,100 + (aNum*25));
okButton.setBounds(110,this.getHeight()-50,80,20);
aNum++;
j1.setBounds(15,height,this.getWidth() - 30,25+20);
cp.add(j1);
okButton.requestFocusInWindow();
this.toFront();
}
public void addLargeMessage(String message, String title)
{
this.setTitle(title);
if (!visible)
{
visible = true;
this.setVisible(true);
}
//JLabel j1 = new JLabel(message);
JTextPane j1=new JTextPane();
j1.setText(message);
j1.setBackground(null);
j1.setEditable(false);
j1.setBorder(null);
int height = (25*aNum)+5;
this.setSize(300,200 + (aNum*25));
okButton.setBounds(110,this.getHeight()-50,80,20);
aNum++;
j1.setBounds(15,height,this.getWidth() - 30,this.getHeight()-75);
cp.add(j1);
okButton.requestFocusInWindow();
this.repaint();
this.toFront();
}
}