Package view

Class ConnectionController

java.lang.Object
view.ConnectionController

public class ConnectionController extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
    The ConnectionController function is the controller for the ConnectionView.fxml file, which allows users to choose a dictionary from a list of dictionaries and connect to it.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    The Back function is used to return the user to the main menu.
    void
    The checkOrCreateCalculationServer function checks if the calculation server is running.
    void
    The connectToServer function is called when the user clicks on the "Connect" button.
    void
    The loadGuestForm function is used to load the GuestPage.fxml file, which contains the GUI for a guest user.
    void
    The loadHomePage function is used to load the HomePage.fxml file into the main window of our application.
    void
    The loadHostForm function is called when the user clicks on the "Host" button.
    void
    loadScene(String sceneName)
    The loadScene function is used to load a new scene into the stage.
    void
    The loadWaitingHostRoom function loads the WaitingHostRoom scene.
    void
    The setViewSharedData function is used to set the viewSharedData variable.
    void
    The StartAsGuest function is called when the user clicks on the "Start as Guest" button.
    void
    The StartAsHost function is called when the user clicks on the "Start as Host" button.
    void
    The StartGame function is called when the user clicks on the "Start Game" button.
    boolean
    The validIp function takes a string as an argument and returns true if the string is a valid IP address.
    boolean
    The validName function checks to see if the name entered by the user is valid.
    boolean
    The validPort function checks to see if the port number is valid.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ConnectionController

      public ConnectionController()
      The ConnectionController function is the controller for the ConnectionView.fxml file, which allows users to choose a dictionary from a list of dictionaries and connect to it. The function also contains an event handler that handles when the user clicks on "Connect" in order to connect them with their chosen dictionary. It also has an event handler that handles when the user clicks on "Cancel" in order to cancel out of this view and return back to MainMenuView.fxml without connecting with any dictionary at all (i.e., they will not be able to play any games). This function
  • Method Details

    • setViewSharedData

      public void setViewSharedData(ViewSharedData viewSharedData)
      The setViewSharedData function is used to set the viewSharedData variable.
      Parameters:
      viewSharedData - viewSharedData Set the viewSharedData variable to the value of the parameter
    • StartAsHost

      public void StartAsHost() throws IOException
      The StartAsHost function is called when the user clicks on the "Start as Host" button. It checks if all the fields are valid, and if they are it initializes a host server with the port number that was entered by the user. It then connects to this server and loads up a waiting room for other players to join in on. If any of these fields were invalid, an error message will be displayed next to them.
      Throws:
      IOException
    • checkOrCreateCalculationServer

      public void checkOrCreateCalculationServer()
      The checkOrCreateCalculationServer function checks if the calculation server is running. If it isn't, then it creates a new calculation server and starts it.
    • StartAsGuest

      public void StartAsGuest() throws IOException
      The StartAsGuest function is called when the user clicks on the "Start as Guest" button. It checks if all the fields are valid, and if they are it connects to a server and loads a new scene where it waits for a host to start the game. If any of them aren't valid, then an error message appears next to that field.
      Throws:
      IOException
    • connectToServer

      public void connectToServer()
      The connectToServer function is called when the user clicks on the "Connect" button. It takes in a String ip, an int port, and a String name from their respective text fields. It then creates a new Client object with those parameters and sets it as the playerClient in viewSharedData. Then it creates a new GameModelReceiver object with those parameters and sets that as gameModelReceiver in viewSharedData.
    • validPort

      public boolean validPort(String port)
      The validPort function checks to see if the port number is valid.
      Parameters:
      port - port Check if the port number is valid
      Returns:
      A boolean value
    • validIp

      public boolean validIp(String ip)
      The validIp function takes a string as an argument and returns true if the string is a valid IP address.
      Parameters:
      ip - ip Check if the ip address is valid
      Returns:
      True if the input string is a valid ip address
    • validName

      public boolean validName(String name)
      The validName function checks to see if the name entered by the user is valid.
      Parameters:
      name - name Check if the name is valid
      Returns:
      True if the name parameter is a valid name
    • loadScene

      public void loadScene(String sceneName) throws IOException
      The loadScene function is used to load a new scene into the stage. It takes in a string that represents the name of the scene to be loaded, and then loads it. The function also initializes all controllers for each page, and sets their viewSharedData variable to this class's viewSharedData variable.
      Parameters:
      sceneName - sceneName Load the corresponding fxml file
      Throws:
      IOException
    • Back

      public void Back() throws IOException
      The Back function is used to return the user to the main menu.
      Throws:
      IOException
    • StartGame

      public void StartGame() throws IOException
      The StartGame function is called when the user clicks on the "Start Game" button. It loads a new scene, which is defined in StartGame.fxml and controlled by StartGameController.
      Throws:
      IOException
    • loadHostForm

      public void loadHostForm() throws IOException
      The loadHostForm function is called when the user clicks on the "Host" button. It loads a new scene, which is the HostPage.fxml file, and sets it as the current scene.
      Throws:
      IOException
    • loadHomePage

      public void loadHomePage() throws IOException
      The loadHomePage function is used to load the HomePage.fxml file into the main window of our application. This function is called when a user clicks on the "Home" button in our application's menu bar, and it will display all the information that we have stored about each student in our database. It also allows us to add new students, edit existing students' information, or delete any student from our database entirely.
      Throws:
      IOException
    • loadGuestForm

      public void loadGuestForm() throws IOException
      The loadGuestForm function is used to load the GuestPage.fxml file, which contains the GUI for a guest user. This function is called when a guest user clicks on the "Guest" button in the LoginPage.fxml file, and it loads up all of their information into an object that can be passed around throughout this program's various GUIs and controllers so that they can access their data at any time without having to re-enter it again.
      Throws:
      IOException
    • loadWaitingHostRoom

      public void loadWaitingHostRoom() throws IOException
      The loadWaitingHostRoom function loads the WaitingHostRoom scene.
      Throws:
      IOException