我注意到的東西,我認爲是奇怪,這下面的代碼:Swing類中,JLabel的appearence異常
public class QuestionFour extends JFrame {
private JTextArea txta1;
private JTextField txt1;
private JButton btnSort;
private JButton btnShuffle;
private JButton btnReverse;
private JPanel pnl1;
private JLabel lbl1;
private LinkedList linkedList;
public QuestionFour() {
super();
this.setLocationRelativeTo(null);
this.setSize(500, 200);
this.setVisible(true);
this.setLayout(new FlowLayout());
txt1 = new JTextField(); // 1
lbl1 = new JLabel("Enter a number: "); // 2
this.add(lbl1);
}
public static void main(String args[]) {
QuestionFour ob = new QuestionFour();
}
}
這是存在的是,當我運行代碼的JLabel不會出現問題,但如果我註釋鍵入1作爲註釋的行,JLabel出現,我認爲這很奇怪,因爲我只實例化了TextField,但沒有將它添加到JFrame中。
有人可以向我解釋這個嗎?