从一个类获取字符串以写入前屏幕类

时间:2012-04-06 10:35:30

标签: java

我正在建立一个空中交通管制系统,它会产生随机数量的燃料以及随机数量的飞机。我完成了这两个元素,但问题是,在输出框中它显示并完美地工作。我的问题是,我告诉它,如果没有飞机进来调用字符串没有飞机,如果有飞机那么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");
      }
}
}

任何人都可以建议如何让名字显示在屏幕上,这样我就可以尝试将它们添加到实际机场课程的队列中。

1 个答案:

答案 0 :(得分:0)

我认为Observer模式可能适合您。在Java中,这是通过ObserverObservable实现的。