繁体   English   中英

Java Gui组件未出现在JFrame中

[英]Java Gui components do not appear in the JFrame

我有一个奇怪的问题,可能是我使用的日食有问题:

我想对计算器进行编程,但是应该出现在Jframe中的组件不存在! 直到我单击它,文本字段才会出现,而当我使用鼠标指针将其移过该按钮时,该按钮就会出现...

这是我的代码:

package calculator;

import java.awt.Font;

import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JButton;

public class MeinTaschenrechner extends JFrame {

    JTextField textField;
    JButton button1;

    public MeinTaschenrechner() {

        setVisible(true);
        setSize(300, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        setTitle("Taschenrechner");
        setResizable(false);
        setLayout(null);


        textField=new JTextField("0");
        textField.setBounds(5, 10, 285, 50);
        Font font=textField.getFont().deriveFont(Font.PLAIN,30);
        textField.setFont(font);
        add(textField);
//      addingNumberButtons();
        button1=new JButton("1");
        button1.setBounds(5, 65, 75, 65);
        add(button1);
    }

这是我的主要课程:

package calculator;

public class ExecuteKlasse {

    public static void main(String[] args) {

        MeinTaschenrechner cc=new MeinTaschenrechner();

    }

}

您不能使setVisible(true); 您的第一行代码。 添加setVisible(true); 作为构造函数的最后一行。

暂无
暂无

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

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