Question: Hello, I need help in the / FIXME Task 4: implement the simple placement viewer/ in a assignment that requires java. Here the instructions: You

Hello, I need help in the / FIXME Task 4: implement the simple placement viewer/ in a assignment that requires java.

Here the instructions:

You need to enhance the Viewer class so that it displays placements visually, according to strings input via the text box. To do this, you should make use of the images of the different pieces. (I did include the images but the images are already in the package)

You may wish to use the following steps:

Display images in the window (anywhere)

Display images of so that their origin is in the correct place.

Fix the makePlacement() method of the Viewer class so that it works correctly.

.....................................................................

Here the code,

package comp1110.ass2.gui;

import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.HBox; import javafx.stage.Stage;

/** * A very simple viewer for piece placements in the twist game. * * NOTE: This class is separate from your main game class. This * class does not play a game, it just illustrates various piece * placements. */ public class Viewer extends Application {

/* board layout */ private static final int SQUARE_SIZE = 60; private static final int VIEWER_WIDTH = 750; private static final int VIEWER_HEIGHT = 500;

private static final String URI_BASE = "assets/";

private final Group root = new Group(); private final Group controls = new Group(); TextField textField;

/** * Draw a placement in the window, removing any previously drawn one * * @param placement A valid placement string */ void makePlacement(String placement) { // FIXME Task 4: implement the simple placement viewer }

/** * Create a basic text field for input and a refresh button. */ private void makeControls() { Label label1 = new Label("Placement:"); textField = new TextField (); textField.setPrefWidth(300); Button button = new Button("Refresh"); button.setOnAction(new EventHandler() { @Override public void handle(ActionEvent e) { makePlacement(textField.getText()); textField.clear(); } }); HBox hb = new HBox(); hb.getChildren().addAll(label1, textField, button); hb.setSpacing(10); hb.setLayoutX(130); hb.setLayoutY(VIEWER_HEIGHT - 50); controls.getChildren().add(hb); }

@Override public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("TwistGame Viewer"); Scene scene = new Scene(root, VIEWER_WIDTH, VIEWER_HEIGHT);

root.getChildren().add(controls);

makeControls();

primaryStage.setScene(scene); primaryStage.show(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!