'How to connect JavaFX login UI to game
I built a working login/signup interface with a DBUtil class, I attach a pic of my Java classes:
Project Setup:

Now I want it to load a game, for example a map of hexagons like this : https://github.com/j-koreth/MapEditor How should I set it up in my classes?
When I login I have an .fxml file with a BEGIN button in it, which changes the window into a new scene which would be the game. I was thinking of putting the main of the MapEditor into the controller of the game scene, which is PartitaController but it doesn't feel right and doesn't boot. What would be the best way? I think It needs another class to load the game rather than put the mapgenerator main into the controller.
My Game controller code in JavaFX is
package com.example.loginsignup;
import javafx.embed.swing.SwingFXUtils;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.stage.FileChooser;
import javax.imageio.ImageIO;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
public class PartitaController implements Initializable {
@FXML
private Button button_signout;
@FXML
private Button bt_attack;
@FXML
private Button bt_defend;
@FXML
private Button bt_market;
@FXML
private Button bt_begin;
@FXML
private ImageView mappa;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
button_signout.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
DBUtil.changeScene(actionEvent, "sample.fxml", "Log in!", null);
}
});
/*** Cambiamento pagina in MERCATO
*
*/
bt_market.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
DBUtil.changeScene(actionEvent, "market.fxml", "items", null);
}
});
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
