示例#1
0
  public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_ESCAPE && gamerunner.running) {

      Graphics gr = this.getGraphics();
      gr.setFont(new Font("TimesRoman", Font.PLAIN, 40));
      gr.drawString("PAUSE", (int) this.getWidth() / 2, this.getHeight() / 2);
      if (!online) {
        gamerunner.running = false;
      }
      if (soundan) {} // end of if
      Menu menu = new Menu(this);
      // volume.setValue(vol);
    } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
      gamerunner.running = true;
      if (soundan) {} // end of if
    } // end of if-else
    else if (e.getKeyCode() == KeyEvent.VK_R && !online) {
      restartGame();
    } else if (e.getKeyCode() == KeyEvent.VK_F11) {
      dispose();
      setUndecorated(true);
      String[] arguments = {"fullscreen"};
      new JavaGame(arguments);
    } else if (e.getKeyCode() == KeyEvent.VK_ENTER && online) {
      String message =
          JOptionPane.showInputDialog(null, "Chat", "Nachricht", JOptionPane.PLAIN_MESSAGE);
      try {
        if (!message.isEmpty()) {
          client.sendNewChatMessage(player[client.id].name, message);
        }
      } catch (IOException e1) {
        e1.printStackTrace();
      }
    }
  }
示例#2
0
  public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_UP) {
      if (x > 20) {
        x -= 5;

        // y+=5;
      }
    } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
      x += 10;

      // if(y>0)
      // y--;
    } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
      if (position == 2) {
        position = 1;

        car.setBounds(120, 500, 120, 70);
      }
      if (position == 3) {
        position = 2;
        car.setBounds(240, 500, 120, 70);
      }
    } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
      if (position == 2) {
        position = 3;
        car.setBounds(360, 500, 120, 70);
      }
      if (position == 1) {
        position = 2;

        car.setBounds(240, 500, 120, 70);
      }
    }
  }
示例#3
0
  public void keyReleased(KeyEvent key) {

    if (key.getKeyCode() == 37) {

      leftcheck = false;
      if (rightcheck) {
        player.ta = changet;
      } else {
        player.ta = 0;
      }
    }

    if (key.getKeyCode() == 39) {

      rightcheck = false;
      if (leftcheck) {
        player.ta = -changet;
      } else {
        player.ta = 0;
      }
    }

    if (key.getKeyCode() == 32) {

      grav = false;
    }
  }
 void objectTable_keyTyped(KeyEvent e) {
   if (e.getKeyCode() == KeyEvent.VK_DELETE) {
     removeCurrent();
   } else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
     editCurrent();
   }
 }
 @Override
 public void keyPressed(KeyEvent e) {
   TreePath path = myTree.getLeadSelectionPath();
   if (path == null) return;
   final Object lastComponent = path.getLastPathComponent();
   if (e.getKeyCode() == KeyEvent.VK_ENTER) {
     if (lastComponent instanceof ParentNode) return;
     doOKAction();
     e.consume();
   } else if (e.getKeyCode() == KeyEvent.VK_INSERT) {
     if (lastComponent instanceof ElementNode) {
       final DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastComponent;
       if (!mySelectedNodes.contains(node)) {
         if (node.getNextNode() != null) {
           myTree.setSelectionPath(new TreePath(node.getNextNode().getPath()));
         }
       } else {
         if (node.getNextNode() != null) {
           myTree.removeSelectionPath(new TreePath(node.getPath()));
           myTree.setSelectionPath(new TreePath(node.getNextNode().getPath()));
           myTree.repaint();
         }
       }
       e.consume();
     }
   }
 }
 void jTextFieldSendMessages_keyPressed(KeyEvent e) {
   if (e.getKeyCode() == e.VK_DOWN) {
     String s = msgHistory.forward();
     if (s != null) {
       jTextFieldSendMessages.setText(s);
     }
   } else if (e.getKeyCode() == e.VK_UP) {
     String s = msgHistory.back();
     if (s != null) {
       jTextFieldSendMessages.setText(s);
     }
   } else if (e.getKeyChar() == '\n') {
     String body = jTextFieldSendMessages.getText();
     if (body.length() > 0) {
       if (body.charAt(body.length() - 1) == '\n') body = body.substring(0, body.length() - 1);
       String subject = jTextFieldSendSubject.getText();
       if (subject.length() > 0) {
         if (subject.charAt(subject.length() - 1) == '\n')
           subject = subject.substring(0, subject.length() - 1);
       }
       if (session != null && session.isConnected()) {
         session.postMessage(jTextFieldTargetUser.getText(), subject, body);
         displaySendMessage(subject, jTextFieldTargetUser.getText(), body, outgoingMsgAttrSet);
       }
       msgHistory.add(body);
       subjectHistory.add(subject);
       subjectHistory.reset();
       msgHistory.reset();
       jTextFieldSendMessages.setText("");
       jTextFieldSendSubject.setText("");
     }
   }
 }
示例#7
0
  @Override
  public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
      System.exit(0);
    }

    // TODO Auto-generated method stub
    if (state == 1) // we are in a story
    {
      if (fadeCounter < FADETIMELIMIT) {
        fadeCounter = FADETIMELIMIT;
        oldbg = bg;
      }

      fadeUpdate = true;
      fadeCounter = 0;
      progress(); // keep going
    } else if (state == 2) {
      if (e.getKeyCode() == KeyEvent.VK_1) {
        index = next(tag, index, 1);
        progress();
      } else if (e.getKeyCode() == KeyEvent.VK_2) {
        index = next(tag, index, 2);
        progress();
      } else if (e.getKeyCode() == KeyEvent.VK_3) {
        index = next(tag, index, 3);
        progress();
      }
    }
  }
示例#8
0
    @Override
    public void keyPressed(KeyEvent evt) {
      if (evt.isConsumed()) return;
      Component comp = getFocusOwner();
      if (evt.getKeyCode() == KeyEvent.VK_ENTER && enterEnabled) {
        while (comp != null) {
          if (comp instanceof JComboBox) {
            JComboBox<?> combo = (JComboBox<?>) comp;
            if (combo.isEditable()) {
              Object selected = combo.getEditor().getItem();
              if (selected != null) combo.setSelectedItem(selected);
            }

            if (combo.isPopupVisible()) {
              evt.consume();
              combo.setPopupVisible(false);
            }
            return;
          }
          // TODO: add other classes that need custom key handling here.
          comp = comp.getParent();
        }
        evt.consume();
        ok();
      } else if (evt.getKeyCode() == KeyEvent.VK_ESCAPE || isCloseBufferShortcut(evt)) {
        evt.consume();
        if (comp instanceof JComboBox) {
          JComboBox<?> combo = (JComboBox<?>) comp;
          if (combo.isPopupVisible()) combo.setPopupVisible(false);
          else cancel();
        } else cancel();
      }
    }
示例#9
0
  @Override
  public void keyPressed(KeyEvent e) {
    // TODO Auto-generated method stub
    if (e.getKeyCode() == KeyEvent.VK_W) {
      this.hero.setDirection(0);
      hero.moveUp();
    } else if (e.getKeyCode() == KeyEvent.VK_D) {
      this.hero.setDirection(1);
      hero.moveRight();
    } else if (e.getKeyCode() == KeyEvent.VK_S) {
      this.hero.setDirection(2);
      hero.moveDown();
    } else if (e.getKeyCode() == KeyEvent.VK_A) {
      this.hero.setDirection(3);
      hero.moveLeft();
    }
    // 判断玩家是否按下J键 则开火
    if (e.getKeyCode() == KeyEvent.VK_J) {
      if (this.hero.bombs.size() <= 40) {

        hero.fire();
      }
    }
    this.repaint();
  }
示例#10
0
 /**
  * Event handler helper-method. Actionable F2-key check
  *
  * @param evt User Keyboard Press
  */
 private void checkF2Key(KeyEvent evt) {
   if (evt.getKeyCode() == 113) {
     System.out.println(evt.getKeyCode());
     EasyButtonMouseReleased(null);
     // HardButtonMouseReleased(null);
     // FileMenuMouseClicked(null);
   }
 }
 // Implementation of keyPressed
 public void keyPressed(KeyEvent e) {
   if (e.getSource() == searchbutton && e.getKeyCode() == KeyEvent.VK_ENTER) {
     update();
   } else if (e.getSource() == addfeesbutton && e.getKeyCode() == KeyEvent.VK_ENTER) {
     addFees();
   } else if (e.getSource() == addcoursebutton && e.getKeyCode() == KeyEvent.VK_ENTER) {
     addCourse();
   }
 }
示例#12
0
 public void keyReleased(KeyEvent ke) {
   if (ke.getKeyCode() == KeyEvent.VK_UP) {
     String up = history.getUp();
     if (up != null) messageText.setText(up);
   } else if (ke.getKeyCode() == KeyEvent.VK_DOWN) {
     String down = history.getDown();
     if (down != null) messageText.setText(down);
   }
 }
示例#13
0
 public void keyReleased(KeyEvent e) {
   if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
     shiftPressed = false;
     repaint();
   }
   if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
     controlPressed = false;
     repaint();
   }
 }
示例#14
0
 /**
  * ************************************************
  *
  * <pre>
  * Summary: Catch any key pressed.
  *
  * </pre>
  *
  * *************************************************
  */
 public void keyPressed(KeyEvent e) {
   // Have an escape do the same as clicking cancel.
   if (e.getKeyCode() == KeyEvent.VK_ESCAPE) abandonButton.doClick();
   // Return
   else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
     if (closeButton.isEnabled()) {
       closeButton.doClick();
     }
   }
 }
示例#15
0
 void jTextFieldSendSubject_keyPressed(KeyEvent e) {
   if (e.getKeyCode() == e.VK_DOWN) {
     String s = subjectHistory.forward();
     if (s != null) {
       jTextFieldSendSubject.setText(s);
     }
   } else if (e.getKeyCode() == e.VK_UP) {
     String s = subjectHistory.back();
     if (s != null) {
       jTextFieldSendSubject.setText(s);
     }
   } else if (e.getKeyChar() == '\n') {
     jTextFieldSendMessages.requestFocus();
   }
 }
示例#16
0
  /** This method cannot be called directly. */
  public void keyTyped(KeyEvent e) {
    int keyCode = e.getKeyCode();
    System.out.println(keyCode);
    switch (keyCode) {
      case KeyEvent.VK_W:
        // handle up
        System.out.println("up?");
        break;
      case KeyEvent.VK_DOWN:
        // handle down
        break;
      case KeyEvent.VK_LEFT:
        // handle left
        break;
      case KeyEvent.VK_RIGHT:
        // handle right
        break;
    }
    System.out.println(e.getKeyChar());
    if (e.getKeyChar() == KeyEvent.VK_UP) {
      System.out.println("up arrow pressed");
    }

    synchronized (keyLock) {
      keysTyped.addFirst(e.getKeyChar());
    }
  }
示例#17
0
 public void keyPressed(KeyEvent e) {
   int code = e.getKeyCode();
   if (code == KeyEvent.VK_ENTER) {
     document.enter();
     e.consume();
   }
 }
示例#18
0
 public void keyPressed(KeyEvent e) {
   // displayInfoKey(e, "KEY PRESSED: ");
   if (e.getKeyCode() == 10) {
     consolefunction(testfield.getText());
     testfield.setText("");
   }
 }
示例#19
0
  public void keyPressed(KeyEvent e) {
    // System.out.println("keyPressed");
    if (focussed) {
      switch (e.getKeyCode()) {
        case KeyEvent.VK_W: // case KeyEvent.VK_W uo:
          pacman.moveUp();
          break;

        case KeyEvent.VK_Z: // case KeyEvent.VK_Z down:
          pacman.moveDown();
          break;

        case KeyEvent.VK_S: // case KeyEvent.VK_S right:
          pacman.moveUp();
          break;

        case KeyEvent.VK_A: // case KeyEvent.VK_A  left:
          pacman.moveUp();
          break;

        case KeyEvent.VK_UP: // case KeyEvent.VK_KP_UP:
          pacman.moveUp();
          break;
        case KeyEvent.VK_DOWN: // case KeyEvent.VK_KP_DOWN:
          pacman.moveDown();
          break;
        case KeyEvent.VK_RIGHT: // case KeyEvent.VK_KP_RIGHT:
          pacman.moveRight();
          break;
        case KeyEvent.VK_LEFT: // case KeyEvent.VK_KP_LEFT:
          pacman.moveLeft();
          break;
      }
    } // end if focussed
  }
示例#20
0
  public void keyPressed(KeyEvent e) {

    switch (e.getKeyCode()) {
      case KeyEvent.VK_Z:
        skill_id = 0;
        break;
      case KeyEvent.VK_X:
        skill_id = 1;
        break;
      case KeyEvent.VK_C:
        skill_id = 2;
        break;
      case KeyEvent.VK_V:
        skill_id = 3;
        break;
      case KeyEvent.VK_SPACE:
        if (arena.game == Constant.GameStatus.PAUSE) {
          arena.game = prevGameStatus;
        } else {
          prevGameStatus = arena.game;
          arena.game = Constant.GameStatus.PAUSE;
        }
        break;
      case KeyEvent.VK_ESCAPE:
        arena.game = Constant.GameStatus.END;
        break;
      default:;
    }
  }
  @SuppressWarnings("HardCodedStringLiteral")
  private boolean togglePopup(KeyEvent e) {
    final KeyStroke stroke = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers());
    final Object action = ((InputMap) UIManager.get("ComboBox.ancestorInputMap")).get(stroke);
    if ("selectNext".equals(action)) {
      if (!isPopupShowing()) {
        return true;
      } else {
        return false;
      }
    } else if ("togglePopup".equals(action)) {
      if (isPopupShowing()) {
        closePopup();
      } else {
        suggestCompletion(true, true);
      }
      return true;
    } else {
      final Keymap active = KeymapManager.getInstance().getActiveKeymap();
      final String[] ids = active.getActionIds(stroke);
      if (ids.length > 0 && IdeActions.ACTION_CODE_COMPLETION.equals(ids[0])) {
        suggestCompletion(true, true);
      }
    }

    return false;
  }
示例#22
0
    public void keyPressed(KeyEvent e) {
      int keyCode = e.getKeyCode();

      System.out.println(keyCode + ", " + e.getKeyChar()); // testing

      // When shift is held, the user has entered editing mode
      if (e.isShiftDown()) {
        editingMode = true;
      } else {
        editingMode = false;
      }

      if (keyCode == KeyEvent.VK_SPACE)
        // Stop all stoppable sounds
        soundManager.stopSounds();
      else {
        SoundInfo sound = soundManager.getSound(keyCode);
        if (sound != null) {
          // Play, stop, or edit the sound
          dialogManager.handleSoundEvent(sound);
        } else if (getEditingMode()
            && keyCode != KeyEvent.VK_SHIFT
            && keyCode != KeyEvent.VK_CAPS_LOCK) {
          // Create a new sound
          dialogManager.displayNewSoundDialog();
        }
      }
    }
 public void keyPressed(KeyEvent e) {
   switch (e.getKeyCode()) {
     case KeyEvent.VK_UP:
       y -= 10;
       if (y < 0) {
         y = 0;
       }
       break;
     case KeyEvent.VK_DOWN:
       y += 10;
       if (y > BlockDown.HEIGHT) {
         y = BlockDown.HEIGHT;
       }
       break;
     case KeyEvent.VK_LEFT:
       x -= 10;
       if (x < 0) {
         x = 0;
       }
       break;
     case KeyEvent.VK_RIGHT:
       x += 10;
       if (x > BlockDown.WEIGHT) {
         x = BlockDown.WEIGHT;
       }
       break;
   }
 }
示例#24
0
 /** Controls the movements and actions of character and tetris pieces */
 public void keyPressed(KeyEvent key) {
   String keyText = KeyEvent.getKeyText(key.getKeyCode());
   if (!pause) {
     if (!shapeAI.getAI()) {
       if (keyText.equalsIgnoreCase("a")) {
         shapes.get(0).moveLeft(map);
         shapeTrack.add(1);
       }
       if (keyText.equalsIgnoreCase("d")) {
         shapes.get(0).moveRight(map);
         shapeTrack.add(2);
       }
       if (keyText.equalsIgnoreCase("w")) {
         shapes.get(0).turn(map, shapeTrack);
       }
     }
     if (keyText.equalsIgnoreCase("left")) {
       character.moveLeft();
     }
     if (keyText.equalsIgnoreCase("right")) {
       character.moveRight();
     }
     if (keyText.equalsIgnoreCase("up")) {
       character.jump();
     }
     if (keyText.equalsIgnoreCase("Slash")) {
       guntrack += 1;
       if (guntrack > weapons.length - 1) {
         guntrack = 0;
       }
     }
   }
   repaint();
 }
示例#25
0
 public void keyReleased(KeyEvent evt) {
   // set paddle speed to 0
   int key = evt.getKeyCode();
   if ((key == KeyEvent.VK_LEFT) || (key == KeyEvent.VK_RIGHT)) {
     paddle.setSpeed(0);
   }
 }
示例#26
0
    @Override
    public void keyPressed(KeyEvent evt) {
      switch (evt.getKeyCode()) {
        case KeyEvent.VK_SPACE:
          goToSelectedNode(M_OPEN);

          // f**k me dead
          EventQueue.invokeLater(
              new Runnable() {
                @Override
                public void run() {
                  resultTree.requestFocus();
                }
              });

          evt.consume();
          break;
        case KeyEvent.VK_ENTER:
          goToSelectedNode(M_OPEN);
          evt.consume();
          break;
        case KeyEvent.VK_DELETE:
          removeSelectedNode();
          evt.consume();
          break;
        default:
          break;
      }
    }
示例#27
0
 public void keyReleased(KeyEvent e) {
   int code = e.getKeyCode();
   if (code == KeyEvent.VK_SPACE) {
     AbstractButton button = (AbstractButton) e.getSource();
     button.putClientProperty(SPACEBAR_PRESSED, Boolean.FALSE);
   }
 }
        /**
         * The keyReleased event ensures that the caret-position is updated for both peers, when the
         * user moves the caret with the arrow-keys.
         */
        public void keyReleased(KeyEvent e) {
          int left = e.VK_LEFT;
          int right = e.VK_RIGHT;
          int up = e.VK_UP;
          int down = e.VK_DOWN;
          int home = e.VK_HOME;
          int end = e.VK_END;
          int A = e.VK_A;
          int kc = e.getKeyCode();

          if (kc == left
              || kc == right
              || kc == up
              || kc == down
              || kc == home
              || kc == end
              || (kc == A && e.isControlDown())) {
            if (dec == null) return;
            lc.increment();
            TextEvent cu = new CaretUpdate(area1.getCaretPosition(), lc.getTimeStamp());
            dec.sendObjectToAllPeers(cu);
            er.getEventHistoryLock().lock();
            er.getEventHistory().add(cu);
            er.getEventHistoryLock().unlock();
          }
        }
示例#29
0
  // For KeyEvents that invole keys being pressed
  public void keyPressed(KeyEvent event) {
    // Assigns the keyPressed array at event.getKeyCode() to true as the key has been pressed
    keyPressed[event.getKeyCode()] = true;

    // Calls the update positions method to update the positions of the sprites.
    updatePositions();
  }
示例#30
0
  @Override
  public void keyPressed(KeyEvent event) {

    if (event.getKeyCode() == KeyEvent.VK_ENTER) {
      onSendButtonClicked();
    }
  }