Concept explainers
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: Declare a class named “ButtonClickHandler”.
Step 2: Declare a method named “handle”.
Step 3: Set the text for “outputLabel” as “Hello World”
Event handler class:
//Event handler class
class ButtonClickHandler implements EventHandler <ActionEvent>
{
//Overrides handle class
@Override
public void handle(ActionEvent event)
{
//Set the text
outputLabel.setText("Hello World");
}
}
Example program:
The below program demonstrates the Event handler class.
//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 11 Solutions
Starting Out with Java: Early Objects (6th Edition)
- Consider the myPicture PictureBox control, which may be found in an application's user interface. By composing a statement, you may make the control invisible.arrow_forwardIn Visual Basic, when you drag a field object to an existing control in the interface, Visual Basic replaces the current control with the newly created control. True or false? a. True b. Falsearrow_forwardIn the graphical user interface of an application, MyPicture is a PictureBox control. Say that to hide the control.arrow_forward
- The following JavaFx code is called as event ________ Model Button btOK = new Button("OK"); OKHandlerClass handler = new OKHandlerClass(); btOK.setOnAction(handler); Window Display Delegation Dialogarrow_forwardTrue or False: You normally add JCheckBox components to a ButtonGroup object.arrow_forwardIf you inadvertently create a Click() method for a control that should not generate a click event, you can successfully eliminate the method by ______________. a. deleting the method code from the Form1.cs file b. eliminating the method from the Events list in the Properties window c. adding the method to the Discard window d. making the method a comment by placing two forward slashes at the start of each linearrow_forward
- Java Programming: Finish the JInsurance application that allows the user to choose insurance options in JCheckBoxes. Use a ButtonGroup to allow the user to select only one of two insurance types—HMO (health maintenance organization) or PPO (preferred provider organization). Use regular (single) JCheckBoxes for dental insurance and vision insurance options; the user can select one option, both options, or neither option. As the user selects each option, display its name and price in a text field; the HMO costs $200per month, the PPO costs $600 per month, the dental coverage adds $75 per month, and the vision care adds $20 per month. When a user deselects an item, make the text field blank. Initial Code: import java.awt.*; import javax.swing.*; import java.awt.event.*; public class JInsurance extends JFrame implements ItemListener { FlowLayout flow = new FlowLayout(); ButtonGroup insGrp = new ButtonGroup(); JCheckBox hmo = new JCheckBox("HMO", false); JCheckBox ppo = new…arrow_forwardJava Programming: Finish the JInsurance application that allows the user to choose insurance options in JCheckBoxes. Use a ButtonGroup to allow the user to select only one of two insurance types—HMO (health maintenance organization) or PPO (preferred provider organization). Use regular (single) JCheckBoxes for dental insurance and vision insurance options; the user can select one option, both options, or neither option. As the user selects each option, display its name and price in a text field; the HMO costs $200per month, the PPO costs $600 per month, the dental coverage adds $75 per month, and the vision care adds $20 per month. When a user deselects an item, make the text field blank.arrow_forwardIn Visual Basic ,Create a simple login form for your local internet café using conditional statement.Your program should ask the user to input the username and password; if the usernameand password match the system, it should display a welcome back message. But if it doesnot, then it should display the message: "wrong username or password". Use a messagebox to display the messagearrow_forward
- Write a JavaFX application that allows the user to choose insurance options. Use a ToggleGroup to allow the user to select only one of two insurance types幽MO (health maintenance organization) or PPO (preferred provider organization). Use CheckBoxes for dental insurance and vision insurance options; the user can select one option, both options, or neither option. As the user selects each option, display its name and price in a text field; the HMO costs $200 per month, the PPO costs $600 per month, the dental coverage adds $75 per month, and the vision care adds $20 per month. Save the application as FXInsurance.java.arrow_forwardproperty Tax in javaA county collects property taxes on the assessment value of property, which is 60 percent of the property’s actual value. If an acre of land is valued at $10,000, its assessment value is $6,000. The property tax is then $0.64 for each $100 of the assessment value. The tax for the acre assessed at $6,000 will be $38.40. Create a GUI application that displays the assess- ment value and property tax when a user enters the actual value of a property.arrow_forwardIt is possible that a control's runtime visibility on the form will change depending on its properties, just as with any other control.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning