public static void main(String[] args) {
   // TODO Auto-generated method stub
   ShapeFactory sf = new ShapeFactory();
   Shape circle = sf.getShape("CIRCLE");
   Shape rect = sf.getShape("RECTANGLE");
   circle.draw();
   rect.draw();
 }
Beispiel #2
0
  public static void main(String[] args) {
    ShapeFactory sf1 = new SquareFactory();
    ShapeFactory sf2 = new CircleFactory();
    sf1.anOperation("Shape one");
    sf2.anOperation("Shape two");

    System.out.printf("icon:%s,main:%s,app_name:%s,hello:%s\n", icon, main, app_name, hello);
    System.out.println(hello == test);
  }
Beispiel #3
0
  public static void main(String[] args) throws IOException {
    List<ShapeIter> list = new ArrayList<ShapeIter>();
    boolean flag = true;
    while (flag) {
      System.out.println("which shape you want to create?");
      System.out.println("1.Circle. 2.Rectangle. 3.Square. 4.Exit");
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      switch (Integer.parseInt(br.readLine())) {
        case 1:
          Circle circle = (Circle) ShapeFactory.getInstance().getShape(ShapeType.CIRCLE);
          System.out.println("Please input the radius :");
          circle.setRadius(Double.parseDouble(br.readLine()));
          list.add(circle);
          break;
        case 2:
          Rectangle rectangle =
              (Rectangle) ShapeFactory.getInstance().getShape(ShapeType.RECTANGLE);
          System.out.println("Please input the width :");
          rectangle.setWidth(Double.parseDouble(br.readLine()));
          System.out.println("Please input the length :");
          rectangle.setLength(Double.parseDouble(br.readLine()));
          list.add(rectangle);
          break;
        case 3:
          Square square = (Square) ShapeFactory.getInstance().getShape(ShapeType.SQUARE);
          System.out.println("Please input the side :");
          square.setSide(Double.parseDouble(br.readLine()));
          list.add(square);
          break;
        case 4:
          flag = false;
          br.close();
          break;
      }
    }

    System.out.println("Before sort");

    for (ShapeIter shape : list) {
      System.out.println(shape.calulateArea());
    }

    Collections.sort(list, new ShapeComparator());
    System.out.println("---------------------");

    System.out.println("After sort");
    for (ShapeIter shape : list) {
      System.out.println(shape.calulateArea());
    }
  }
Beispiel #4
0
  /** @return the shapes contained in this group container */
  public Shape[] getShapes() {
    // Out escher container record should contain serveral
    //  SpContainers, the first of which is the group shape itself
    List lst = _escherContainer.getChildRecords();

    ArrayList shapeList = new ArrayList();
    // Don't include the first SpContainer, it is always NotPrimitive
    for (int i = 1; i < lst.size(); i++) {
      EscherRecord r = (EscherRecord) lst.get(i);
      if (r instanceof EscherContainerRecord) {
        // Create the Shape for it
        EscherContainerRecord container = (EscherContainerRecord) r;
        Shape shape = ShapeFactory.createShape(container, this);
        shape.setSheet(getSheet());
        shapeList.add(shape);
      } else {
        // Should we do anything special with these non
        //  Container records?
        logger.log(
            POILogger.ERROR,
            "Shape contained non container escher record, was " + r.getClass().getName());
      }
    }

    // Put the shapes into an array, and return
    Shape[] shapes = (Shape[]) shapeList.toArray(new Shape[shapeList.size()]);
    return shapes;
  }