mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
2b3a972ed5
- Fixed bug where an invalid port number would crash the program - Closed the stage before cleaning up resources. This speeds up closing the app. - Added error handling for when the client looses connection to the server. Tags: #story[1281]
71 lines
2.3 KiB
Java
71 lines
2.3 KiB
Java
package seng302.visualiser.controllers.dialogs;
|
|
|
|
import com.jfoenix.controls.JFXButton;
|
|
import com.jfoenix.controls.JFXSlider;
|
|
import com.jfoenix.controls.JFXTextField;
|
|
import com.jfoenix.validation.RequiredFieldValidator;
|
|
import java.net.URL;
|
|
import java.util.ResourceBundle;
|
|
import javafx.application.Platform;
|
|
import javafx.fxml.FXML;
|
|
import javafx.fxml.Initializable;
|
|
import javafx.scene.control.Label;
|
|
import javafx.scene.input.MouseEvent;
|
|
import seng302.gameServer.ServerDescription;
|
|
import seng302.utilities.Sounds;
|
|
import seng302.visualiser.controllers.ViewManager;
|
|
import seng302.visualiser.validators.FieldLengthValidator;
|
|
import seng302.visualiser.validators.ValidationTools;
|
|
|
|
public class DirectConnectController implements Initializable {
|
|
|
|
//--------FXML BEGIN--------//
|
|
@FXML
|
|
private JFXTextField serverAddress;
|
|
@FXML
|
|
private JFXTextField portNumber;
|
|
@FXML
|
|
private JFXButton submitBtn;
|
|
//---------FXML END---------//
|
|
|
|
public void initialize(URL location, ResourceBundle resources) {
|
|
FieldLengthValidator fieldLengthValidator = new FieldLengthValidator(40);
|
|
fieldLengthValidator.setMessage("Too long.");
|
|
|
|
RequiredFieldValidator fieldRequiredValidator = new RequiredFieldValidator();
|
|
fieldRequiredValidator.setMessage("Required.");
|
|
|
|
serverAddress.setValidators(fieldLengthValidator, fieldRequiredValidator);
|
|
portNumber.setValidators(fieldLengthValidator, fieldRequiredValidator);
|
|
|
|
submitBtn.setOnMouseReleased(event -> {
|
|
Sounds.playButtonClick();
|
|
connectToServer();
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
* connects to the server
|
|
*/
|
|
private void connectToServer() {
|
|
//TODO fix port number validation
|
|
|
|
try{
|
|
Integer.parseInt(portNumber.getText());
|
|
}
|
|
catch (NumberFormatException e){
|
|
ViewManager.getInstance().showErrorSnackBar("You need to enter a valid port number");
|
|
return;
|
|
}
|
|
|
|
ViewManager.getInstance().getGameClient()
|
|
.runAsClient(serverAddress.getText(), Integer.parseInt(portNumber.getText()));
|
|
}
|
|
|
|
public void playButtonHoverSound(MouseEvent mouseEvent) {
|
|
Sounds.playHoverSound();
|
|
}
|
|
|
|
}
|