当我按下运行按钮时,我的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);
}
}
答案 0 :(得分:2)
只需添加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);
}
}