-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScienceWindow.java
More file actions
128 lines (103 loc) · 3.13 KB
/
ScienceWindow.java
File metadata and controls
128 lines (103 loc) · 3.13 KB
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
// ScienceWindow.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
public class ScienceWindow extends JFrame
{
private CommandsPanel parent;
private JLabel num_days;
private JLabel invalid_command;
private JTextField textfield1;
private JButton okay;
private JButton close;
private String science_text;
public ScienceWindow(CommandsPanel panel)
{
parent = panel;
setLayout(new GridBagLayout());
GridBagConstraints gc = new GridBagConstraints();
num_days = new JLabel("<html><div align = \"right\">Number of days<br>to travel time:</div></html>");
num_days.setForeground(Color.WHITE);
num_days.setFont(new Font("Sans Serif", Font.PLAIN, 12));
textfield1 = new JTextField();
textfield1.setToolTipText("The number of days can be 0, positive, or negative.");
invalid_command = new JLabel("Please fill in all fields.");
invalid_command.setForeground(Color.DARK_GRAY.brighter());
invalid_command.setFont(new Font("Sans Serif", Font.BOLD, 12));
okay = new JButton("OK");
initializeButton(okay, "Click to add the time travel attempt to the commands window.");
okay.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
String param1 = textfield1.getText();
if(!param1.equals("") && param1.matches("^[+-]?\\d+$"))
{
science_text = "SCIENCE " + param1;
parent.returnText(science_text);
setVisible(false);
}
else if(!param1.equals("") && !param1.matches("^[+-]?\\d+$"))
{
invalid_command.setText("Number of days should be an integer.");
invalid_command.setForeground(new Color(255, 17, 17));
}
else
{
invalid_command.setText("Please fill in all fields.");
invalid_command.setForeground(new Color(255, 17, 17));
}
}
});
close = new JButton("Cancel");
initializeButton(close, "Click to cancel the time travel attempt.");
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
setVisible(false);
}
});
gc.weightx = 0.5;
gc.weighty = 0.5;
gc.insets = new Insets(5, 5, 5, 5); // top, left, bottom, right
gc.ipadx = 1;
gc.ipady = 5;
gc.anchor = GridBagConstraints.LINE_END;
gc.gridx = 0;
gc.gridy = 0;
add(num_days, gc);
gc.ipadx = 150;
gc.fill = GridBagConstraints.BOTH;
gc.gridx = 1;
gc.gridy = 0;
add(textfield1, gc);
gc.weighty = 0.2;
gc.ipadx = 1;
gc.fill = GridBagConstraints.BASELINE;
gc.anchor = GridBagConstraints.CENTER;
gc.gridx = 0;
gc.gridwidth = 2;
gc.gridy = 2;
add(invalid_command, gc);
gc.anchor = GridBagConstraints.PAGE_END;
gc.insets = new Insets(5, 30, 5, 30); // top, left, bottom, right
gc.gridwidth = 1;
gc.ipadx = 1;
gc.fill = GridBagConstraints.BOTH;
gc.gridx = 0;
gc.gridy = 3;
add(okay, gc);
gc.fill = GridBagConstraints.BOTH;
gc.gridx = 1;
gc.gridy = 3;
add(close, gc);
}
void initializeButton(JButton button, String text)
{
button.setBorder(new LineBorder(Color.LIGHT_GRAY, 1));
button.setBackground(new Color(40, 101, 243));
button.setForeground(Color.BLACK);
button.setToolTipText(text);
}
}