next up previous contents
Next: UNNL Class Up: MyUtil Package Previous: Sortable Interface

Trash Class

The Trash class provides a relocatable and selectable graphic object which may be used as a trash can.

package MyUtil;

import java.awt.*;

public class Trash {

   static final Color highlightColor= Color.yellow;

   static final Color canColor= new Color(128,128,128);

   static final Color canBright= new Color (200, 200, 200);

   static final Color canDark= Color.black; // new Color (100, 100, 100);

   public Trash(int x, int y, int w, int h) {
      beenSelected(false);
      p_center = new xPoint(x,y);
      width=w/2;
      height=h/2;
   }

   private boolean p_beenSelected;

   private int width,height;

   public boolean beenSelected() { return p_beenSelected ;}

   public Trash beenSelected(boolean haveI) {
      p_beenSelected=haveI;
      return this;
   }

   private xPoint p_center;

   public xPoint center() { return p_center ;}

   public Trash center(xPoint p) {
      p_center.x=p.x;
      p_center.y=p.y;
      return this;
   }

   public Trash center(int x, int y) {
      p_center.x=x;
      p_center.y=y;
      return this;
   }

   private int p_colorNum;

   private int p_vNum;

   public String toString(){
      return super.toString()+" Trashcan";
   }

   public void draw(Graphics g) {
      int Left=center().x-width/2,
          Top=center().y-height/2,
          Right=Left+width;
      g.setColor(canDark);
      g.fillRect(Left,Top,width,height);
      g.setColor(canColor);
      g.fillRect(Left+2,Top+2,width-4,height-4);
      g.setColor(canDark);
      g.fillRect(Left -3 + width / 2,Top-2,6,3);
      g.fillRect(Left,Top+4,width,2);
      for (int tmp=Left+8;tmp<Right-2;tmp+=6) {
         g.fillRect(tmp,Top+6,1,height-6);
      }
    }

    public boolean contains(xPoint p) {
       return (p.x>center().x-width/2 &&
               p.x<center().x+width/2 &&
               p.y>center().y-height/2 &&
               p.y<center().y+height/2);
    }

}



Kelly Waters
Mon Oct 27 18:18:15 EST 1997