Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi everyone, hope you are well i need a help in java please. edit the following code: Adapt the Click Counter example to use FXML

Hi everyone, hope you are well i need a help in java please.

edit the following code: Adapt the Click Counter example to use FXML instead of Java for the UI coding.

**************************************************************************

package application;

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.stage.Stage;

public class ClickCounter extends Application {

private int numClicked;

@Override

public void start(Stage primaryStage) throws Exception {

BorderPane bp = new BorderPane();

bp.getStyleClass().add("grid");

GridPane gp = new GridPane();

Label clickedLabel = new Label("Buttons Clicked: ");

clickedLabel.getStyleClass().add("clickedLabel");

Label numClickedLabel = new Label("0");

numClickedLabel.getStyleClass().add("clickedLabel");

HBox clickedCounterBox = new HBox();

clickedCounterBox.getStyleClass().add("clickedBox");

clickedCounterBox.getChildren().add(clickedLabel);

clickedCounterBox.getChildren().add(numClickedLabel);

Scene sc = new Scene(bp);

sc.getStylesheets().add("styles/style.css");

numClicked = 0;

for (int rowCounter = 0; rowCounter < 10; rowCounter++)

for (int colCounter = 0; colCounter < 10; colCounter++) {

Button b = new Button("Unclicked");

b.setMinWidth(150);

b.getStyleClass().add("button");

b.setOnMouseClicked(new EventHandler() {

Boolean clicked = false;

@Override

public void handle(MouseEvent t) {

if (clicked == true) {

clicked = false;

b.setText("Unclicked");

numClicked--;

} else {

clicked = true;

b.setText("Clicked");

numClicked++;

}

numClickedLabel.setText(String.valueOf(numClicked));

}

});

gp.add(b, colCounter, rowCounter);

}

bp.setTop(clickedCounterBox);

bp.setBottom(gp);

primaryStage.setScene(sc);

primaryStage.show();

}

public static void main(String[] args) {

launch(args);

}

}

*******************************************************************************

.pane{

-fx-font-size: 250%;

-fx-padding: 20px;

}

.grid{

-fx-font-size: 200%;

}

.clickedLabel{

-fx-background-color: #00FFFF;

}

.clickedBox{

-fx-alignment: center;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions

Question

Identify the critical elements in a performance management system

Answered: 1 week ago