31.1* | ( Creating a table for a loan schedule ) Exercise 26.5 displays an amortization schedule in a text area. Write a program that enables the user to enter or choose the loan amount, number of years , and interest rate from spinners and displays the schedule in a table, as shown in Figure 31.29. Figure 31.29. The table shows the loan schedule. |
31.2* | ( Deleting rows and columns ) Listing 31.5, TableModelDemo.java, allows you to delete only the first selected row or column. Enable the program to delete all the selected rows or columns. Also enable the program to delete a row or a column by pressing the DELETE key. |
31.3** | ( Creating a student table ) Create a table for student records. Each record consists of name, birthday, class status, in-state, and a photo, as shown in Figure 31.30. The name is of the String type; birthday is of the Date type; class status is one of the following five values: Freshman, Sophomore, Junior, Senior, or Graduate; in-state is a boolean value indicating whether the student is a resident of the state; and photo is an image icon. Use the default editors for name, birthday, and in-state. Supply a combo box as custom editor for class status. Figure 31.30. The table displays student records and supports add, remove, and edit operations.
|
31.4* | ( Displaying a table for data from a text file ) Suppose that a table named Exercise31_4Table.txt is stored in a text file. The first line in the file is the header, and the remaining lines correspond to rows in the table. The elements are separated by commas. Write a program to display the table using the JTable component. For example, the following text file is displayed in a table, as shown in Figure 31.31: Figure 31.31. The data in the file is displayed in a JTable .
|
31.5*** | ( Creating a controller using JTable ) In Exercise 30.1, you created a chart model ( ChartModel ) and two views ( PieChart and BarChart ). Create a controller that enables the user to modify the data, as shown in Figure 31.32. You will see the changes take effect in the pie chart view and the bar chart view. Your exercise consists of the following classes:
Figure 31.32. You can modify the data in the controller. The views are synchronized with the controller. |
31.6* | ( Creating a tree for book chapters ) Create a tree to display the table of contents for a book. When a node is selected in the tree, display a paragraph to describe the selected node, as shown in Figure 31.33. Figure 31.33. The content of the node is displayed in a text area when the node is clicked. |
31.7** | ( Adding and deleting tree nodes using the INSERT and DELETE keys ) Modify Listing 31.15, ModifyTree.java, to add a new child node by pressing the INSERT key, and delete a node by pressing the DELETE key. |
31.8* | ( Traversing trees ) Create a tree using the default JTree constructor and traverse the nodes in breadth-first, depth-first, preorder, and postorder. |
31.9* | ( Storing and restoring trees ) Modify Listing 31.15, ModifyTree.java, to add two buttons, as shown in Figure 31.34 to store and restore trees. Use the object I/O to store the tree model. Figure 31.34. You can store tree data to a file and restore it later. |