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”.
Step 1: Register the instance of the class with “myButton” control. It is done with the help of the statement “setOnAction (new ButtonClickHandler ())”.
Statement to register an instance of the class with “myButton” control:
//Register the event handler
myButton.setOnAction(new ButtonClickHandler ());
Example program:
The statement to register the instance of the class with “myButton” control is highlighted.
//Import required packages
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
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
{
//Create a label
private Label outputLabel;
//Declare the main method
public static void main(String[] args)
{
// Launch the application.
launch(args);
}
//Override the start method
@Override
public void start(Stage primaryStage)
{
//Create a label
outputLabel = new Label();
//Create a button
Button myButton = new Button ("Click Me");
//Register the event handler
myButton...
Want to see the full answer?
Check out a sample textbook solutionChapter 11 Solutions
Starting Out with Java: Early Objects (6th Edition)
- Instructions This assignment uses the logic from the recent quiz and assignment. You can see some of that code in there.What is different? The sequence of operations, spending and finding money, is totally controllable with buttons.This makes the program very flexible. Update the Code below with the following: Add 2 new event functions: buyTortilla() and addFoundMoney(). Add 2 new buttons that trigger buyTortilla() and addFoundMoney(). STARTER CODE <!DOCTYPE html><html><head><style>p {font-family: arial; font-size: 20px;} </style></head><body> <button onclick='buyApple()'>Purchase Appple</button><button onclick='buyOrange()'>Purchase Orange</button> <!-- This marks space for a paragraph that we can update during the program --><p id="balance"></p> <script>// javascript code begin// Step 1. initialize variables:change=100 // starting balanceapple=10 // price of 1 appleorange=20 // price of 1…arrow_forwardHow does a handler interface streamline the process of handling different types of events?arrow_forwardAlert dont submit AI generated answer.arrow_forward
- Modify the Dice Poker program from this chapter to include any or all of the following features: 1- Splash Screen. When the program first fires up, have it print a short introductory message about the program and buttons for "Let's Play" and "Exit." The main interface shouldn't appear unless the user se- lects "Let's Play." 2-Add a "Help" button that pops up another window displaying the rules of the game (the payoffs table is the most important part). 3-Add a high score feature. The program should keep track of the 10 best scores. When a user quits with a good enough score, he/she is invited to type in a name for the list. The list should be printed in the splash screen when the program first runs. The high-scores list will have to be stored in a file so that it persists between program invocations.arrow_forward1. Code-Tracing - Without running / testing the following code, predict what the following program would print on the screen if you printed freeze and then boil. Write your answer in the comment section when submitting your work. For help with code-tracing see the code tracing page in this module. ments freeze - int(32) boil - int(212) freeze - 0 boil - 100 print(freeze, boil) # what would this print to the monitor? Research • Submit your answer in the comment section.arrow_forwardYou are a Chemistry major who has to create a program for first time chemistry lab users. The Erlenmeyer flask contains a nitric acid solution. When the student presses a button, 0.5 mL of NaOH solution can be added to a buret, which is set up over the Erlenmeyer flask. An indicator is added to the solution being titrated. The indicator is a substance that changes to blue when the reaction is complete (endpoint). You determine the amount of mixture that will cause this reaction to occur. Create a titration simulator that will allow a student to add up to 18 mL of titrant. Notify the student when the mixture turns blue. In Python please :)arrow_forward
- 1.In your game console class, add a start function which should prompt the user for an email address. -Use a regular expression to validate that it is a valid email address and prompt them again until they enter a valid one. -Next, prompt the user to enter a credit card number and use a regular expression to validate the credit card. -Prompt them again until they enter a valid one and once done, display the game menu. Existing Code below: class Game {constructor(name){this.name = name;}} class GameConsole{constructor(){this.games = [];} load(){var gameNames = ["Zelda", "Halo", "Mario", "The God Among Us\n"];for (var i = 0; i < gameNames.length; i++) {let game = new Game(gameNames[i]);this.games.push(game);}} log(){console.log("Games Loaded:");for (var i = 0; i < this.games.length; i++) {var name = this.games[i].name;console.log(name);}}} let gamecon = new GameConsole();gamecon.load();gamecon.log(); const prompt = require('prompt-sync')(); var adventurersName = ["Captain…arrow_forwardCarly’s Catering provides meals for parties and special events. In previous chapters, you have developed a class that holds catering event information and an application that tests the methods using four objects of the class. Now modify the Event and EventDemo classes as follows: Modify the method that sets the event number in the Event class so that if the argument passed to the method is not a four-character String that starts with a letter followed by three digits, then the event number is forced to A000. If the initial letter in the event number is not uppercase, force it to be so. Add a contact phone number field to the Event class. Add a set method for the contact phone number field in the Event class. Whether the user enters all digits or any combination of digits, spaces, dashes, dots, or parentheses for a phone number, store it as all digits. For example, if the user enters (920) 872-9182, store the phone number as 9208729182. If the user enters a number with fewer or more…arrow_forwardUsing Time as an actor is helpful to show _____. Which is correct? A. how long the Use Case takes to execute B. when you require the Use Case to be triggered at a specific point in time C. how long the interval is between Use Case executions. D. the development time for the Use Case.arrow_forward
- When you create a Handler, what method do you need to define in order for the handler to be able to manage both messages and runnables? How does that method work?arrow_forwardPlease solve in java as exactly shown in the picture. Thanksarrow_forwardPlease help with the below using java. Include getters and setters and comment where they are on the code. Please also comment the whole codearrow_forward
- New Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT