-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunWordle1.java
87 lines (71 loc) · 2.9 KB
/
RunWordle1.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
package org.gameProject.wordle1;
import java.awt.*;
import javax.swing.*;
/**
* This class sets up the top-level frame and widgets for the GUI.
*
* This game adheres to a Model-View-Controller design framework.
*
* In a Model-View-Controller framework, Game initializes the view,
* implements a bit of controller functionality through the reset
* button, and then instantiates a GameBoard. The GameBoard will
* handle the rest of the game's view and controller functionality, and
* it will instantiate a Wordle object to serve as the game's model.
*/
public class RunWordle1 implements Runnable {
public void run() {
// NOTE: the 'final' keyword denotes immutability even for local variables.
// Top-level frame in which game components live
final JFrame frame = new JFrame("Wordle");
frame.setLocation(300, 300);
// Status panel
final JPanel status_panel = new JPanel();
frame.add(status_panel, BorderLayout.SOUTH);
final JLabel status = new JLabel("Setting up...");
status_panel.add(status);
// Game board
final WordleGameBoard board = new WordleGameBoard(status);
frame.add(board, BorderLayout.CENTER);
// Control Panel
// Instructions, TextBox, Enter, Reset, Load, Save (from left to right)
final JPanel control_panel = new JPanel();
control_panel.setLayout(new GridLayout(1, 5));
frame.add(control_panel, BorderLayout.NORTH);
final JButton instructions = new JButton("Instructions");
instructions.setBackground(Color.RED);
instructions.setOpaque(true);
final JTextField textbox = new JTextField("Input word here");
final JButton enter = new JButton("Enter");
final JButton reset = new JButton("Reset");
final JButton load = new JButton("Load Game");
final JButton save = new JButton("Save Progress");
instructions.addActionListener(e -> board.openInstructions(frame));
control_panel.add(instructions);
textbox.addActionListener(e -> {
String s;
s = textbox.getText().trim();
board.setWordInBoard(s);
textbox.setText("");
});
control_panel.add(textbox);
enter.addActionListener(e -> {
String s;
s = textbox.getText().trim();
board.setWordInBoard(s);
textbox.setText("");
});
control_panel.add(enter);
reset.addActionListener(e -> board.reset());
control_panel.add(reset);
load.addActionListener(e -> board.load(frame));
control_panel.add(load);
save.addActionListener(e -> board.save(frame));
control_panel.add(save);
// Put the frame on the screen
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
// Start the game
board.reset();
}
}