gpt4 book ai didi

java - JFrame 未执行! (Eclipse 编辑器)

转载 作者:行者123 更新时间:2023-12-02 03:26:49 25 4
gpt4 key购买 nike

当我按下运行按钮时,我的 JFrame 没有执行,甚至没有显示。我确信我的代码是正确的(请检查),我猜这可能是 Eclipse Bug。我们将不胜感激!

Eclipse 版本:Neon

操作系统:Ubuntu Linux 16.04 LTS

代码:

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;

public class CreateServer {

public static JFrame start= new JFrame("TRDServerCreator");

public static void main(String[] args)
{
CreateServer.startwin();
}

public static void startwin ()
{
start.setSize(500,500);
start.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
start.setLocationRelativeTo(null);
start.setResizable(false);

JPanel cont= new JPanel();
start.add(cont);

JLabel n1=new JLabel("Thank you for choosing TRD Server Creator");
n1.setVisible(true);
JLabel n2=new JLabel("Pls select the Verison of your New Server");
n2.setVisible(true);
cont.add(n1,n2);
}

}

最佳答案

只需添加start.setVisible(true);

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;

public class CreateServer {

public static JFrame start= new JFrame("TRDServerCreator");

public static void main(String[] args)
{
CreateServer.startwin();
}

public static void startwin ()
{
start.setSize(500,500);
start.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
start.setLocationRelativeTo(null);
start.setResizable(false);

JPanel cont= new JPanel();
start.add(cont);

JLabel n1=new JLabel("Thank you for choosing TRD Server Creator");
n1.setVisible(true);
JLabel n2=new JLabel("Pls select the Verison of your New Server");
n2.setVisible(true);
cont.add(n1,n2);

start.setVisible(true);

}
}

关于java - JFrame 未执行! (Eclipse 编辑器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38732905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com