示例#1
0
  public static void main(String[] args) {

    ConsoleIO con = new ConsoleIO();

    Shape tri = new Triangle();
    tri.name = "Triangle";
    tri.setColor = "Yellow";

    tri.getArea();
    tri.getPerimeter();

    Shape sq = new Square();
    System.out.println("square");
    sq.setColor = "blue";

    sq.getArea();
    sq.getPerimeter();

    Shape rec = new Rectangle();
    System.out.println("rectangle");
    rec.setColor = "Green";

    rec.getArea();
    rec.getPerimeter();

    Shape circ = new Circle();
    System.out.println("circle");
    circ.setColor = "Red";

    circ.getArea();
    circ.getPerimeter();
  }
 void addShape(Shape shape) {
   // Add the shape to the canvas, and set its size/position and color.
   // The shape is added at the top-left corner, with size 80-by-50.
   // Then redraw the canvas to show the newly added shape.
   shape.setColor(currentColor);
   shape.reshape(3, 3, 80, 50);
   shapes.add(shape);
   repaint();
 }
示例#3
0
 @Override
 public void colorButtonHit(Color c) {
   col = c;
   if (selectedIndex > -1) {
     Shape s = model.getShape(selectedIndex);
     s.setColor(col);
     model.setShape(selectedIndex, s);
   }
   GUIFunctions.changeSelectedColor(c);
 }
 /**
  * On click, if a shape has been clicked, change its color to the Drawing object's current set
  * color.
  */
 public void executeClick(Point p, Drawing dwg) {
   Shape clickedShape = dwg.getFrontmostContainer(p);
   if (clickedShape != null) clickedShape.setColor(dwg.getColor());
 }