Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. /*
  2.  *
  3.  *  BasicElement.java
  4.  *
  5.  */
  6.  
  7. import java.awt.*;
  8. import java.awt.event.*;
  9.  
  10. public class BasicElement
  11. {   private int x;      //  Coordinates for the
  12.     private int y;      //   rectangle.
  13.     private Color color;//  Color of the rectangle.
  14.     private int value;  //  Size of the rectangle.
  15.  
  16.     //
  17.     //  Drawing an element
  18.     //
  19.     public void paint(Graphics pane)
  20.     {
  21.         final                   //  The following constants define
  22.             int                 //      the visual characteristics of an element
  23.                 DELTA = 5,      //  For the size of the element's "bottom line"
  24.                 WIDTH = 20,     //      the width of the element
  25.                 HEIGHT = 10;    //      the incremental height
  26.                                 //          (as a unit of the element's value)
  27.  
  28.         pane.setColor(Color.black);         //  Drawing the element's "bottom line"
  29.         pane.drawLine(x-DELTA, y, x+WIDTH+DELTA, y);
  30.  
  31.         pane.setColor(Color.black);         //  Drawing the frame in black
  32.         pane.drawRect(x, y - HEIGHT*value, WIDTH, HEIGHT*value);
  33.                                             //      and the element itself
  34.         pane.setColor(color);               //      in just the right color
  35.         pane.fillRect(x + 1, y - HEIGHT*value + 1, WIDTH - 1, HEIGHT*value - 1);
  36.     }
  37.    
  38.     //  Create a method for LabDemo to use.
  39.     public BasicElement(int newX, int newY){
  40.         x = newX;   //  Sets the coordinates for
  41.         y = newY;   //   the rectangle.
  42.     }
  43.    
  44.     public class Item extends BasicElement{ //  Makes item a subclass of BasicElement.
  45.  
  46.         public Item(int newX, int newY) {
  47.             super(newX, newY);  //  To bring newX and newY values to be used by the Item subclass.
  48.             // TODO Auto-generated constructor stub
  49.         }
  50.        
  51.     }
  52.    
  53.    
  54.     public void setValue(int newValue){
  55.         value = newValue;   //  Value of the size
  56.     }                       //   of the rectangle.
  57.    
  58.     public void setColor(Color newColor){
  59.         color = newColor;   //  Sets the rectangle's
  60.                             //   color.
  61.     }
  62.    
  63.     public int getValue(){
  64.         return value;   //  Returns the value of the
  65.     }                   //   rectangle to be drawn.
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement