Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Graphics2D;
- import java.awt.Rectangle;
- import java.awt.geom.Line2D;
- /** LabeledBar is a rectangle with an interior label.
- * @author John Dalbey
- * @version 2014.6.13
- */
- public class LabeledBar
- {
- private int xLeft;
- private int yTop;
- private int width;
- private int height;
- private String label;
- private Color color;
- /** Construct this object from the specified dimensions.
- * @param x x coordinate of the upper-left corner of this bar.
- * @param y y coordinate of the upper-left corner of this bar.
- * @param aWidth width of the bar in pixels.
- * @param label the text to be displayed inside the bar.
- * @param color desired color of the lines of the bar.
- */
- public LabeledBar(int x, int y, int aWidth, String label, Color color)
- {
- xLeft = x;
- yTop = y;
- width = aWidth;
- height = 20;
- this.label = label;
- this.color = color;
- }
- /** Draw this bar on the supplied graphics context.
- * @param g2 the context on which to draw this bar.
- */
- public void draw(Graphics2D g2)
- {
- Rectangle leftRectangle = new Rectangle(
- xLeft, yTop,
- width, height);
- g2.setColor(color);
- g2.draw(leftRectangle);
- g2.drawString(label, xLeft+height/4, yTop+height*3/4);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement