Java Swing O Reilly (Ipower web hosting) public int getRowCount() {
Java Swing O Reilly public int getRowCount() { return data.length; } public String getColumnName(int col) { return headers[col]; } public Class getColumnClass(int col) { return (col == 0) ? String.class : Number.class; } public boolean isCellEditable(int row, int col) { return true; } public Object getValueAt(int row, int col) { return data[row][col]; } public void setValueAt(Object value, int row, int col) { data[row][col] = (String)value; fireTableRowsUpdated(row,row); } }; JTable jt = new JTable(tm); JScrollPane jsp = new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); final TableChartPopup tcp = new TableChartPopup(tm); JButton button = new JButton(”Show me a chart of this table”); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { tcp.setVisible(true); } } ); getContentPane().add(button, BorderLayout.SOUTH); } public static void main(String args[]) { ChartTester ct = new ChartTester(); ct.setVisible(true); } } The TableChart object is actually made of three pieces. The TableChart class extends JComponent, which provides all the machinery for getting a new component on the screen. It implements TableModelListener because it has to register and respond to TableModelEvents. // TableChart.java // A chart-generating class that uses the TableModel interface to get // its data. // import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.table.*; public class TableChart extends JComponent implements TableModelListener { protected TableModel model; protected ChartPainter cp; protected double[] percentages; // pie slices protected String[] labels; // labels for slices protected String[] tips; // tooltips for slices protected java.text.NumberFormat formatter = java.text.NumberFormat.getPercentInstance(); public TableChart(TableModel tm) { setUI(cp = new PieChartPainter()); setModel(tm); - 460 -
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.