TicTacToeClient.java (3222B)
1 /* 2 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 */ 4 package com.groupproject.tictactoeclient; 5 6 import com.formdev.flatlaf.FlatDarkLaf; 7 import com.groupproject.tictactoeclient.ContentPanes.CustomPanel; 8 import com.groupproject.tictactoeclient.ContentPanes.MainContentPanel; 9 import com.groupproject.tictactoeclient.ContentPanes.StartPanel; 10 import com.groupproject.tictactoeclient.ContentPanes.register; 11 import com.tttws.TicTacToeWS; 12 import com.tttws.TicTacToeWebService; 13 import javax.swing.JFrame; 14 import javax.swing.JOptionPane; 15 import javax.swing.JPanel; 16 import javax.swing.UIManager; 17 import javax.swing.UnsupportedLookAndFeelException; 18 19 /** 20 * 21 * @author William 22 */ 23 public class TicTacToeClient { 24 25 private static TicTacToeClient client; 26 private static TicTacToeWebService service; 27 public static TicTacToeWS proxy; 28 public JFrame frame; 29 private CustomPanel CurrentPanel; 30 public String UID = ""; 31 public String GID = ""; 32 public boolean OPPONENTS_TURN = true; 33 public int NUM_OF_MOVES = 0; 34 public String GID_Temp; 35 public String HOST_UID = ""; 36 public String username; 37 public String openGames; 38 public int[][] BOARD; 39 40 public static void main(String[] args) { 41 // Enable flatlaf dark theme 42 try { 43 UIManager.setLookAndFeel(new FlatDarkLaf()); 44 } catch (UnsupportedLookAndFeelException e) { 45 JOptionPane.showMessageDialog( 46 null, 47 "Could not initialize FlatLaf. Default swing look and feel will be used.", 48 "Error", 49 JOptionPane.ERROR_MESSAGE 50 ); 51 } 52 53 // Initialize SOAP interface 54 service = new TicTacToeWebService(); 55 proxy = service.getTicTacToeWSPort(); 56 57 // Initalize UI 58 client = new TicTacToeClient(); 59 } 60 61 public TicTacToeClient() { 62 frame = new JFrame("TicTacToe"); // Create new Swing window 63 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 64 frame.setSize(600, 400); 65 //showPanel(new register(this)); 66 showPanel(new StartPanel(this)); 67 68 frame.setVisible(true); 69 70 Thread t1 = new Thread(new PollingThread(this)); 71 t1.start(); 72 } 73 74 public void showPanel(CustomPanel panel) { 75 frame.getContentPane().removeAll(); // Clear current content 76 CurrentPanel = panel; 77 frame.getContentPane().add(panel); // Add new panel 78 frame.revalidate(); // Refresh the frame 79 frame.repaint(); 80 } 81 82 public void refreshCurrentPanel() { 83 CurrentPanel.refresh(); 84 } 85 86 //reset the game data when user goes back to the main menu so the previous game doesnt show up and user can create a new game 87 public void resetGame() { 88 this.BOARD = null; 89 this.GID = ""; 90 this.HOST_UID = ""; 91 this.NUM_OF_MOVES = 0; 92 93 refreshCurrentPanel(); 94 } 95 96 //used to log the user out and remove their user details 97 public void logout() { 98 this.UID = null; 99 this.GID = ""; 100 this.HOST_UID = ""; 101 this.NUM_OF_MOVES = 0; 102 this.BOARD = new int[2][2]; 103 104 } 105 106 }