Esempio n. 1
0
  public void repaintObjects(List<Component> list) {
    this.removeAll();
    for (Component component : list) {
      StandartFigure standartFigure = (StandartFigure) component;

      switch (standartFigure.getTypeFigure()) {
        case Circle:
          standartFigure.setBounds(
              standartFigure.getX(),
              standartFigure.getY(),
              standartFigure.getWidth() + 2,
              standartFigure.getHeight() + 2);
          break;
        case Square:
          standartFigure.setBounds(
              standartFigure.getX(),
              standartFigure.getY(),
              standartFigure.getWidth() + 2,
              standartFigure.getHeight() + 2);
          break;
        case RoundRect:
          standartFigure.setBounds(
              standartFigure.getX(),
              standartFigure.getY(),
              standartFigure.getWidth() + 2,
              standartFigure.getHeight() + 2);
          break;
        case Line:
          standartFigure.setBounds(
              standartFigure.getX(),
              standartFigure.getY(),
              standartFigure.getWidth() + 2,
              standartFigure.getHeight() + 2);
          break;

        default:
          break;
      }
      add(standartFigure);
      repaint();
      standartFigure = null;
    }
  }
Esempio n. 2
0
    @Override
    public void mouseClicked(MouseEvent e) {
      if (SwingUtilities.isRightMouseButton(e)) {
        grabFocus();
      }

      if (SwingUtilities.isLeftMouseButton(e)) {
        curPoint = e.getPoint();
        Color color = new Color(randomInt(), randomInt(), randomInt());
        switch (paint.getSelectedIndex()) {
          case 1:
            StandartFigure circle = new StandartFigure(TypeFigure.Circle, curPoint);
            circle.setBounds(curPoint.x, curPoint.y, 52, 52);
            circle.setColor(color);
            add(circle);
            break;
          case 2:
            StandartFigure square = new StandartFigure(TypeFigure.Square, curPoint);
            square.setBounds(curPoint.x, curPoint.y, 52, 52);
            square.setColor(color);
            add(square);
            break;
          case 3:
            StandartFigure line = new StandartFigure(TypeFigure.Line, curPoint);
            line.setBounds(curPoint.x, curPoint.y, 52, 52);
            line.setColor(color);
            add(line);
            break;
          case 4:
            StandartFigure roundRectangle = new StandartFigure(TypeFigure.RoundRect, curPoint);
            roundRectangle.setBounds(curPoint.x, curPoint.y, 52, 52);
            roundRectangle.setColor(color);
            add(roundRectangle);
            break;
          default:
            System.out.println("Error index Figure");
            break;
        }
      }
    }