Esempio n. 1
0
  @Override
  public void keyPressed(KeyEvent ke) {
    // System.out.println("key pressed:"+ke.getKeyCode());
    if (ke.isControlDown()) {
      if (ke.getKeyCode() == 67) { // Ctrl+c = copy
        menu.copy();
      } else if (ke.getKeyCode() == 88) { // Ctrl+x = cut
        menu.copy();
        menu.delete();
      } else if (ke.getKeyCode() == 86) { // Ctrl+v = paste
        menu.paste();
      } else if (ke.getKeyCode() == 79) { // Ctrl+o = open
        menu.open();
      } else if (ke.getKeyCode() == 83) { // Ctrl+s = save
        menu.save();
      }
    }

    if (ke.getKeyCode() == 38) { // Up key
      for (Bead bead : multiSelect) {
        if (bead.getTrack() > 1) {
          bead.setTrack(bead.getTrack() - 1);
          bead.setLocation(bead.getX(), bead.getY() - beadPlayer1.TRACKHEIGHT);
        }
      }
    } else if (ke.getKeyCode() == 40) { // Down key
      for (Bead bead : multiSelect) {
        if (bead.getTrack() < 8) {
          bead.setTrack(bead.getTrack() + 1);
          bead.setLocation(bead.getX(), bead.getY() + beadPlayer1.TRACKHEIGHT);
        }
      }
    } else if (ke.getKeyCode() == 37) { // Left key
      for (Bead bead : multiSelect) {
        if (bead.getX() > 55) bead.setLocation(bead.getX() - beadPlayer1.BEADHEIGHT, bead.getY());
      }
    } else if (ke.getKeyCode() == 39) { // Right key
      for (Bead bead : multiSelect) {
        if (bead.getX() < 1000) bead.setLocation(bead.getX() + beadPlayer1.BEADHEIGHT, bead.getY());
      }
    } else if (ke.getKeyCode() == 127 || ke.getKeyCode() == 8) { // delete/backspace key
      menu.delete();
    }
  }
Esempio n. 2
0
  /*
  While there is a startBead, where the dragging started,
  this gets ending coordinates of the mouse dragging,
  and calculates the eucleadian distance in between
  so that it returns whether the drag is valid or not.

  tempMinimumDistance. = 100;
  */
  private boolean isActualDrag(int endBeadx, int endBeady) {
    int xdif;
    int ydif;
    double distance;
    try {
      xdif = endBeadx - activeBead.getX();
      ydif = endBeady - activeBead.getY();
      distance = Math.sqrt(Math.abs(xdif * xdif - ydif * ydif)); // Euclidean distance.
      // System.out.println(distance);
      if (distance > 10) { // if distance is greater than 100
        return true;
      } else if (activeBead.connectedTo != null) { // If the bead is already paired.
        return true;
      }
    } catch (NullPointerException e) {
    }
    return false;
  }