Java Swing O Reilly summing and averaging along (Mac os x web server)
Thursday, July 26th, 2007Java Swing O Reilly summing and averaging along the columns. It would have been more work (but not much more work) to present the data in any particular column, letting the user choose the column to be displayed. Figure 16.3. A Chart component using a TableModel Here’s the application that produces both the pie chart and the table. It includes the TableModel as an anonymous inner class. This inner class is very simple, much simpler than the models we used earlier in this chapter; it just provides an array for storing the data, methods to get and set the data, and methods to provide other information about the table. Notice that we provided an isCellEditable() method that always returns true (the default method always returns false). Because we’re allowing the user to edit the table, we must also override setValueAt(); our implementation updates the data array and calls fireTableRowsUpdated() to notify any listeners that data has changed and they need to redraw. The rest of ChartTester just sets up the display; we display the pie chart as a popup, to make things somewhat more interesting. // ChartTester.java // import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; public class ChartTester extends JFrame { public ChartTester() { super(”Simple JTable Test”); setSize(300, 200); addWindowListener(new BasicWindowMonitor()); TableModel tm = new AbstractTableModel() { String data[][] = { {”Ron”, “0.00″, “68.68″, “77.34″, “78.02″}, {”Ravi”, “0.00″, “70.89″, “64.17″, “75.00″}, {”Maria”, “76.52″, “71.12″, “75.68″, “74.14″}, {”James”, “70.00″, “15.72″, “26.40″, “38.32″}, {”Ellen”, “80.32″, “78.16″, “83.80″, “85.72″} }; String headers[] = { “”, “Q1″, “Q2″, “Q3″, “Q4″ }; public int getColumnCount() { return headers.length; } - 459 -
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.