Hallo ich war dabei einen eigenen kleinen Taschenrechner zu programmieren (bitte nicht die Programmierweise kritisieren bin Anfänger) und hab jetzt eine Fehlermeldung aus der ich nicht schlau werde.
und hier die fehlermeldung:
schonmal danke im vorraus und wie gesagt bitte nur auf den Fehler eingehen nicht den Rest des Programms.
Java:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
/**
*
* Beschreibung
*
* @version 1.0 vom 16.04.2016
* @author
*/
public class langeweilemachtsmöglich extends JFrame {
// Anfang Attribute
private JButton Ziffer1 = new JButton();
private JButton Ziffer2 = new JButton();
private JButton Ziffer3 = new JButton();
private JButton Ziffer4 = new JButton();
private JButton Ziffer5 = new JButton();
private JButton Ziffer6 = new JButton();
private JButton Ziffer7 = new JButton();
private JButton Ziffer8 = new JButton();
private JButton Ziffer9 = new JButton();
private JButton Ziffer0 = new JButton();
private JButton Komma = new JButton();
private JButton Rechnen = new JButton();
private JButton Plus = new JButton();
private JButton Minus = new JButton();
private JButton Mal = new JButton();
private JButton Geteilt = new JButton();
private JTextField Ergebnis = new JTextField();
private JButton Delete = new JButton();
private JButton weg = new JButton();
// Ende Attribute
double e = 0;
double c = 0;
double b = 0;
double a = 0;
int d = 7;
public langeweilemachtsmöglich(String title) {
// Frame-Initialisierung
super(title);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
int frameWidth = 366;
int frameHeight = 284;
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);
// Anfang Komponenten
Ziffer1.setBounds(16, 136, 75, 25);
Ziffer1.setText("1");
Ziffer1.setMargin(new Insets(2, 2, 2, 2));
Ziffer1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Ziffer1_ActionPerformed(evt);
}
});
cp.add(Ziffer1);
Ziffer2.setBounds(96, 136, 75, 25);
Ziffer2.setText("2");
Ziffer2.setMargin(new Insets(2, 2, 2, 2));
Ziffer2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Ziffer2_ActionPerformed(evt);
}
});
cp.add(Ziffer2);
Ziffer3.setBounds(176, 136, 75, 25);
Ziffer3.setText("3");
Ziffer3.setMargin(new Insets(2, 2, 2, 2));
Ziffer3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Ziffer3_ActionPerformed(evt);
}
});
cp.add(Ziffer3);
Ziffer4.setBounds(16, 112, 75, 25);
Ziffer4.setText("4");
Ziffer4.setMargin(new Insets(2, 2, 2, 2));
Ziffer4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Ziffer4_ActionPerformed(evt);
}
});
cp.add(Ziffer4);
Ziffer5.setBounds(96, 112, 75, 25);
Ziffer5.setText("5");
Ziffer5.setMargin(new Insets(2, 2, 2, 2));
Ziffer5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Ziffer5_ActionPerformed(evt);
}
});
cp.add(Ziffer5);
Ziffer6.setBounds(176, 112, 75, 25);
Ziffer6.setText("6");
Ziffer6.setMargin(new Insets(2, 2, 2, 2));
Ziffer6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Ziffer6_ActionPerformed(evt);
}
});
cp.add(Ziffer6);
Ziffer7.setBounds(16, 88, 75, 25);
Ziffer7.setText("7");
Ziffer7.setMargin(new Insets(2, 2, 2, 2));
Ziffer7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Ziffer7_ActionPerformed(evt);
}
});
cp.add(Ziffer7);
Ziffer8.setBounds(96, 88, 75, 25);
Ziffer8.setText("8");
Ziffer8.setMargin(new Insets(2, 2, 2, 2));
Ziffer8.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Ziffer8_ActionPerformed(evt);
}
});
cp.add(Ziffer8);
Ziffer9.setBounds(176, 88, 75, 25);
Ziffer9.setText("9");
Ziffer9.setMargin(new Insets(2, 2, 2, 2));
Ziffer9.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Ziffer9_ActionPerformed(evt);
}
});
cp.add(Ziffer9);
Ziffer0.setBounds(16, 160, 75, 25);
Ziffer0.setText("0");
Ziffer0.setMargin(new Insets(2, 2, 2, 2));
Ziffer0.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Ziffer0_ActionPerformed(evt);
}
});
cp.add(Ziffer0);
Komma.setBounds(96, 160, 75, 25);
Komma.setText(".");
Komma.setMargin(new Insets(2, 2, 2, 2));
Komma.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Komma_ActionPerformed(evt);
}
});
cp.add(Komma);
Rechnen.setBounds(176, 160, 75, 25);
Rechnen.setText("Exe");
Rechnen.setMargin(new Insets(2, 2, 2, 2));
Rechnen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Rechnen_ActionPerformed(evt);
}
});
cp.add(Rechnen);
Plus.setBounds(256, 160, 75, 25);
Plus.setText("+");
Plus.setMargin(new Insets(2, 2, 2, 2));
Plus.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Plus_ActionPerformed(evt);
}
});
cp.add(Plus);
Minus.setBounds(256, 136, 75, 25);
Minus.setText("-");
Minus.setMargin(new Insets(2, 2, 2, 2));
Minus.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Minus_ActionPerformed(evt);
}
});
cp.add(Minus);
Mal.setBounds(256, 112, 75, 25);
Mal.setText("*");
Mal.setMargin(new Insets(2, 2, 2, 2));
Mal.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Mal_ActionPerformed(evt);
}
});
cp.add(Mal);
Geteilt.setBounds(256, 88, 75, 25);
Geteilt.setText("/");
Geteilt.setMargin(new Insets(2, 2, 2, 2));
Geteilt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Geteilt_ActionPerformed(evt);
}
});
cp.add(Geteilt);
Ergebnis.setBounds(176, 56, 150, 28);
Ergebnis.setText(Text2);
Ergebnis.setHorizontalAlignment(SwingConstants.RIGHT);
cp.add(Ergebnis);
Delete.setBounds(16, 57, 75, 25);
Delete.setText("Ac");
Delete.setMargin(new Insets(2, 2, 2, 2));
Delete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Delete_ActionPerformed(evt);
}
});
cp.add(Delete);
weg.setBounds(96, 57, 75, 25);
weg.setText("Del");
weg.setMargin(new Insets(2, 2, 2, 2));
weg.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
weg_ActionPerformed(evt);
}
});
cp.add(weg);
// Ende Komponenten
setVisible(true);
} // end of public langeweilemachtsmöglich
// Anfang Methoden
String Text = "";
String Text2 = "0";
int Löschsteuerung = 0;
public static void main(String[] args) {
new langeweilemachtsmöglich("langeweilemachtsmöglich");
} // end of main
public void Ziffer1_ActionPerformed(ActionEvent evt) {
if (Löschsteuerung==1) {
a = 0;
b = 0;
c = 0;
d = 7;
Text = "";
Ergebnis.setText(Text);
Löschsteuerung = 0;
} // end of if
Text = Text + "1";
Ergebnis.setText(Text);
} // end of Ziffer1_ActionPerformed
public void Ziffer2_ActionPerformed(ActionEvent evt) {
Text = Text + "2";
Ergebnis.setText(Text);
} // end of Ziffer2_ActionPerformed
public void Ziffer3_ActionPerformed(ActionEvent evt) {
Text = Text + "3";
Ergebnis.setText(Text);
} // end of Ziffer3_ActionPerformed
public void Ziffer4_ActionPerformed(ActionEvent evt) {
Text = Text + "4";
Ergebnis.setText(Text);
} // end of Ziffer4_ActionPerformed
public void Ziffer5_ActionPerformed(ActionEvent evt) {
Text = Text + "5";
Ergebnis.setText(Text);
} // end of Ziffer5_ActionPerformed
public void Ziffer6_ActionPerformed(ActionEvent evt) {
Text = Text + "6";
Ergebnis.setText(Text);
} // end of Ziffer6_ActionPerformed
public void Ziffer7_ActionPerformed(ActionEvent evt) {
Text = Text + "7";
Ergebnis.setText(Text);
} // end of Ziffer7_ActionPerformed
public void Ziffer8_ActionPerformed(ActionEvent evt) {
Text = Text + "8";
Ergebnis.setText(Text);
} // end of Ziffer8_ActionPerformed
public void Ziffer9_ActionPerformed(ActionEvent evt) {
Text = Text + "9";
Ergebnis.setText(Text);
} // end of Ziffer9_ActionPerformed
public void Ziffer0_ActionPerformed(ActionEvent evt) {
Text = Text + "0";
Ergebnis.setText(Text);
} // end of Ziffer0_ActionPerformed
public void Komma_ActionPerformed(ActionEvent evt) {
Text = Text + ".";
Ergebnis.setText(Text);
} // end of Komma_ActionPerformed
public void Plus_ActionPerformed(ActionEvent evt) {
double a = Double.parseDouble(Text);
e = a;
Text = "";
Ergebnis.setText(Text);
d = 0;
} // end of Plus_ActionPerformed
public void Minus_ActionPerformed(ActionEvent evt) {
double a = Double.parseDouble(Text);
e = a;
Text = "";
Ergebnis.setText(Text);
d = 1;
} // end of Minus_ActionPerformed
public void Mal_ActionPerformed(ActionEvent evt) {
double a = Double.parseDouble(Text);
e = a;
Text = "";
Ergebnis.setText(Text);
d = 2;
} // end of Mal_ActionPerformed
public void Geteilt_ActionPerformed(ActionEvent evt) {
double a = Double.parseDouble(Text);
e = a;
Text = "";
Ergebnis.setText(Text);
d = 3;
} // end of Geteilt_ActionPerformed
public void Delete_ActionPerformed(ActionEvent evt) {
double a = 0;
double b = 0;
double c = 0;
double e = 0;
Text = "";
Text2 = "0";
Ergebnis.setText(Text2);
} // end of Delete_ActionPerformed
public void Rechnen_ActionPerformed(ActionEvent evt) {
double b = Double.parseDouble(Text);
if (d==0) {
c = e + b;
} // end of if
if (d==1) {
c = e - b;
} // end of if
if (d==2) {
c = e * b;
} // end of if
String Text = (new Double(c).toString());
Ergebnis.setText(Text);
if (d==3) {
c = e / b;
if (b==0) {
String Text2 = (new Double(c).toString());
Ergebnis.setText(Text2 + " !Kann nicht durch 0 teilen!");
} // end of if
} // end of if
Löschsteuerung = 1;
} // end of if
} // end of Rechnen_ActionPerformed
public void weg_ActionPerformed(ActionEvent evt) {
int Textlänge = 0;
Text = Ergebnis.getText();
Textlänge = Text.length();
Text = Text.substring(0,f-1);
Ergebnis.setText(Text);
} // end of weg_ActionPerformed
// Ende Methoden
} // end of class langeweilemachtsmöglich
und hier die fehlermeldung:
Code:
Compiliere F:\langeweilemachtsmöglich.java mit Java-Compiler
langeweilemachtsmöglich.java:385:12: error: class, interface, or enum expected
public void weg_ActionPerformed(ActionEvent evt) {
^
langeweilemachtsmöglich.java:387:5: error: class, interface, or enum expected
Text = Ergebnis.getText();
^
langeweilemachtsmöglich.java:388:5: error: class, interface, or enum expected
Textlänge = Text.length();
^
langeweilemachtsmöglich.java:389:5: error: class, interface, or enum expected
Text = Text.substring(0,f-1);
^
langeweilemachtsmöglich.java:390:5: error: class, interface, or enum expected
Ergebnis.setText(Text);
^
langeweilemachtsmöglich.java:391:3: error: class, interface, or enum expected
} // end of weg_ActionPerformed
^
6 errors
schonmal danke im vorraus und wie gesagt bitte nur auf den Fehler eingehen nicht den Rest des Programms.