Java,swing从另一个类打开新的JFrame

Java,swing从另一个类打开新的JFrame,java,swing,jframe,Java,Swing,Jframe,我有一段代码: public class GUI extends JFrame { private PlaneUI planeui; public GUI(PlaneUI planeui) { this.planeui = planeui; } //We have put the code that creates the GUI inside a method public GUI() { start(); planeui.display(); } ... 这只是一个

我有一段代码:

public class GUI extends JFrame {
private PlaneUI planeui;

public GUI(PlaneUI planeui) {
    this.planeui = planeui;
}

//We have put the code that creates the GUI inside a method
public GUI() {
   start();
   planeui.display();
} ...
这只是一个测试,我需要方法“planeui.display”在程序启动时起作用,以及已经起作用的方法“start();”

public final class PlaneUI extends JFrame {

public void display() {
    //Creates a new JPanel object
   JPanel panelStart = new JPanel();
   getContentPane().add(panelStart);

   //Changing the default layout from Flowlayout to absolute
   panelStart.setLayout(null);

   setTitle("Reservationer"); //Sets the window title
   setSize(236, 256); //Sets the default size of the window
   setLocationRelativeTo(null); //Start location of the window (centered)
   setDefaultCloseOperation(EXIT_ON_CLOSE); //Exits the window
}
}

我已经导入了所需的库,我觉得问题在于一个对象没有正确创建,因为我得到了一个nullpointerexception。我试着用main方法运行这个planeUI类,它工作正常。我就是不能让它这样工作

在函数
PlaneUI.display()
中添加最后一行
setVisible(true)
,因为您在函数
PlaneUI.display()中添加了所有内容,但没有显示任何内容
因为在函数
PlaneUI.display()中添加所有内容但不显示任何内容

添加最后一行
setVisible(true)
因为在函数
PlaneUI.display()中添加所有内容但不显示任何内容

添加最后一行
setVisible(true)
因为您添加了所有内容,但没有显示任何内容

您必须将其添加到
display()
方法中:

setVisible(true)


否则,您所要做的就是设置JFrame的所有方面并向其中添加JPanel。之后必须使其可见。

必须将其添加到
display()
方法中:

setVisible(true)


否则,您所要做的就是设置JFrame的所有方面并向其中添加JPanel。之后必须使其可见。

必须将其添加到
display()
方法中:

setVisible(true)


否则,您所要做的就是设置JFrame的所有方面并向其中添加JPanel。之后必须使其可见。

必须将其添加到
display()
方法中:

setVisible(true)


否则,您所要做的就是设置JFrame的所有方面并向其中添加JPanel。之后必须使其可见。

有关使用多个框架的信息,请参阅。除了将面板设置为可见外,面板中是否有任何组件?根据。1) 通过调用setLayout(null)将容器的布局管理器设置为null。2) 为容器的每个子级调用组件类的setbounds方法。3) 调用组件类的重绘方法。
EXIT\u ON\u CLOSE
将终止JVM,因此当您关闭
PlaneUI
时,它将退出您的应用程序,以使用多个帧。除了将面板设置为可见外,面板中是否有任何组件?根据。1) 通过调用setLayout(null)将容器的布局管理器设置为null。2) 为容器的每个子级调用组件类的setbounds方法。3) 调用组件类的重绘方法。
EXIT\u ON\u CLOSE
将终止JVM,因此当您关闭
PlaneUI
时,它将退出您的应用程序,以使用多个帧。除了将面板设置为可见外,面板中是否有任何组件?根据。1) 通过调用setLayout(null)将容器的布局管理器设置为null。2) 为容器的每个子级调用组件类的setbounds方法。3) 调用组件类的重绘方法。
EXIT\u ON\u CLOSE
将终止JVM,因此当您关闭
PlaneUI
时,它将退出您的应用程序,以使用多个帧。除了将面板设置为可见外,面板中是否有任何组件?根据。1) 通过调用setLayout(null)将容器的布局管理器设置为null。2) 为容器的每个子级调用组件类的setbounds方法。3) 调用组件类的重绘方法。
EXIT\u ON\u CLOSE
将终止JVM,因此当您关闭
PlaneUI
时,它将退出您的应用程序