Can someone help me create this coding using JavaFX? This is for my game project btw.
So there’s an arrow where if you choose level 1 it shows level 1 on the left side, but when I choose level 3 or 4 it’s gonna be the same too, arrows on the left side. I tried to code but it doesn’t work. This is my coding btw.
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
public class GameLevels extends Application {
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Game Levels");
VBox vbox = new VBox(10);
vbox.setAlignment(Pos.CENTER);
Label title = new Label("GAME LEVELS");
title.setFont(Font.font("Arial", FontWeight.BOLD, 40));
title.setTextFill(Color.WHITE);
Label[] levels = new Label[5];
for (int i = 0; i < 5; i++) {
levels[i] = new Label("LEVEL " + (i + 1));
levels[i].setFont(Font.font("Arial", FontWeight.NORMAL, 24));
levels[i].setTextFill(Color.WHITE);
levels[i].setOnMouseClicked(this::handleLevelClick);
vbox.getChildren().add(levels[i]);
}
Label back = new Label("BACK");
back.setFont(Font.font("Arial", FontWeight.NORMAL, 24));
back.setTextFill(Color.WHITE);
back.setOnMouseClicked(this::handleBackClick);
vbox.getChildren().addAll(title, levels[0], levels[1], levels[2], levels[3], levels[4], back);
Scene scene = new Scene(vbox, 400, 600);
scene.setFill(Color.BLACK);
primaryStage.setScene(scene);
primaryStage.show();
}
private void handleLevelClick(MouseEvent event) {
Label source = (Label) event.getSource();
System.out.println(source.getText() + " clicked");
}
private void handleBackClick(MouseEvent event) {
System.out.println("Back clicked");
}
public static void main(String[] args) {
launch(args);
}
}
I tried to code this but it doesn’t work, it says error JavaFX. Can someone give me the correct coding and result is the same as the picture that I put there. Thanks a lot need ASAP. 🙁