Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi need help with this lab // This class implements a button-click counter. // You only need to complete the TO DO parts. // You

Hi need help with this lab

// This class implements a button-click counter.

// You only need to complete the "TO DO" parts.

// You don't need to worry about how the rest works.

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.stage.Stage;

import javafx.scene.layout.FlowPane;

import javafx.scene.control.Button;

import javafx.event.ActionEvent;

import javafx.event.EventHandler;

import javafx.scene.control.Label;

public class Counter extends Stage

{

// ****** TO DO: Create a private int variable here named "counter" initialized to 0

// ****** TO DO: First make this variable static and run the program, clicking on the buttons.

// ****** TO DO: Then remove the static and run the program, clicking the buttons.

// ****** EXPLAIN TO LAB ASSISTANT: Explain the different behavior when it is static vs. non-static.

public Counter()

{

FlowPane root = new FlowPane();

Button btnAddOne;

Button btnRefresh;

Label lblCounter;

lblCounter = new Label("0");

btnAddOne = new Button("Add One");

btnRefresh = new Button("Refresh");

// This code runs when the "Add One" button is clicked

btnAddOne.setOnAction(e ->

{

counter++;

lblCounter.setText(Integer.toString(counter));

}

);

// This code runs when the "Refresh" button is clicked

btnRefresh.setOnAction(e ->

{

lblCounter.setText(Integer.toString(counter));

}

);

root.getChildren().add(lblCounter);

root.getChildren().add(btnAddOne);

root.getChildren().add(btnRefresh);

Scene scene = new Scene(root, 250, 50);

setTitle("Counter");

setScene(scene);

show();

}

}

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

Step: 3

blur-text-image

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

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago