当我运行它时,我在框架上插入的东西不存在

时间:2016-03-15 07:34:32

标签: java swing user-interface jbutton frame

我试图制作游戏。 我有一个框架,并在框架上插入jbutton jlabel jtextfield,框架有一个背景。 但现在它没有出现。 为什么没有按钮等可见?你能解决这些代码吗?

public class NewPlayer extends JFrame {

    public NewPlayer() {

        JLabel backGround = new JLabel(new ImageIcon("images\\fiha2taban2.png"));
        setTitle("FiHa");
        setSize(750, 550);
        getContentPane().add(backGround);
        setLocationRelativeTo(null); // Center the frame
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
        setResizable(false);
        setIconImage(Toolkit.getDefaultToolkit().getImage("images\\iconfh.png"));

        Color renk=new Color(255,250,155);

        // Create two labels and set their components
        JLabel label1= new JLabel("NEW PLAYER !");
        label1.setBounds(220,200,300,40);
        this.add(label1);
        label1.setFont(new Font("Times New Roman", Font.BOLD , 40));

        JLabel label2= new JLabel("Please enter your name: ");
        label2.setBounds(270,290,249,40);
        this.add(label2);
        label2.setFont(new Font("Times New Roman", Font.BOLD , 20));

        // Create a text field and set its components
        JTextField txtField = new JTextField("", 20);
        txtField.setBounds(220,335,300,40);
        this.add(txtField);
        txtField.setFont(new Font("Times New Roman", Font.BOLD , 16));

        // Create a button and set its components
        JButton button1 = new JButton("OKAY");
        button1.setBounds(315,396,110,40);
        this.add(button1);
        button1.setFont(new Font("Times New Roman", Font.BOLD , 16));
        button1.setBackground(renk);
        }
    }
}

0 个答案:

没有答案