Java按钮未显示(GUI)

时间:2018-06-13 17:09:31

标签: java class user-interface interface frame

在处理比以前更大的项目时,我一直在寻找一个很好的方法来奠定良好的基础。如果我把所有内容都写在主要内容中就可以了在做这样的课程时,框架可以工作但是我添加的按钮不想出现:

//主

package taxsystem;

import java.awt.*;
import javax.swing.*;

public class Taxmain
{
    public mainFrame mf;
    public Interface gui;

    public void startApplication()
    {
        mf = new mainFrame();
        mf.startApp();
        gui = new Interface();
        gui.makeLayout();
    }

    public static void main(String[] args)
    {
        Taxmain tm = new Taxmain();
        tm.startApplication();
    }
}

//实际的框架

package taxsystem;


import java.awt.*;
import javax.swing.*;

public class mainFrame extends JFrame
{
    public void startApp()
    {
        setResizable(false);
        setVisible(true);
        setSize(720,340);
        setLocation(0,0);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setBackground(Color.WHITE);

        setTitle("Tax Handler");
    }
}

//布局(我创建没有出现的按钮)

package taxsystem;


import java.awt.*;
import javax.swing.*;

public class Interface extends JPanel
{
    Taxmain mc;
    public JButton testButton;

    public void makeLayout()
    {
        testButton = new JButton();
        testButton.setText("Printer");

        testButton.setFont(new Font("verdana", Font.ITALIC, 16));
        testButton.setForeground(Color.BLACK);

        testButton.setFocusable(false);
        testButton.setSize(new Dimension(150, 40));
        testButton.setLocation(10, 10);
        this.setLayout(null);
        this.add(testButton);   
    }
}

目前看起来像这样:https://gyazo.com/fad5dbca6c59905faea0a8ac1fbd424a

在此先感谢,无论如何我还能改进我到目前为止的代码吗?

1 个答案:

答案 0 :(得分:0)

您需要将JPanel添加到JFrame

SELECT *
FROM person
WHERE my_schema.isEligible(?, value) > -1