ich wollte einen taschenrechner mit 5 funktionen erstellen. ererrechnet +, -, *, /, und den größten gemeinsamen teiler. nur tauchen dann ein paar sehr seltsame fehlermeldungen auf:
die fehlermeldung sah dann so aus:
Code:
import java.awt.*;
import java.awt.event.*;
/**
*
* Beschreibung
*
* @version 1.0 vom 25.09.2007
* @author Lars Reimer
*/
public class Taschenrechner extends Frame {
// Anfang Variablen
private Checkbox radioButton1 = new Checkbox();
private Checkbox radioButton2 = new Checkbox();
private Checkbox radioButton3 = new Checkbox();
private TextField textField1 = new TextField();
private TextField textField2 = new TextField();
private TextField textField3 = new TextField();
private Checkbox radioButton4 = new Checkbox();
private Checkbox radioButton5 = new Checkbox();
private Button button1 = new Button();
// Ende Variablen
public Taschenrechner(String title) {
// Frame-Initialisierung
super(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) { System.exit(0); }
});
int frameWidth = 300;
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);
Panel cp = new Panel(null);
add(cp);
// Anfang Komponenten
button1.setBounds(232, 40, 49, 185);
radioButton1.setLabel("Addition");
cp.add(radioButton1);
radioButton2.setBounds(8, 72, 17, 17);
radioButton2.setLabel("Subtraktion");
cp.add(radioButton2);
radioButton3.setBounds(8, 96, 17, 17);
radioButton3.setLabel("Multiplikation");
cp.add(radioButton3);
source1.setBounds(8, 8, 81, 24);
source1.setText("");
cp.add(source1);
source2.setBounds(200, 8, 81, 24);
source2.setText("");
cp.add(source2);
target.setBounds(8, 240, 273, 24);
target.setText("");
cp.add(target);
radioButton4.setBounds(8, 120, 17, 17);
radioButton4.setLabel("Division");
cp.add(radioButton4);
radioButton5.setBounds(8, 144, 17, 17);
radioButton5.setLabel("Größter gemeinsamer Teiler");
cp.add(radioButton5);
button1.setBounds(232, 40, 49, 185);
button1.setLabel("GO!");
cp.add(button1);
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
button1ActionPerformed(evt);
}
});
// Ende Komponenten
setResizable(false);
setVisible(true);
}
// Anfang Ereignisprozeduren
public void button1ActionPerformed(ActionEvent evt) {
double a;
double b;
a = Double.parseDouble(source1.getText());
b = Double.parseDouble(source2.getText());
if(radioButton1 == true)
target.setText("" + (a+b));
else if(radioButton2 == true)
target.setText("" + (a-b));
else if(radioButton3 == true)
target.setText("" + (a*b));
else if(radioButton4 == true)
target.setText("" + (a/b));
else if(radioButton5 == true)
while(a != b) {
if(a<b) b=b-a;
else a=a-b;
}
target.setText("" + a);
else
target.setText("Fehler!");
}
// Ende Ereignisprozeduren
public static void main(String[] args) {
new Taschenrechner("Taschenrechner");
}
}
die fehlermeldung sah dann so aus:
Code:
Compiliere D:\Dateien\javaprogramme\taschenrechner\Taschenrechner.java mit Java-Compiler
Taschenrechner.java:103:5: 'else' without 'if'
else
^
Taschenrechner.java:104:20: <identifier> expected
target.setText("Fehler!");
^
Taschenrechner.java:104:21: illegal start of type
target.setText("Fehler!");
^
Taschenrechner.java:115:17: class, interface, or enum expected
public static void main(String[] args) {
^
Taschenrechner.java:117:3: class, interface, or enum expected
}
^
5 errors