Hallo,
habe heute einen Taschenrechner programmiert. Am anfang hat es einwandfrei funktioniert, doch seit kurzem sind sehr viele Fehler sichtbar. Ich poste mal die Programmcode:
hier die Fehlermeldungen als Bild:
habe heute einen Taschenrechner programmiert. Am anfang hat es einwandfrei funktioniert, doch seit kurzem sind sehr viele Fehler sichtbar. Ich poste mal die Programmcode:
Java:
public class Calculator extends javax.swing.JFrame {
//Varibales
double plusminus;
double firstDouble;
double secondDouble;
double totalDouble;
//to check for button clicks
int plusClick;
int minusClick;
int malClick;
int geteiltClick;
int dezimalClick;
/** Creates new form Calculator */
public Calculator() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jTabbedPane1 = new javax.swing.JTabbedPane();
jPanel1 = new javax.swing.JPanel();
display = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
jButton8 = new javax.swing.JButton();
jButton9 = new javax.swing.JButton();
plus = new javax.swing.JButton();
minus = new javax.swing.JButton();
mal = new javax.swing.JButton();
jButton13 = new javax.swing.JButton();
clear = new javax.swing.JButton();
dezimal = new javax.swing.JButton();
geteilt = new javax.swing.JButton();
posneg = new javax.swing.JButton();
gleich = new javax.swing.JButton();
label1 = new java.awt.Label();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Ismail & Hasret");
setBackground(new java.awt.Color(0, 0, 0));
jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
display.setEditable(false);
display.setFont(new java.awt.Font("Arial", 1, 18));
display.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
displayActionPerformed(evt);
}
});
jButton1.setFont(new java.awt.Font("Arial", 1, 18));
jButton1.setText("1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setFont(new java.awt.Font("Arial", 1, 18));
jButton2.setText("3");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setFont(new java.awt.Font("Arial", 1, 18));
jButton3.setText("2");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton4.setFont(new java.awt.Font("Arial", 1, 18));
jButton4.setText("4");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jButton5.setFont(new java.awt.Font("Arial", 1, 18));
jButton5.setText("5");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
jButton6.setFont(new java.awt.Font("Arial", 1, 18));
jButton6.setText("6");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});
jButton7.setFont(new java.awt.Font("Arial", 1, 18));
jButton7.setText("7");
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton7ActionPerformed(evt);
}
});
jButton8.setFont(new java.awt.Font("Arial", 1, 18));
jButton8.setText("8");
jButton8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton8ActionPerformed(evt);
}
});
jButton9.setFont(new java.awt.Font("Arial", 1, 18));
jButton9.setText("9");
jButton9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton9ActionPerformed(evt);
}
});
plus.setFont(new java.awt.Font("Arial", 1, 18));
plus.setText("+");
plus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
plusActionPerformed(evt);
}
});
minus.setFont(new java.awt.Font("Arial", 1, 18));
minus.setText("-");
minus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
minusActionPerformed(evt);
}
});
mal.setFont(new java.awt.Font("Arial", 1, 18));
mal.setText("x");
mal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
malActionPerformed(evt);
}
});
jButton13.setFont(new java.awt.Font("Arial", 1, 18));
jButton13.setText("0");
jButton13.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton13ActionPerformed(evt);
}
});
clear.setFont(new java.awt.Font("Arial", 1, 18));
clear.setText("C");
clear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clearActionPerformed(evt);
}
});
dezimal.setFont(new java.awt.Font("Arial", 1, 18));
dezimal.setText(".");
dezimal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
dezimalActionPerformed(evt);
}
});
geteilt.setFont(new java.awt.Font("Arial", 1, 18));
geteilt.setText("/");
geteilt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
geteiltActionPerformed(evt);
}
});
posneg.setFont(new java.awt.Font("Arial", 1, 18));
posneg.setText("+/-");
posneg.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
posnegActionPerformed(evt);
}
});
gleich.setFont(new java.awt.Font("Arial", 1, 18));
gleich.setText("=");
gleich.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
gleichActionPerformed(evt);
}
});
label1.setText("Pamugundan Ismailine armagan");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(display, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(plus)))
.addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(posneg, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(jButton13)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(clear)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(dezimal, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(geteilt, javax.swing.GroupLayout.DEFAULT_SIZE, 43, Short.MAX_VALUE))
.addComponent(gleich, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton5))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton8)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(minus, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton9)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(mal)))))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(display, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton3)
.addComponent(jButton2)
.addComponent(plus))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton4)
.addComponent(jButton5)
.addComponent(jButton6)
.addComponent(minus))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton7)
.addComponent(jButton8)
.addComponent(jButton9)
.addComponent(mal))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton13)
.addComponent(clear)
.addComponent(dezimal)
.addComponent(geteilt))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(posneg)
.addComponent(gleich))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void clearActionPerformed(java.awt.event.ActionEvent evt) {
display.setText("");
dezimalClick=0;
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
display.setText(display.getText()+jButton1.getText());
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
display.setText(display.getText()+jButton3.getText());
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
display.setText(display.getText()+jButton2.getText());
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
display.setText(display.getText()+jButton4.getText());
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
display.setText(display.getText()+jButton5.getText());
}
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
display.setText(display.getText()+jButton6.getText());
}
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
display.setText(display.getText()+jButton7.getText());
}
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
display.setText(display.getText()+jButton8.getText());
}
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
display.setText(display.getText()+jButton9.getText());
}
private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {
display.setText(display.getText()+jButton13.getText());
}
private void dezimalActionPerformed(java.awt.event.ActionEvent evt) {
if(dezimalClick==0){
display.setText(display.getText()+dezimal.getText());
dezimalClick=1;
}
}
private void posnegActionPerformed(java.awt.event.ActionEvent evt) {
plusminus=(Double.parseDouble( String.valueOf(display.getText ())));
plusminus=plusminus*(-1);
display.setText(String.valueOf(plusminus));
}
private void plusActionPerformed(java.awt.event.ActionEvent evt) {
firstDouble=(Double.parseDouble(String.valueOf(display.getText())));
display.setText("");
plusClick=1;
dezimalClick=0;
}
private void minusActionPerformed(java.awt.event.ActionEvent evt) {
firstDouble=(Double.parseDouble(String.valueOf(display.getText())));
display.setText("");
minusClick=1;
dezimalClick=0;
}
private void malActionPerformed(java.awt.event.ActionEvent evt) {
firstDouble=(Double.parseDouble(String.valueOf(display.getText())));
display.setText("");
malClick=1;
dezimalClick=0;
}
private void geteiltActionPerformed(java.awt.event.ActionEvent evt) {
firstDouble=(Double.parseDouble(String.valueOf(display.getText())));
display.setText("");
geteiltClick=1;
dezimalClick=0;
}
private void gleichActionPerformed(java.awt.event.ActionEvent evt) {
secondDouble=(Double.parseDouble(String.valueOf(display.getText())));
if(plusClick>0){
totalDouble=firstDouble+secondDouble;
display.setText((String.valueOf(totalDouble)));
firstDouble=0;
secondDouble=0;
plusClick=0;
}
if(minusClick>0){
totalDouble=firstDouble-secondDouble;
display.setText((String.valueOf(totalDouble)));
firstDouble=0;
secondDouble=0;
minusClick=0;
}
if(malClick>0){
totalDouble=firstDouble*secondDouble;
display.setText((String.valueOf(totalDouble)));
firstDouble=0;
secondDouble=0;
malClick=0;
}
if(geteiltClick>0){
totalDouble=firstDouble/secondDouble;
display.setText((String.valueOf(totalDouble)));
firstDouble=0;
secondDouble=0;
geteiltClick=0;
}
}
private void displayActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Calculator().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton clear;
private javax.swing.JButton dezimal;
private javax.swing.JTextField display;
private javax.swing.JButton geteilt;
private javax.swing.JButton gleich;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton13;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JPanel jPanel1;
private javax.swing.JTabbedPane jTabbedPane1;
private java.awt.Label label1;
private javax.swing.JButton mal;
private javax.swing.JButton minus;
private javax.swing.JButton plus;
private javax.swing.JButton posneg;
// End of variables declaration
}
hier die Fehlermeldungen als Bild:
