Вопрос

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! 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); your first line of code. Add setVisible(true); as the last line in your constructor.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top