Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA program plz help you will create a JavaFX GUI that represents the streets o

ID: 3776404 • Letter: J

Question

JAVA program plz help

you will create a JavaFX GUI that represents the streets of Pamplona. You do not need to consult an actual map of Pamplona, although you may if you want to.

Do the styling (coding of the details of the appearance of the GUI, such as colors and font sizes) using CSS, not the JavaFX setters, wherever possible. Make the start and finish squares appear different from other squares.

Grading for this lab will heavily weight the appearance of the GUI as well as its functionality. To get a good grade on this assignment, your GUI must both work correctly and look good.

Here are some of the classes you will need. This is not a complete list, and each class will need more than the basics I specify below:

A Coordinate class with an int row, an int column, and a char representing the value of the coordinate (this week, you will use four values for the Coordinates: blank (' ') for an empty space, W for a wall, S for the starting point, and E for the exit.) Provide getters and setters.

A StreetMap class with a two-dimensional array of Coordinates but no GUI code.

A JavaFX GUI class called MazeGUIPane. Since the constructor for Scene takes a Pane as a parameter, this class should extend one of the Pane classes, most likely BorderPane. It should also contain a GridPane with a two-dimensional grid of Labels. One label in the GridPane corresponds to one Coordinate in the StreetMap. Note this important distinction: the MazeGUIPane is for the the user interface while the StreetMap is for data.

The outer edges of the grid should consist of walls, except for one starting square and one exit square. When the game starts, squares that are not on the edges should be randomly set to wall and space squares (use about 20% walls.) Note that this does not guarantee that it is possible to escape the bulls at all; if you are troubled by this, see the note below. Also, you may want to make sure that the few squares nearest the start square are all empty space rather than assigning them random values.

Clicking on a label that is not on the edge of the board toggles the label between wall and empty space. The event handling code must update the StreetMap when the squares toggle. It must also change the css class of the Label in order to change its appearance.

You will also need a game reset button. You do not need to make the button work yet. In my solution, this button is in an HBox contained in the MazeGUIPane.

Map of Pamplona Run

Explanation / Answer

MazeGuiPane.java

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class MazeGuiPane extends Application {
private GridPane grid = new GridPane();
private BorderPane border = new BorderPane();
private Scene sc = new Scene(border);
public Label[][] labelGridArray = new Label[20][20];
private StreetMap map = new StreetMap();
int col;
int row;

public void start(Stage primary) {

sc.getStylesheets().add("style.css");
grid.getStyleClass().add("grid-style");
border.getStyleClass().add("border-style");
Label mainTitle = new Label("Map Of Pamplona");
mainTitle.getStyleClass().add("white-text");
Button butt = new Button("RUN!");
VBox vBox = new VBox();
HBox buttHBox = new HBox();
HBox titleBox = new HBox();
VBox titleVBox = new VBox();
VBox buttVBox = new VBox();

map.makeGrid();

for (col = 0; col < 20; col++) {
for (row = 0; row < 20; row++) {
Label square = new Label();
if (map.gridArray[col][row].getValue() == ' '){
square.getStyleClass().add("default-box");
}
else if(map.gridArray[col][row].getValue() == 'S') {
square.setText("Start");
square.getStyleClass().add("start-end");
}
else if(map.gridArray[col][row].getValue() == 'E') {
square.setText("End");
square.getStyleClass().add("start-end");
}
else {
square.getStyleClass().add("wall");
}
// System.out.println(map.gridArray[col][row]);
// System.out.println("label: " + labelGridArray[col][row] );

square.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent t) {
row = grid.getRowIndex(square);
col = grid.getColumnIndex(square);
if(map.gridArray[col][row].getValue() == 'W'){
square.getStyleClass().removeAll("wall");
square.getStyleClass().add("default-box");
map.gridArray[col][row].setTier(row); map.gridArray[col][row].setColumn(col); map.gridArray[col][row].setValue(' ');
}
else {
square.getStyleClass().removeAll("default-box");
square.getStyleClass().add("wall");
map.gridArray[col][row].setTier(row); map.gridArray[col][row].setColumn(col); map.gridArray[col][row].setValue('W');
}
}
});

labelGridArray[col][row] = square;
grid.add(square, col, row);
}
}
titleBox.getStyleClass().add("title");
titleBox.getChildren().add(mainTitle);
titleVBox.getChildren().add(titleBox);

buttHBox.getStyleClass().add("button-style");
buttHBox.getChildren().add(butt);
buttVBox.getChildren().add(buttHBox);

vBox.getChildren().add(grid);

border.setTop((titleBox));
border.setCenter(vBox);
border.setBottom(buttVBox);


primary.setScene(sc);
primary.show();
}


public static void main (String[] args) {
launch(args);
}}

=========================================================

Coordinate.java

==================================================================

StreetMap.java

==================================================================

style.css