Class ProgressBar
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Canvas
|
+----ProgressBar
- public class ProgressBar
- extends Canvas
The progress bar component is a lightweight component that can be easily incorporated into
most Java programs. A progress bar is made up of a rectangle boarder, background color, a
foreground color, and a percentage displayed in the center of the rectangle. The foreground color
expands or contracts to fill the rectangle depending on the percentage passed in the updatebar
method (for example if 50% is passed the progress bar will show the left half as the foreground
color and the right half as the background color). The string percentage displayed inside the
progress bar will change colors when the foreground color of the progress bar paints over it.
-
ProgressBar(int, int)
- Creates a progress bar using the passed width and height.
-
ProgressBar(int, int, Color, Color, Color)
- Creates a progress bar using the passed width, height, canvas color,
progress bar foreground color, and progress bar background color.
-
paint(Graphics)
- Paints the progress bar on the canvas.
-
setBackGroundColor(Color)
- Sets the background color of the progress bar.
-
setCanvasColor(Color)
- Sets the background color of the canvas the progress bar is drawn on.
-
setProgressColor(Color)
- Sets the foreground color of the progress bar.
-
update(Graphics)
-
-
updateBar(float)
- This method is called when another component wants to update the progress bar.
ProgressBar
public ProgressBar(int progressWidth,
int progressHeight)
- Creates a progress bar using the passed width and height.
ProgressBar
public ProgressBar(int progressWidth,
int progressHeight,
Color canvasColor,
Color progressColor,
Color progressBackground)
- Creates a progress bar using the passed width, height, canvas color,
progress bar foreground color, and progress bar background color.
updateBar
public void updateBar(float percentage)
- This method is called when another component wants to update the progress bar. A percentage in the form
of a float between 0 and 1 is accepted, then the progress bars repaint method is called to paint the
progress bar on its Canvas. The foreground of the progress bar will be repainted, plus the float will
be displayed in the center of the progress bar. Never pass this method a float greater than 1.
setCanvasColor
public void setCanvasColor(Color color)
- Sets the background color of the canvas the progress bar is drawn on.
setProgressColor
public void setProgressColor(Color progressColor)
- Sets the foreground color of the progress bar.
setBackGroundColor
public void setBackGroundColor(Color progressBackground)
- Sets the background color of the progress bar.
paint
public void paint(Graphics g)
- Paints the progress bar on the canvas. The string percentage displayed inside the progress bar will change colors
when the foreground color of the progress bar paints over it. This is accomplished by first painting the
the string percentage in the same color as the foreground, then setting the clipping rectange to the same size
as the foreground and repainting the percentage in the background color in the same spot. When the forground
is not overlaying the string percentage, the second string percentage will not paint because the clipping rectangle
does not cover that area.
- Overrides:
- paint in class Canvas
update
public void update(Graphics g)
- Overrides:
- update in class Component