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
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
- 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_forwardAlert dont submit AI generated answer.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_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_forwardIn Java FX or Javaarrow_forward
- You 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_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
- 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