Question: Java Programming 2 Exercise 18-2 Develop a new GUI In Netbeans IDE 8.1 text boxes. In this exercise, you'll create a GUI application that calculates


Java Programming 2 Exercise 18-2 Develop a new GUI
In Netbeans IDE 8.1
text boxes. In this exercise, you'll create a GUI application that calculates the area and perimeter of a rectangle based on its length and width. When you're done, the application should look like this: a Exercise 18-2 Develop a new GUI Area and Perimeter Calcula... O 8 Length: Width: 4 Area: 32.000 Perimeter: 24.000 Compute Reset Review the existing code for the application 1. Open the project named ch18_ex2_AreaAndPerimeter that's in the ex_starts folder. 2. Open the Rectangle class in the murach.business package and review its fields and methods. 3. Open the AreaAndPerimeterFrame class in the murach.ui package and examine the existing code. Note that: This class extends the JFrame class. This class has a constructor that calls the initComponents() method. This class contains several methods such as the initComponents() method that haven't been implemented or that require additional code. ma This class contains a getConstraints method that works like the getConstraints() method in the Future Value application shown in this This class contains a main() method that creates the frame, which components. Then, resize the frame to make it larger so you can see its title. Run the application. This should display a frame that doesn't contain any Add code to the initComponents() method that initializes the frame and its 10. Implement the resetButtonClicked() method. This method should set all four 618 Section 4 GUI programming chapter causes the frame to be displayed. 4. Add the components to the frame 5. Add instance variables for the four text fields and two buttons. 6. components. This method should: Create the four text fields. Modify the text fields for the area and perimeter so the user can't edit them. Set the minimum and preferred dimension for all four fields. Create the two buttons. Create a panel that uses the GridBagLayout manager. Then, add the four labels and text fields to this panel. To do that, you can use the getConstraints() method. Finally, add this panel to the center of the frame. Create a panel that uses the FlowLayout manager with right alignment. Then, add the two buttons to this panel. Finally, add this panel to the bottom of the frame. Pack the frame to set its size. 7. Run the application. This should display a frame that looks like the frame shown above. However, if you click on one of the buttons, it should not perform an action. Handle the events that occur when the user clicks the buttons 8. Add action listeners to both of the buttons. These action listeners should call the computeButtonClicked() and resetButtonClicked() methods. 9. Implement the computeButtonClicked() method. If the user enters an invalid length or width, this method should use a dialog box to display a user-friendly error message. Then, the user can try again. To do that, you can use the Swing Validator class. If the user enters a valid length and width, this method should calculate the area and perimeter and set the corresponding text fields. To do that, you can use the Rectangle class. text fields to empty strings
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
