我正在尝试为我正在开发的风险游戏创建启动画面。出于某种原因,即使我将它添加到 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, 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");
}
}
});