Java:如何在对象到达之前检查它将到达的位置

Java:如何在对象到达之前检查它将到达的位置,java,object,Java,Object,我所使用的代码部分有一个对话框,要求用户输入一定数量的单位,并要求对象递增输入的单位但是,如果单位数量的增加会导致对象的y位置=0,则会弹出警报,对象不会移动。我有一些东西可以工作,但只有在物体完成它的旅程之后 这就是我到目前为止所做的: /* * Prompts the user to enter the number of units they want the * rocket to move upwards. * * If the number

我所使用的代码部分有一个对话框,要求用户输入一定数量的单位,并要求对象递增输入的单位
但是,如果单位数量的增加会导致对象的y位置=0,则会弹出警报,对象不会移动。我有一些东西可以工作,但只有在物体完成它的旅程之后

这就是我到目前为止所做的:

   /*
    * Prompts the user to enter the number of units they want the  
    * rocket to move upwards.
    * 
    * If the number the units provided would cause the tip of the  
    * capsule to go past the top of the Graphical Display, the user 
    * is informed via a dialogue box that the rocket will not launch.  
    * 
    * Otherwise the rocket launches as required. 
    */
   public void launch()
   {
      String inputNumString;
      int inputNum;
      inputNumString = OUDialog.request("Please Enter Number of Units You Wish the Rocket to Ascend");
      inputNum = Integer.parseInt(inputNumString);
      this.ignition();
      this.animateRocket(inputNum);
      this.getCapsule().getYPos();
      if (getCapsule().getYPos() <= 0) 
      {
         OUDialog.alert("Rocket Will Not Launch");



      }

   }
/*
*提示用户输入所需的单位数
*火箭向上移动。
* 
*如果提供的装置数量过大,则会导致
*要通过胶囊顶部的图形显示,用户
*通过对话框通知火箭不会发射。
* 
*否则火箭将按要求发射。
*/
公开发售()
{
字符串输入numstring;
int-inputNum;
inputNumString=OUDialog.request(“请输入您希望火箭上升的单位数”);
inputNum=Integer.parseInt(inputNumString);
这是点火开关();
这个.animateRocket(inputNum);
这个.getCapsule().getYPos();

if(getCapsule().getYPos()
if(getCapsule().getYPos()-inputNum我不知道这些方法是做什么的,但是您应该将逻辑更改为这样

 public void launch()
   {
      String inputNumString;
      int inputNum;
      inputNumString = OUDialog.request("Please Enter Number of Units You Wish the Rocket to Ascend");
      inputNum = Integer.parseInt(inputNumString);
      this.ignition();
      // calculate new position here
      calculateNewPosition();
      if (getCapsule().getYPos() <= 0) {
         OUDialog.alert("Rocket Will Not Launch");
      } else {
         this.animateRocket(inputNum);
      }

   }
public void launch()
{
字符串输入numstring;
int-inputNum;
inputNumString=OUDialog.request(“请输入您希望火箭上升的单位数”);
inputNum=Integer.parseInt(inputNumString);
这是点火开关();
//在此计算新位置
计算位置();

如果(getCapsule().getYPos()提示:不要问/思考非常高级别的问题,你需要从变量、坐标等方面思考。对不起,没有,还没有做到。仍然没有警告