Exercise 2: Graphical User Interface for calculating monthly payments of the BP plan (20pt) Now, we will create user friendly GUI. The GUI should look as follows. х Monthly payment calculator of BP plan Spending amount: 10000 Monthly interest rate: 0.03 Payment periods: 5 Monthly payment: $2,318.55 Calculate The GUI contains an inner panel, as highlighted below.
3 x Monthly payment calculator of BP plan Spending amount: 10000 Monthly interest rate: 0.03 Payment periods: Monthly payment: $2,318.55 Calculate 5 The inner panel contains the following components: • A label for the spending amount; A text field for entering the spending amount; • A label for the monthly interest rate; A text field for entering the monthly interest rate; A label for the payment period; A text field for entering the number of payments; • A label for the monthly payment; A label to show the calculated result; Set the size of inner panel to 300 x 100. You need to use the Grid Layout to make the components well aligned. You can use the following code: import javax.swing.*; JPanel panelInner = new JPanel(new GridLayout(4,2)); panelInner.setPreferredSize(new Dimension (300, 100)); Then add the above components to the inner panel one by one in row-major order (1.e. first add label 1, second add text field 1; then add label 2, text field 2, ...) Create a button labeled as “Calculate". Next, create an outer panel (create it in the usual way), and add the inner panel and the button to the outer panel, as illustrated below. ох Monthly payment calculator of BP plan Spending amount: 10000 Monthly interest rate: 0.03 Payment periods: Monthly payment: $2,318.55 Calculate 5 Add the outer panel to the frame. You may set the frame size as 400 x 200. Set a proper title for the frame.
The program needs to respond to a button click as follows: • Read the spending amount form the proper text field, and convert it to a double; • Read the interest rate from the proper text field, and convert it to a double; • Read the number of payment period from the proper text field, and convert it to a double; • Calculate the monthly payment (use the method developed in Exercise 1); • Display the result by updating the text of the result label. Note: Use the following code to set the proper display format: (...label object...).setText(String.format("%.2f", ...);
Exercise 2: Graphical User Interface for calculating monthly payments of the BP plan (20pt) Now, we will create user fri
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Exercise 2: Graphical User Interface for calculating monthly payments of the BP plan (20pt) Now, we will create user fri
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!