Module [M07] - Event Driven Programming
We continue our exploration of JavaFX Application Programming Interface by learning a bit more about a style of programming that consists in triggering parts of your program based on the user's interaction with your GUI. We then leverage these techniques to play a bit with animations.
- Textbook Reading Assignments
-
The following sections of the textbook are assigned for this module.
- Chapter #15 – Event Driven Programming
Module Learning Outcomes
In this module, you will develop further your programming skills as follows;
- Tracing
- Ability to read and trace Java programs leveraging Event Driven Programming.
- Implementing
- Ability to write Java programs leveraging Event Driven Programming.
- Testing
- Ability to develop tests for Java programs leveraging Event Driven Programming.
- Debugging
- Ability to troubleshoot Java programs leveraging Event Driven Programming.
- Designing
- Ability to design Java programs leveraging Event Driven Programming.
As with the previous module, we are going to supplement the reading with some apprenticeship videos showing you how to apply the techniques you studied to exercises similar to the ones you will have to work on as part of your homework assignments.
- A01 - BubbleButtonsRemote
- File Link: YouTube
- This exercise is practice exercise #15.3 in the latest edition of our text Display a circle in a pane and provide four buttons (up, down, left, right) that, when clicked, will move the circle around without allowing it to move past the edges of the window.
- A02 - BubbleKeysRemote
- File Link: YouTube
- This exercise is practice exercise #15.11 in the latest edition of our text Modify the previous program so that the circle is moved by using the cursor keys instead of by clicking on buttons.
- A03 - SimpleCalculator
- File Link: YouTube
- This exercise is practice exercise #15.4 in the latest edition of our text We want to write a JavaFX program featuring two input fields allowing the user to provide two double values, another field displaying the result of an arithmetic operation between the two operands. Four buttons will each allow to compute a different operation; +, -, *, /.
- A04 - TargetCircle
- File Link: YouTube
- This exercise is practice exercise #15.12 in the latest edition of our text This program will draw a single circle in the midle of a pane. Display whether the mouse pointer is inside the circle or not. update the message every time the mouse is moved.
- A05 - TargetCircles
- File Link: YouTube
- Improve the previous program by managing several circles in the pane and displaying whether the mouse is outside any circle or identifying which one it is in.
- B01 - Pick Four Cards
- This exercise is #15.1 in the 10th edition of our text. Write a program that lets the user click the Refresh button to display four cards from a deck of 52 cards. See the hint in Programming Exercise 14.3 on how to obtain four random cards.
- B02 - Investment Calculator
-
This exercise is #15.5 in the 10th edition of our text.
Write a program that calculates the future value of an investment at a given interest rate for a specified number of years.
The formula for the calculation is:
futureValue = investmentAmount * (1 + monthlyInterestRate)years*12
Use text fields for the investment amount, number of years, and annual interest rate. Display the future amount in a text field when the user clicks the Calculate button.
- B03 - Adding & Removing Bubbles
- This exercise is #15.15 in the 10th edition of our text. Write a program that lets the user click on a pane to dynamically create and remove points. When the user left-clicks the mouse (primary button), a point is created and displayed at the mouse point. The user can remove a point by pointing to it and right-clicking the mouse (secondary button).
- B04 - Boundary Rectangle
- This exercise is #15.17 in the 10th edition of our text. Write a program that enables the user to add and remove points in a two-dimensional plane dynamically. A minimum bounding rectangle is updated as the points are added and removed. Assume that the radius of each point is 10 pixels.
- B05 - Eye-Hand Coordination Game
- This exercise is #15.19 in the 10th edition of our text. Write a program that displays a circle of radius 10 pixels filled with a random color at a random location in a pane. When you click the circle, it disappears and a new random-color circle is displayed at another random location. After twenty circles are clicked, display the time spent in the pane.