简体   繁体   English

Java:为什么不显示此JFrame按钮?

[英]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() . 您忘记调用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. 虽然,因为您是JFrame的子类,我还是建议在构造函数中完成大部分工作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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