通过 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 (将#修改为@)