私は、特定の形状の面積を計算するための小さなプログラムを作ろうとしています。 ユーザーは、テキストフィールドを使用して入力を行うことができます(図形の高さやものなど)。彼はボタンを押す必要があり、価格は印刷されるはずです。 しかしそれは現れません。JAVA JTextFieldが表示されません
コード:
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Rechner extends JFrame implements ActionListener{
private static JButton button1;
private static JButton button2;
private static JButton button3;
private static JButton button4;
private static JTextField numberField;
private JPanel jpanel;
public Rechner(String titel){
super(titel);
jpanel = new JPanel();
numberField = new JTextField(1500);
add(numberField, BorderLayout.CENTER);
button1 = new JButton("Rechteck");
button1.setBounds(10, 10, 150, 30);
button1.addActionListener(this);
add(button1);
button2 = new JButton("Dreieck");
button2.setBounds(170, 10, 150, 30);
button2.addActionListener(this);
add(button2);
button3 = new JButton("Trapez");
button3.setBounds(330, 10, 150, 30);
button3.addActionListener(this);
add(button3);
button4 = new JButton("Parallelogramm");
button4.setBounds(490, 10, 150, 30);
button4.addActionListener(this);
add(button4);
setResizable(false);
}
public static void main(String[] args) {
Rechner frame = new Rechner("Menu");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(660, 400);
frame.setLayout(null);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == button1){
System.out.println("fff");
}
String numberStr = numberField.getText();
}
}
私は[尋ねる]と[ツアー]にリンクして帽子を得るつもりです。 –
私は 'swing'を使っていませんが、このクラスは' ActionListener'を実装しているので、 'actionPerformed'はそのリスナークラスの一部であると仮定します。それは '@ Override'であってはなりませんか? –
正確に表示されるものは何ですか?あなたの 'actionPerformed'は単に" fff "を標準出力に出力します(そしてすぐに破棄されるローカル変数に値を割り当てます)。あなたはそれが何を期待していますか? – RealSkeptic