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...
Want to see the full answer?
Check out a sample textbook solutionChapter 12 Solutions
MyLab Programming with Pearson eText -- Access Code Card -- for Starting Out with Java: From Control Structures through Objects
- 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_forwardJava or Java FXarrow_forwardRead the instructions below and write your code using Microsoft Visual Studio (Community version). Build your own console application with C#. Write a Rectangle class, the private data members are the length (len) and width (wid) of the rectangle, the parameterless constructor sets len and wid to 0, and the parameterized constructor sets the value of length (len) and width (wid). In addition, the class also includes common methods such as calculating the perimeter of the rectangle, calculating the area of the rectangle, obtaining the length value of the rectangle, obtaining the width value of the rectangle, and modifying the length and width values of the rectangle to the corresponding formal parameter values. Please upload your executable C# file as attachment in the system.arrow_forward
- 6. You are writing a game's weapon-spawning system. The weapon that's spawned is completely randomized. There are a few base types of weapons, but some of these have one or more additional functions. The additional functions can apply to any of the types of weapons. Which design pattern is the most useful here? Question options: Adapter Null Object Decorator Proxyarrow_forwardIf you have a class that you can not modify its code, and you want to add features to this class, in this case which pattern to use Select one: a. Factory Method b. Decorator c. Observer d. Abstract Factoryarrow_forwardModify 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_forward
- In Java FX or Javaarrow_forwardYou have some questionable legacy code (that doesn't use interfaces) that you want to enhance, but you don't want to risk breaking other code that uses it. Which pattern would you use? Decorator Null Object O Adapter Proxyarrow_forwardYou need to design this class. It represents each food wastage entry recorded by the user through the form on the webpage (frontend). If you notice the form on the webpage, you’ll see that each FoodWastageRecord will have the following as the data members aka member variables. Date (as string) Meal (as string) Food name (as string) Quantity in ounces (as double) Wastage reason (as string) Disposal mechanism (as string) Cost (as double) Each member variable comes with its accessor/mutator functions. food_wastage_record.hpp class FoodWastageRecord { public: void SetDate(const std::string &date); void SetMeal(const std::string &meal); void SetFoodName(const std::string &food_name); void SetQuantityInOz(double qty_in_oz); void SetWastageReason(const std::string &wastage_reason); void SetDisposalMechanism(const std::string &disposal_mechanism); void SetCost(double cost); std::string Date() const; std::string Meal() const; std::string FoodName() const;…arrow_forward
- You 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_forwardin Javaarrow_forward.arrow_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