Components won't show up on JFrame

134 views Asked by At

This question is a repeat, but the other answers have not fixed this error. The components I am putting into my JFrame aren't showing up. I have been working with JFrame for a while now and as far as I can tell I am making no mistakes.

My Code:

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

        }  
    }
1

There are 1 answers

0
Madhawa Priyashantha On BEST ANSWER

you haven't add content yet to the frame.you have created contentPane but haven't add it to jframe .add it before call setVisible()

this.setContentPane(contentPane);
setVisible(true);