Java Reference
In-Depth Information
final String stat5 = "URL\'s with Errors:";
final String stat6 = "Deepest URL\'s found:";
Next, a FontMetrics object is created to properly space all of the text. Drawing a
white rectangle clears the display area.
FontMetrics fm = g.getFontMetrics();
int y = fm.getHeight();
g.setColor(Color.WHITE);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.BLACK);
int total = this.processing + this.error + this.done + this.wait-
ing;
Both NumberFormat and PercentFormat objects are created to format the
numbers.
NumberFormat numFormat = NumberFormat.getInstance();
NumberFormat percentFormat = NumberFormat.getPercentInstance();
If a percent done can be calculated, then calculate it. Otherwise put a zero into percent
done.
if ((this.waiting + this.processing + this.done) == 0) {
this.donePercent = 0;
} else {
this.donePercent = (double) this.done / (double) (this.waiting +
this.processing + this.done);
}
If a percent error can be calculated, then calculate it. Otherwise put a zero into percent
error.
if (total == 0) {
this.errorPercent = 0;
} else {
this.errorPercent = (double) this.error / (double) total;
}
Display the total number of URLs found and move the y variable down by the correct
amount.
g.drawString(stat1, 10, y);
g.drawString("" + numFormat.format(total), 200, y);
y += fm.getHeight();
Display the total number of URLs done and the percent done. Move the y variable down
by the correct amount.
g.drawString(stat2, 10, y);
g.drawString("" + numFormat.format(this.done) + "("
Search WWH ::




Custom Search