Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab4.gui;
- import java.util.Observable;
- import java.util.Observer;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import lab4.client.GomokuClient;
- import lab4.data.GameGrid;
- import lab4.data.GomokuGameState;
- /*
- * The GUI class
- */
- public class GomokuGUI implements Observer{
- private GomokuClient client;
- private GomokuGameState gamestate;
- JFrame frame;
- GameGrid grid;
- GamePanel panel;
- JLabel messageLabel;
- JButton connectButton, disconnectButton, newGameButton;
- /**
- * The constructor
- *
- * @param g The game state that the GUI will visualize
- * @param c The client that is responsible for the communication
- */
- public GomokuGUI(GomokuGameState g, GomokuClient c){
- frame = new JFrame("Gomoku");
- grid = new GameGrid(15);
- panel = new GamePanel(grid);
- messageLabel = new JLabel();
- connectButton = new JButton();
- disconnectButton = new JButton();
- newGameButton = new JButton();
- this.client = c;
- this.gamestate = g;
- client.addObserver(this);
- gamestate.addObserver(this);
- }
- public void update(Observable arg0, Object arg1) {
- // Update the buttons if the connection status has changed
- if(arg0 == client){
- if(client.getConnectionStatus() == GomokuClient.UNCONNECTED){
- connectButton.setEnabled(true);
- newGameButton.setEnabled(false);
- disconnectButton.setEnabled(false);
- }else{
- connectButton.setEnabled(false);
- newGameButton.setEnabled(true);
- disconnectButton.setEnabled(true);
- }
- }
- // Update the status text if the gamestate has changed
- if(arg0 == gamestate){
- messageLabel.setText(gamestate.getMessageString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement