Ejemplo n.º 1
0
  public void changeColor() {

    // set initial color of top left quadrant

    if ((cxLoc < vLine.getStart().getX()) && (cyLoc < hLine.getStart().getY())) {

      ball.setColor(Color.cyan);
    }
    // set initial color of top right quadrant

    if ((cxLoc > vLine.getStart().getX()) && (cyLoc < hLine.getStart().getY())) {

      ball.setColor(Color.magenta);
    }
    // set initial color of bottom left quadrant

    if ((cxLoc < vLine.getStart().getX()) && (cyLoc > hLine.getStart().getY())) {

      ball.setColor(Color.yellow);
    }
    // set initial color of bottom right quadrant

    if ((cxLoc > vLine.getStart().getX()) && (cyLoc > hLine.getStart().getY())) {

      ball.setColor(Color.black);
    }
  }
Ejemplo n.º 2
0
  public void resizeBall() {

    // if it grows set xLoc, YLoc and
    // increment, otherwise false.
    if (grow) {

      if (size < MAX_SIZE) {
        double xLoc = cxLoc + size / 2;

        double yLoc = cyLoc + size / 2;

        size += GROWTH;

        ball.setSize(size, size);

        cxLoc = xLoc - size / 2;

        cyLoc = yLoc - size / 2;

        ball.moveTo(cxLoc, cyLoc);

      } else {

        grow = false;
      }

    } else {

      // otherwise shrink

      if ((size <= MAX_SIZE) && (size > MIN_SIZE)) {

        double xLoc = cxLoc + size / 2;

        double yLoc = cyLoc + size / 2;

        size -= GROWTH;

        ball.setSize(size, size);

        cxLoc = xLoc - size / 2;

        cyLoc = yLoc - size / 2;

        ball.moveTo(cxLoc, cyLoc);

      } else {

        grow = true;
      }
    }
    // time delay to prevent lag
    pause(100 - speed);
  }
Ejemplo n.º 3
0
  public void actionPerformed(ActionEvent evt) {

    // if start is pressed, activate run method
    if (evt.getActionCommand().equals("Start")) {

      start();
    }
    // if stop is pressed, stop all of the balls
    // and change color.
    if (evt.getActionCommand().equals("Stop")) {

      stop();
      changeColor();
    }
    // if clear all is pressed, clear all of the balls
    // from the canvas.
    if (evt.getActionCommand().equals("Clear All")) {

      ball.removeFromCanvas();
    }
  }
Ejemplo n.º 4
0
  public void mousePressed(MouseEvent evt) {

    // Checks if the MouseEvent evt lies on the ball
    // and creates variable b_grabbed.
    b_grabbed = ball.contains(new Location(evt.getPoint()));
  }