[英]Java Gui components do not appear in the JFrame
i have a strange problem which may a problem with eclipse that i use: 我有一个奇怪的问题,可能是我使用的日食有问题:
i want to programm a calculator but the components which should appear in the Jframe, are not there! 我想对计算器进行编程,但是应该出现在Jframe中的组件不存在! The textfield do not appears until i click on it and the button come out when i go over it with the mouse pointer... 直到我单击它,文本字段才会出现,而当我使用鼠标指针将其移过该按钮时,该按钮就会出现...
here's my code: 这是我的代码:
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);
}
And here is my main class: 这是我的主要课程:
package calculator;
public class ExecuteKlasse {
public static void main(String[] args) {
MeinTaschenrechner cc=new MeinTaschenrechner();
}
}
You cannot make setVisible(true); 您不能使setVisible(true); your first line of code. 您的第一行代码。 Add setVisible(true); 添加setVisible(true); as the last line in your constructor. 作为构造函数的最后一行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.