[英]My GUI does not print anything at all
MyFrame(){
String titel = "Rezept";
JLabel label = new JLabel(titel);
JButton abutton = new JButton("Abbrechen");
JButton sbutton = new JButton("Speichern");
JPanel jp1 = new JPanel();
jp1.setLayout(new FlowLayout(FlowLayout.CENTER));
jp1.add(label);
JPanel jp2 = new JPanel();
jp2.setLayout(new GridLayout(1,2));
jp2.add(abutton);
jp2.add(sbutton);
setLayout(new BorderLayout());
setSize(300,500);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
add(jp1, BorderLayout.NORTH);
add(jp2, BorderLayout.SOUTH);
}
public static void main(String[]args){
new MyFrame();
}
I just don't get it.我只是不明白。 When I run this GUI it doesn't print out anything at all.当我运行这个 GUI 时,它根本不打印任何东西。
I only get an empty frame.我只得到一个空框架。 What am I doing wrong here?我在这里做错了什么?
(Code is in "MyFrame extends JFrame" class) (代码在“MyFrame extends JFrame”类中)
you will never see anything if you call the method setVisible(true);
如果你调用setVisible(true);
方法,你将永远看不到任何东西setVisible(true);
before adding the JPanels...在添加 JPanels 之前...
change the order to something like:将顺序更改为:
add(jp1, BorderLayout.NORTH);
add(jp2, BorderLayout.SOUTH);
setVisible(true);
after that you should see something like之后你应该看到类似的东西
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.