简体   繁体   中英

Java: Why isn't this JFrame button displaying?

Basically, all i wan't is for this button to display. It was working in another program I had earlier but it doesn't seem to be working in this one and i have no idea why. If anyone could help that would be great.

public void fixtureList()
{
    JButton editButton;

    setLayout(null);

    editButton = new JButton("Edit");
    editButton.setBounds(200, 200, 100, 100);
    add(editButton);

}

public void loginPanel()
{
    setLayout(null);

    JButton loginButton;

    loginButton = new JButton("Login");
    loginButton.setBounds(10, 10, 100, 100);
    add(loginButton);
    loginButton.addActionListener(new ActionListener()
    {

        public void actionPerformed(ActionEvent e)
        {
            //Execute when button is pressed
            fixtureList();
            System.out.println("Loading the fixtures screen");
        }

    });

}

You forget to call loginPanel() . Try:

    Main window = new Main();

    window.setTitle("PE Fixtures v1.0");
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.loginPanel();
    window.setSize(250, 430);
    window.getContentPane().setBackground(new Color(53, 56, 64));
    window.setVisible(true);

Although, because you are subclassing JFrame , I would suggest doing most of that work in the constructor.

您需要在main方法中调用loginPanel()方法,该方法目前尚未使用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM