为什么这不起作用 - JOptionPane - 读取整数值

时间:2014-05-29 18:31:51

标签: java swing command joptionpane

所以我正在处理我的项目,我想实现诸如" / heal value"等命令。但是当我调试这段代码时,它打印出我在控制台中输入的内容但没有给出效果?我这样做了吗?

这是完整的课程

import javax.swing.JOptionPane;

public class Commands {
  //Variables
  String command; //The variable that controls each command
  int[] blockName; //Each block is a int[]
  String number; //The block stack amount number - you only need to worry about /heal
  String amount; //The amount of health you want to give the player
  public static boolean open = false; //Detects whether the command window is open

  public Commands() {
  }

  public void tick() {
    if(open) {
      //create a JOptionPane so you can enter a command
      command = JOptionPane.showInputDialog("Please Enter Command");
      //Should check to see if command matchs any of the commands
      loadCommands();
      //prints the command input
      if(command != "" || command != null) { 
        System.out.println(Component.username + ": " + command + " Called");
      }
      //then sets open to false so that the JOptionPane. You dont need to worry about this
      open = false;
    }
  }

  public void loadCommands() {
    //This is the list of commands
    try {
      //This is the /give command
      if(command.equals("/give " + blockName + " " + number)) {
        Component.inventory.holdingID = blockName;
        Component.inventory.holdingIDStack = Integer.parseInt(number);
        System.out.println(command);
      }

      //This is the /heal command I am using to debug
      if(command.equals("/heal " + amount)) {
        Component.character.health += Integer.parseInt(amount);
        System.out.println(command);
      }
      //This is the/kill command to kill the play this too does not work?
      if(command.equals("/kill ")) {
        Component.character.hurt(999);
        System.out.println(command);
      }
    } catch(NullPointerException e) { 
      /*This is here because without it a NullPointerException appears in the console and the JOptionPane can't be closed */
    }
  }

/* How I know it doesn't work is because it doesnt print out the command twice like
 * it is meant to...
 */

}

0 个答案:

没有答案