enter image description here
Can someone help me create the code by using JavaFX same as the picture?
The arrow has to be responsive means that when I click level 1 it will show on the left side of level 1, same with the other level, if I choose level 3 it will show on the left side of level 3 as well.
I don’t really understand about JavaFX and our teacher told us to create a select level game by using JavaFX. I need someone to create a coding. 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);
vbox.getChildren().add(title);
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().add(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);
}
}
Jerry is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.