我正在创建一个空中交通管制系统,它会生成随机数量的燃料和随机数量的飞机。我已经完成了这两个元素,但问题是,在输出框中,它都显示并完美运行。我的问题是我要告诉它,如果没有飞机进来就调用字符串 no planes,如果有飞机,那么 KLM。我无法让它用所有前端写入主类。
当我使用 Netbeans 拖放前端时,我已经编辑了屏幕中的一些编码:
enter public void StartSimulation()
{
Start pointer = new Start();
Plane incoming = new Plane();
//Needs a condition in here that checks if the plane and fuel has been
//Generated and also loop to keep up with the constant generated planes and fuel
jTextArea1.setText(incoming.planeName);
我试过条件如下:
if (incoming.nextPlaneLanding != 167)
这会在输出框中一遍又一遍地生成第一件事。我也尝试在平面类中设置一个布尔值,但同样,即使在它周围有以下条件,它也没有任何效果。if (incoming.completed = true)
这是我在飞机课上的东西:
class Plane
extends TimerTask
{
public int nextPlaneLoop = 0;
public int planes;
public int fuel;
public String planeName;
@Override
public void run()
{
if(nextPlaneLoop <=167)
{
//Currently only running 1 or 0 planes...
planes = (int) (Math.random()*((2-1)+1));
System.out.println("Random generated plane amount: "+planes);
System.out.println("Method called, one whole day loop");
//Adds to the plane in the airspace loop
nextPlaneLoop++;
System.out.println("Loop incrementing: "+nextPlaneLoop);
if(planes == 0)
{
System.out.println("No fuel is required as no planes are coming in");
planeName = "No incoming plane";
System.out.println("Planes name is: "+planeName);
System.out.println(" ");
}
else
{
//Amount of fuel
fuel = 30 + (int)(Math.random()*((120-30)+1));
System.out.println("Random fuel: "+fuel);
planeName = "KLM AirFrance";
System.out.println("Planes name is: "+planeName);
System.out.println(" ");
}
}
else
{
this.cancel();
System.out.println("Not in loop any more. End of day");
}
}
}
任何人都可以建议必须如何将名称显示在屏幕上,以便我可以尝试将它们添加到实际机场类的队列中。