Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- * BasicElement.java
- *
- */
- import java.awt.*;
- import java.awt.event.*;
- public class BasicElement
- { private int x; // Coordinates for the
- private int y; // rectangle.
- private Color color;// Color of the rectangle.
- private int value; // Size of the rectangle.
- //
- // Drawing an element
- //
- public void paint(Graphics pane)
- {
- final // The following constants define
- int // the visual characteristics of an element
- DELTA = 5, // For the size of the element's "bottom line"
- WIDTH = 20, // the width of the element
- HEIGHT = 10; // the incremental height
- // (as a unit of the element's value)
- pane.setColor(Color.black); // Drawing the element's "bottom line"
- pane.drawLine(x-DELTA, y, x+WIDTH+DELTA, y);
- pane.setColor(Color.black); // Drawing the frame in black
- pane.drawRect(x, y - HEIGHT*value, WIDTH, HEIGHT*value);
- // and the element itself
- pane.setColor(color); // in just the right color
- pane.fillRect(x + 1, y - HEIGHT*value + 1, WIDTH - 1, HEIGHT*value - 1);
- }
- // Create a method for LabDemo to use.
- public BasicElement(int newX, int newY){
- x = newX; // Sets the coordinates for
- y = newY; // the rectangle.
- }
- public class Item extends BasicElement{ // Makes item a subclass of BasicElement.
- public Item(int newX, int newY) {
- super(newX, newY); // To bring newX and newY values to be used by the Item subclass.
- // TODO Auto-generated constructor stub
- }
- }
- public void setValue(int newValue){
- value = newValue; // Value of the size
- } // of the rectangle.
- public void setColor(Color newColor){
- color = newColor; // Sets the rectangle's
- // color.
- }
- public int getValue(){
- return value; // Returns the value of the
- } // rectangle to be drawn.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement