This repository has been archived by the owner on Sep 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIslandView1.java
136 lines (106 loc) · 3.46 KB
/
IslandView1.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
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
/**
*
* @author Ben Kowalski
*
*/
public class IslandView1 extends JFrame implements IslandView {
private IslandController controller;
/**
* Text areas.
*/
private final JTextArea topText;
/**
* Operator and related buttons.
*/
private final JButton rod;
/**
* Default constructor.
*/
public IslandView1() {
// Create the JFrame being extended
/*
* Call the JFrame (superclass) constructor with a String parameter to
* name the window in its title bar
*/
super("Island Game");
// Set up the GUI widgets --------------------------------------------
/*
* Create widgets
*/
this.topText = new JTextArea("Open the game!", 5, 20);
this.rod = new JButton("Pull up");
// Set up the GUI widgets --------------------------------------------
/*
* Initially, the following buttons should be disabled: divide (divisor
* must not be 0) and root (root must be at least 2) -- hint: see the
* JButton method setEnabled
*/
this.rod.setEnabled(false);
/*
* Create scroll panes for the text areas in case number is long enough
* to require scrolling
*/
this.topText.setLineWrap(true);
this.topText.setEditable(false);
/*
* Create main button panel
*/
JPanel mainPanel = new JPanel(new GridLayout(2, 1));
/*
* Add the buttons to the main button panel, from left to right and top
* to bottom
*/
mainPanel.add(this.topText);
mainPanel.add(this.rod);
// Set up the observers ----------------------------------------------
/*
* Register this object as the observer for all GUI events
*/
this.rod.addActionListener(this);
/*
* Set up initial state of GUI to behave like last event was "Clear";
* currentState is not a GUI widget per se, but is needed to process
* digit button events appropriately
*/
// Set up the main application window --------------------------------
/*
* Make sure the main window is appropriately sized, exits this program
* on close, and becomes visible to the user
*/
this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
/**
* Register argument as observer/listener of this; this must be done first,
* before any other methods of this class are called.
*
* @param controller
* controller to register
*/
@Override
public void registerObserver(IslandController controller) {
this.controller = controller;
}
/**
* Update the text
*/
@Override
public void updateTextBox(String newText) {
this.topText.setText(newText);
}
@Override
public void updateRodEnabled(boolean rodStatus) {
this.rod.setEnabled(rodStatus);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}