[英]Components won't show up on JFrame
這個問題是重復的,但其他答案並未解決此錯誤。 我放入JFrame的組件沒有顯示。 我已經使用JFrame已有一段時間了,據我所知,我沒有犯錯。
我的代碼:
public void Toutrial_start1()
{
Container contentPane = new Container();
setSize(800,500);
setLocation(100,100);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("Wizard101");
setResizable(false);
tou1 = new JLabel();
tou1.setBounds(0,0, 800, 500);
tou1.setIcon(t1);
but = new JButton();
but.setBounds(100,100, 200, 200);
but.addActionListener(this);
but.setIcon(t1);
contentPane.add(but);
contentPane.add(tou1);
setVisible(true);
SchoolDecider();
genderDecider();
nameDecider();
playerStats.Stats();
}
@Override
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
}
}
您尚未向框架添加內容。您已經創建了contentPane
但尚未將其添加到jframe。請在調用setVisible()
之前添加它
this.setContentPane(contentPane);
setVisible(true);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.