Siehe Überschrift...
Kurz zum Inhalt: Ich versuche ein Programm zu erstellen, in das eine Nummer eingegeben werden kann und diese überprüft/verglichen wird mit Hilfe von if-else und einer internen Variabel "r = 123". Das Ausgabefeld gibt dann aus, ob die eingegebene Nummer "a" mit "r" richitg oder falsch ist.
Hier der Quellcode und darunter die Fehlermeldung:
Compiler-Fehler:
Kurz zum Inhalt: Ich versuche ein Programm zu erstellen, in das eine Nummer eingegeben werden kann und diese überprüft/verglichen wird mit Hilfe von if-else und einer internen Variabel "r = 123". Das Ausgabefeld gibt dann aus, ob die eingegebene Nummer "a" mit "r" richitg oder falsch ist.
Hier der Quellcode und darunter die Fehlermeldung:
Java:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class codeschloss extends JFrame {
private JLabel ueberschrift = new JLabel();
private JLabel Jeingabe = new JLabel();
private JButton check = new JButton();
private JLabel Jausgabe = new JLabel();
private JTextField ausgabe = new JTextField();
public codeschloss(String title) {
super(title);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
int frameWidth = 297;
int frameHeight = 300;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2;
setLocation(x, y);
setResizable(false);
Container cp = getContentPane();
cp.setLayout(null);
ueberschrift.setBounds(8, 8, 267, 41);
ueberschrift.setText("Bitte Zahlencode eingeben!");
ueberschrift.setOpaque(false);
ueberschrift.setHorizontalTextPosition(SwingConstants.CENTER);
ueberschrift.setHorizontalAlignment(SwingConstants.CENTER);
ueberschrift.setFont(new Font("Calibri", Font.BOLD, 18));
cp.add(ueberschrift);
cp.setBackground(new Color(0xC0C0C0));
Jeingabe.setBounds(8, 64, 51, 33);
Jeingabe.setText("Eingabe:");
Jeingabe.setBackground(Color.WHITE);
Jeingabe.setOpaque(true);
Jeingabe.setHorizontalAlignment(SwingConstants.CENTER);
cp.add(Jeingabe);
check.setBounds(8, 104, 265, 33);
check.setText("C H E C K !");
check.setMargin(new Insets(2, 2, 2, 2));
check.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
check_ActionPerformed(evt);
}
});
check.setBackground(Color.RED);
check.setForeground(Color.WHITE);
check.setFont(new Font("Calibri", Font.BOLD + Font.ITALIC, 24));
cp.add(check);
Jausgabe.setBounds(8, 144, 57, 33);
Jausgabe.setText("Ausgabe:");
Jausgabe.setHorizontalAlignment(SwingConstants.CENTER);
Jausgabe.setBackground(Color.WHITE);
Jausgabe.setOpaque(true);
cp.add(Jausgabe);
ausgabe.setBounds(72, 144, 201, 33);
ausgabe.setHorizontalAlignment(SwingConstants.CENTER);
cp.add(ausgabe);
eingabe.setHorizontalAlignment(SwingConstants.CENTER);
setVisible(true);
}
public static void main(String[] args) {
new codeschloss("codeschloss");
}
public void check_ActionPerformed(ActionEvent evt) {
int a = eingabe.getInt();
int r = 123;
if (a==r) {
ausgabe.setText("richtig!");
} else {
ausgabe.setText("falsch!");
}
}
}
Code:
Compiliere "C:\Users\PC\Desktop\Codeschloss\codeschloss.java" mit Java-Compiler
codeschloss.java:74:5: error: cannot find symbol
eingabe.setHorizontalAlignment(SwingConstants.CENTER);
^
symbol: variable eingabe
location: class codeschloss
codeschloss.java:87:13: error: cannot find symbol
int a = eingabe.getInt();
^
symbol: variable eingabe
location: class codeschloss
2 errors