Exemplo n.º 1
0
    public void mousePressed(java.awt.event.MouseEvent e) {
      isClick = true;
      JButton b = (JButton) e.getSource();
      // check to see if the target button can be moved
      if (!solved && check(buttons.indexOf(b))) {
        // hide the target button
        b.setVisible(false);

        // Figure out the bounds of the areas where source
        // and target buttons are located
        int menuOffset = getJMenuBar().getHeight();
        dragSourceArea = b.getBounds();
        dragTargetArea = ((JButton) buttons.get(hiddenIndex)).getBounds();
        dragSourceArea.translate(0, menuOffset);
        dragTargetArea.translate(0, menuOffset);

        // setup the bounds of the panel to limit the locations on the drag
        // layer
        panelArea = new Rectangle(0, menuOffset, getJPanel().getWidth(), getJPanel().getHeight());

        // Setup and show the drag button on the upper layer
        getDragButton().setText(b.getText());
        getDragButton().setBounds(dragSourceArea);
        getDragButton().setVisible(true);

        // Offset when repositioning the drag button later
        cursorOffset = new Point(e.getX(), e.getY());
      }
    }
Exemplo n.º 2
0
  // Used to change cell states manually when game isn't running
  private void manualCell(java.awt.event.MouseEvent e) {
    // Gets coordinates of clicked cell
    JLabel cell = (JLabel) e.getSource();
    int x = cell.getX() / 18;
    int y = cell.getY() / 18;

    // Changes state of the cell
    if (alive[x][y]) {
      alive[x][y] = false;
      cells[x][y].setIcon(white);
    } else {
      alive[x][y] = true;
      cells[x][y].setIcon(black);
    }
  }
Exemplo n.º 3
0
    public void mouseReleased(java.awt.event.MouseEvent e) {
      if (dragTargetArea != null) {

        // Turn off the drag button and feedback
        getDragButton().setVisible(false);
        paintTargetFeedback(-1, -1);

        e.translatePoint(dragSourceArea.x, dragSourceArea.y);
        Point p = makeSafePoint(e.getX(), e.getY());

        JButton b = (JButton) e.getSource();
        if (isClick || dragTargetArea.contains(p.x, p.y)) {
          // if we're considered a simple click, or the dragging ended
          // within the target area, perform the move.
          slide(buttons.indexOf(b));
        } else {
          // The drag finished outside the target, so just show the
          // hidden button and don't move anything.
          b.setVisible(true);
        }
        dragTargetArea = null;
        dragSourceArea = null;
      }
    }
Exemplo n.º 4
0
 public void mousePressed(java.awt.event.MouseEvent event) {
   Object object = event.getSource();
   if (object == LightCalendar.this) LightCalendar_MousePress(event);
 }