Java Swing O Reilly updateLocalValues(); calculatePercentages() and createLabelsAnd-Tips() (Most popular web site)

Java Swing O Reilly updateLocalValues(); calculatePercentages() and createLabelsAnd-Tips() are helper methods that keep the work modular. If up-dateLocalValues() is called with its argument set to true, it finds out the new number of rows for the table and creates new arrays to hold the component’s view of the data. It calculates percentages, retrieves labels, makes up tool tips, and calls the ChartPainter (the user interface object) to give it the new information. It ends by calling repaint() to redraw the screen with updated data. ChartPainter is the actual user interface class. It is abstract; we subclass it to implement specific kinds of charts. It extends the ComponentUI class, which makes it sound rather complex. But in fact, it isn’t. We’ve made one tremendously simplifying assumption: the chart will look the same for any look-and-feel. (The component in which the chart is embedded will change its appearance, but that’s another issue and one we don’t have to worry about.) All our ComponentUI has to do is implement paint(), which we leave abstract, forcing the subclass to implement it. Our other abstract method, indexOfEntryAt(), is required by TableChart. // ChartPainter.java // A simple chart-drawing UI base class. This class tracks the basic fonts // and colors for various types of charts including pie and bar. The paint() // method is abstract and must be implemented by subclasses for each type. // import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.plaf.*; public abstract class ChartPainter extends ComponentUI { protected Font textFont = new Font(”Serif”, Font.PLAIN, 12); protected Color textColor = Color.black; protected Color colors[] = new Color[] { Color.red, Color.blue, Color.yellow, Color.black, Color.green, Color.white, Color.gray, Color.cyan, Color.magenta, Color.darkGray }; protected double values[] = new double[0]; protected String labels[] = new String[0]; public void setTextFont(Font f) { textFont = f; } public Font getTextFont() { return textFont; } public void setColor(Color[] clist) { colors = clist; } public Color[] getColor() { return colors; } public void setColor(int index, Color c) { colors[index] = c; } public Color getColor(int index) { return colors[index]; } public void setTextColor(Color c) { textColor = c; } public Color getTextColor() { return textColor; } public void setLabels(String[] l) { labels = l; } public void setValues(double[] v) { values = v; } public abstract int indexOfEntryAt(MouseEvent me); public abstract void paint(Graphics g, JComponent c); } - 463 -
You want to have a cheap webhost for your apache application, then check apache web hosting services.

Leave a Reply