public class Primary extends JFrame {
public Primary(String title) {
super(title);
JLabel Label1 = new JLabel("hello");
Container c= getContentPane();
c.add(Label1, new AbsoluteConstraints(117,15));
}
}
我已經寫了這段代碼,在主類中調用了runnable JFrame
。 儘管沒有顯示錯誤,但在編譯時出現很多錯誤。 錯誤很長,但這裏是它的一個樣本:Java Swing錯誤= S AbsoluteConstraints
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: cannot add to layout: constraint must be a string (or null) at java.awt.BorderLayout.addLayoutComponent(BorderLayout.java:426) at javax.swing.JRootPane$1.addLayoutComponent(JRootPane.java:531) at java.awt.Container.addImpl(Container.java:1120)"
請學習java命名約定並堅持使用它們。 – kleopatra