Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Declare an instance of DataManager at the FXMainPane class level so that its scope extends throughout the class. Instantiate it in the constructor. To set
- Declare an instance of DataManager at the FXMainPane class level so that its scope extends throughout the class. Instantiate it in the constructor.
- To set the buttons to respond to mouse-clicks,
- create an inner class at the class level (for example, called ButtonHandler) that implements EventHandler. For each button, use button.setOnAction(new ButtonHandler()).
- This interface requires the method handle(ActionEvent event) to be implemented. The mouse event is provided to the handle method, and event.getTarget() returns the object that caused the event, allowing a selection to be made.
- Implement an if-else-if structure that gets the target button that was selected and executes the appropriate block of code.
- If the "Hello", "Howdy" or "Chinese" buttons were selected, call the DataManager instance's methods getHello, getHowdy, or getChinese and call the text field's method setText with the response from the DataManager.
- If the "Clear" button was selected, call the text field's method setText(""); to clear out the text field.
- If the "Exit" button was selected, call Platform.exit(); and System.exit(0);
- Position the components so they are generally centered and spaced apart.
- To set margins for each component, call the static method on the containing component, e.g., HBox.setMargin(button1, inset);where inset is an instance of the class Inset.
- To center each HBox, use hBox.setAlignment(Pos.CENTER); where Pos is an Enum that will need to be imported.
- JUST FOR FUN (optional): create a sixth button that says "Hello" in another language. Add a method to the DataManager class to return the string.
- Add the files to GitHub in a directory named CMSC203_Lab2
Compile and run FXDriver. Select each of the buttons to ensure they are working correctly.
Submit the three java files to Blackboard. If any of these instructions is confusing to you, download and study the code in GUI_Template.zip in Week 4.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres a breakdown of the instructions incorporating best practices 1 Declare and Instantiate DataMan...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started