-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuessGUI.java
89 lines (71 loc) · 2.7 KB
/
GuessGUI.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
/**GuessGUI Class
* The GUI View for the Guess Name
* Date Created: Nov 18, 2018
* @author W. Couch
*/
import javax.swing.*;
import java.awt.*;
public class GuessGUI extends JPanel
{
//Instance Variables
private GuessGame game; //The game Model
// ** Define your GUI components here
JPanel info = new JPanel();
JPanel userGuide = new JPanel();
JPanel hintOut = new JPanel();
JTextField playerGuess = new JTextField(5);
JLabel instructions = new JLabel("");
JLabel hint = new JLabel("");
/** Default constructor for the GUI. Assigns Model and View, identifies controllers
* and draws the layout
* @param newGame The Model for the game
*/
public GuessGUI(GuessGame newGame)
{
super();
this.game = newGame;
this.game.setGUI(this);
this.layoutView();
this.registerControllers();
this.update();
}
/** Draws the initial layout for the game board
*/
private void layoutView()
{
// ** enter your code here
//Code to guide user
userGuide.setLayout (new GridLayout (4,3,0,0));
userGuide.add(instructions);
//Code to get number
info.setLayout(new GridLayout (4,3,0,0));
info.add(playerGuess);
info.setBorder(BorderFactory.createTitledBorder("Enter Guess"));
//Hint code
hintOut.setLayout (new GridLayout(2,4,0,0));
hintOut.add(hint);
//Overall layout
this.setLayout(new BorderLayout());
this.add(this.userGuide, BorderLayout.NORTH);
this.add(this.info, BorderLayout.CENTER);
this.add(this.hintOut, BorderLayout.SOUTH);
}// end of layoutView()
/**Assigns the controller to the respond guess entry.
*/
private void registerControllers()
{
//Responds to entry of a guess
GuessController controller = new GuessController(this.game, playerGuess); //assumes text box is named playerGuess
playerGuess.addActionListener(controller);
}
/** Redraws the game board according to the current game situation. Requires data
* from the Model.
*/
public void update()
{
//Sets the text for individual labels
this.instructions.setText(game.getState());
this.hint.setText(game.getHint());
playerGuess.setText("");
}//end of update()
}