Java Swing O Reilly } runningTotal += percentages[i]; (Web hosting india)

Java Swing O Reilly } runningTotal += percentages[i]; } // make each entry a percentage of the total // make each entry a percentage of the total for (int i = model.getRowCount() - 1; i >= 0; i–) { percentages[i] /= runningTotal; } } // This method just takes the percentages and formats them for use as // tooltips protected void createLabelsAndTips() { for (int i = model.getRowCount() - 1; i >= 0; i–) { labels[i] = (String)model.getValueAt(i, 0); tips[i] = formatter.format(percentages[i]); } } // Call this method to update the chart. We try to be a bit efficient here// in that we only allocate new storage arrays if the new table has a// different number of rowsprotected void updateLocalValues(boolean freshStart) { if (freshStart) { int count = model.getRowCount(); if ((tips == null) || (count != tips.length)) { percentages = new double[count]; labels = new String[count]; tips = new String[count]; } } calculatePercentages(); createLabelsAndTips(); // Now that everything’s up-to-date, reset the chart painter with the new // values cp.setValues(percentages); cp.setLabels(labels); // and finally, repaint the chart. repaint(); } } The constructor for TableChart sets the user interface for this class to be the PieChartPainter that we’ll discuss later in this chapter. It also saves the TableModel for the component by calling our setModel() method; providing a separate setModel() (rather than saving the model in the constructor) lets us change the model at a later time a nice feature for a real component, though we don’t take advantage of it. We also override getToolTipText() that is called with a MouseEvent as an argument. This method calls the ChartPainter’s indexOfEntryAt() method to figure out which of the model’s entries corresponds to the current mouse position, looks up the appropriate tooltip, and returns it. tableChanged() is the method we implement to listen for TableModelEvents. It just delegates the call to another method, updateLocalValues(), with an argument of true if the table’s structure has changed (e.g., rows added or deleted), and false if only the values have changed. The rest of TableChart takes care of updating the data when the change occurs. The focal point of this work is - 462 -
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Leave a Reply