如何解决通过 JLabel 将图像添加到 JWindow 未出现在屏幕上
我正在尝试为我正在开发的风险游戏创建启动画面。出于某种原因,即使我将它添加到 Jwindow 中也不会出现启动画面,我会很感激能看到我看不到的东西的专家眼睛。提前致谢
/new jWindow as it is better for splash screen as there is no borders
JWindow window = new JWindow();
ImageIcon imageIcon = new ImageIcon("Images/riskimage.jpg");
JLabel label = new JLabel(imageIcon);
window.getContentPane().add(label);
window.setBounds(200,200,100);
window.setVisible(true);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printstacktrace();
}
window.setVisible(false);
// title of frame
JFrame frame = new JFrame("Risk");
//Creating a text field
JTextField textField = new JTextField(20);
frame.add(textField,BorderLayout.soUTH);
JLabel welcome = new JLabel("");
welcome.setFont (welcome.getFont ().deriveFont (20.0f));
welcome.setText("Please Enter name for Player 1 in the text Box at the bottom");
frame.add(welcome,BorderLayout.norTH);
//action listener listens for enter key
textField.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
//checks if player Ones name is set and sets player Twos name aswell
if (!playerOneNameSet)
{
playerOneName = textField.getText();
textField.setText("");
welcome.setText("Please Enter name for Player 2 in the text Box at the bottom");
playerOneNameSet = true;
}
else
{
playerTwoName = textField.getText();
textField.setText("");
//turning the nameSetUpDone to true as we are finished setting up the names
nameSetUpDone = true;
// repainting as we want to update the screen
frame.getContentPane().repaint();
welcome.setText("Player One:" + playerOneName +" Player Two:" + playerTwoName + " Awaiting player one move");
}
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。