Starting Out with Java: Early Objects (6th Edition)
Starting Out with Java: Early Objects (6th Edition)
6th Edition
ISBN: 9780134462011
Author: Tony Gaddis
Publisher: PEARSON
Expert Solution & Answer
Book Icon
Chapter 11, Problem 13AW

Explanation of Solution

Event handler:

  • The event handler is nothing but an object that responds to the events.
  • A particular method in the event handler is called if an event source is connected to the event handler. The object of the event is passed as the argument to that method.
    • This process is known as event firing.
  • The event handler class should implement the “EventHandler” interface.
    • This interface is in the package “javafx.event”.

Algorithm to register an instance of the class with “myButton” control using lambda expression:

Step 1: Register the event handler for the button using “setOnAction ()” method.

Step 2: Inside this, set the text for the label as “Hello World”.

Statement to register an instance of the class with “myButton” control using lambda expression:

//Register the event handler

myButton.setOnAction(event ->

{

//Set the text

outputLabel.setText("Hello World");

});

Example program:

The statement to register the event handler for “myButton” is highlighted.

//Import required packages

import javafx.application.Application;

import javafx.geometry.Pos;

import javafx.geometry.Insets;

import javafx.stage.Stage;

import javafx.scene.Scene;

import javafx.scene.layout.VBox;

import javafx.scene.control.Label;

import javafx.scene.control.Button;

//Declare the main class

public class Example extends Application

{

//Declare the main method

public static void main(String[] args)

{

// Launch the application...

Blurred answer
Students have asked these similar questions
In this Assignment we will build a simple graphical application that is responsive and that uses basic widgets and demonstrates event handling. The screen shot below shows the expected result In this Assignment we will build a simple graphical application that is responsive and that uses basic widgets and demonstrates event handling. The screen shot below shows the expected result You must not use any other library except tkinter. Your code must run on a standard machine. Your code must be written as a class that inherits from Tk and the application must resize gracefully. The apps must start in a usable state i.e. all the relevant values of the input widget must be set. So if you click ok when the app starts, then you should get the pop-up message shown in the last page. The reset button must set the app to the initial start state.  Widget must align vertically as well as horizontally with their matching widget   Application not designed as a class. Application not responsive: The…
DescriptionIn this assignment, you are required to implement an electronic programming quiz system. User can createquestions and preview the quiz.Your TaskYou are asked to write a Java program for the programming quiz system. There are two types of questions:Multiple Choice Question and Ture/False Question. User can create questions using the system; andpreview the quiz, which display all questions in the system one by one. During the preview, the user canattempt the quiz by entering his/her answers to questions. The system will then immediately check theanswer and calculate. After attempting all questions, the total score will be displayed. A sample run of theprogram is shown as below (Green text refers to user input):  Please choose (c)reate a question, (p)review or (e)xit >> cEnter the type of question (MC or TF) >> MCEnter the question text >> Each primitive type in Java has a correspondingclass contained in the java.lang package. These classes are called…
Create an application in Java that uses card layout with three cards. The first card - a login card - should have two text fields, one for username and other for password. There are two users - Bob and Fred - whose passwords are "mubby and "goolag" respectively. If Bob logs in, switch to a card - the bob card - that has a text field, a text area and two buttons. If the first button is pressed, get the text from the text field and append it to the text area. If the second button is pressed, return to the login card. If Fred logs in, switch to a card - the fred card - that has three buttons. If the first button is pressed, change the background color to green. If the second  button is pressed, change the background color to red. If the third button is pressed, return to login card.

Chapter 11 Solutions

Starting Out with Java: Early Objects (6th Edition)

Ch. 11.2 - What is the purpose of the launch method of the...Ch. 11.2 - What is the purpose of the Application classs...Ch. 11.2 - The program in Code Listing 12-1 calls a Stage...Ch. 11.2 - Prob. 11.14CPCh. 11.3 - What is the general difference between an HBox...Ch. 11.3 - Prob. 11.16CPCh. 11.3 - Prob. 11.17CPCh. 11.3 - How do you change the alignment of an HBox...Ch. 11.3 - Prob. 11.19CPCh. 11.4 - Prob. 11.20CPCh. 11.4 - Prob. 11.21CPCh. 11.4 - Prob. 11.22CPCh. 11.4 - Prob. 11.23CPCh. 11.4 - Prob. 11.24CPCh. 11.5 - Prob. 11.25CPCh. 11.5 - Prob. 11.26CPCh. 11.5 - Prob. 11.27CPCh. 11.5 - Prob. 11.28CPCh. 11.6 - Prob. 11.29CPCh. 11.6 - Prob. 11.30CPCh. 11.6 - Prob. 11.31CPCh. 11.6 - Prob. 11.32CPCh. 11.7 - In what package is the TextField class?Ch. 11.7 - Prob. 11.34CPCh. 11.8 - Prob. 11.35CPCh. 11.9 - Prob. 11.36CPCh. 11.9 - Prob. 11.37CPCh. 11 - Prob. 1MCCh. 11 - This type of control appears as a rectangular...Ch. 11 - Typically, when the user clicks this type of...Ch. 11 - Prob. 4MCCh. 11 - Prob. 5MCCh. 11 - Prob. 6MCCh. 11 - Prob. 7MCCh. 11 - All JavaFX applications must extend the class. a....Ch. 11 - This container arranges its contents in a single,...Ch. 11 - Prob. 10MCCh. 11 - You use this class to actually display an image....Ch. 11 - The EventHandler interface specifies a method...Ch. 11 - Prob. 13MCCh. 11 - Prob. 14MCCh. 11 - Prob. 15TFCh. 11 - Prob. 16TFCh. 11 - Prob. 17TFCh. 11 - Prob. 18TFCh. 11 - Prob. 1FTECh. 11 - Prob. 2FTECh. 11 - Assume hbox is an HBox container: // This code has...Ch. 11 - Prob. 4FTECh. 11 - Prob. 5FTECh. 11 - Prob. 1AWCh. 11 - Prob. 2AWCh. 11 - Prob. 3AWCh. 11 - Prob. 4AWCh. 11 - Prob. 5AWCh. 11 - Prob. 6AWCh. 11 - Prob. 7AWCh. 11 - Prob. 8AWCh. 11 - Prob. 9AWCh. 11 - Prob. 10AWCh. 11 - Prob. 11AWCh. 11 - Prob. 12AWCh. 11 - Prob. 13AWCh. 11 - Assume borderPane is the name of an existing...Ch. 11 - Prob. 1SACh. 11 - What is the purpose of the Application classs...Ch. 11 - What is the purpose of the Application classs...Ch. 11 - Prob. 4SACh. 11 - Prob. 5SACh. 11 - What two classes do you use to display an image?Ch. 11 - Prob. 7SACh. 11 - Prob. 8SACh. 11 - Prob. 9SACh. 11 - Prob. 10SACh. 11 - Prob. 11SACh. 11 - Latin Translator Look at the following list of...Ch. 11 - Name Formatter Create a JavaFX application that...Ch. 11 - Tip, Tax, and Total Create a JavaFX application...Ch. 11 - Property Tax A county collects property taxes on...Ch. 11 - Prob. 5PCCh. 11 - Prob. 6PCCh. 11 - Travel Expenses Create a GUI application that...Ch. 11 - Joes Automotive Joes Automotive performs the...Ch. 11 - Tic-Tac-Toe Simulator Create a JavaFX application...Ch. 11 - Prob. 10PC
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning