Har lavet denne lommeregner man kan ikke finde ud af at få det med komma'er til at virker nogle der kan hjælpe og eventuelt rette i min lommeregner hvis i synes der skal lave nogle rettelser
koden til komma'er skulle vist være temp = temp * Double.parseDouble(nyTekst); men kan ikke få det til at virke
import java.awt.*;
import java.awt.event.*;
public class RegneMaskine3 extends Frame implements ActionListener
{
TextField tekstfelt1 = new TextField("0",11);
Button button0 = new Button();
Button button1 = new Button();
Button button2 = new Button();
Button button3 = new Button();
Button button4 = new Button();
Button button5 = new Button();
Button button6 = new Button();
Button button7 = new Button();
Button button8 = new Button();
Button button9 = new Button();
Button buttonc = new Button();
Button buttonPlus = new Button();
Button buttonMinus = new Button();
Button buttonGange = new Button();
Button buttonDele = new Button();
FlowLayout FlowLayout1 = new FlowLayout();
public RegneMaskine3() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
button0.setLabel("0");
button1.setLabel("1");
button2.setLabel("2");
button3.setLabel("3");
button4.setLabel("4");
button5.setLabel("5");
button6.setLabel("6");
button7.setLabel("7");
button8.setLabel("8");
button9.setLabel("9");
buttonc.setLabel("c");
buttonPlus.setLabel("+");
buttonMinus.setLabel("-");
buttonGange.setLabel("*");
buttonDele.setLabel("/");
this.setLayout(new FlowLayout());
this.add(tekstfelt1, null);
this.add(button1, null);
this.add(button2, null);
this.add(button3, null);
this.add(button4, null);
this.add(button5, null);
this.add(button6, null);
this.add(button7, null);
this.add(button8, null);
this.add(button9, null);
this.add(button0, null);
this.add(buttonc, null);
this.add(buttonPlus, null);
this.add(buttonMinus, null);
this.add(buttonGange, null);
this.add(buttonDele, null);
tekstfelt1.addActionListener(this);
button0.addActionListener(this);
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
button5.addActionListener(this);
button6.addActionListener(this);
button7.addActionListener(this);
button8.addActionListener(this);
button9.addActionListener(this);
buttonc.addActionListener(this);
buttonPlus.addActionListener(this);
buttonGange.addActionListener(this);
buttonMinus.addActionListener(this);
buttonDele.addActionListener(this);
}
String gammelTekst = "";
String nyTekst = "";
double temp = 0;
public void actionPerformed(ActionEvent e)
{
if(e.getSource() != buttonPlus && e.getSource() != buttonMinus && e.getSource() != buttonGange
&& e.getSource() != buttonDele && e.getSource() != buttonc)
{
nyTekst = gammelTekst + ((Button) e.getSource()).getLabel();
gammelTekst = nyTekst;
}
tekstfelt1.setText("" + nyTekst);
if(e.getSource() == buttonPlus){
temp = temp + Integer.parseInt(nyTekst);
tekstfelt1.setText("" + temp );
gammelTekst = ("");}
if(e.getSource() == buttonMinus){
temp = temp - Integer.parseInt(nyTekst);
tekstfelt1.setText("" + temp );
gammelTekst = ("");}
if(e.getSource() == buttonGange){
temp = temp * Integer.parseInt(nyTekst);
tekstfelt1.setText("" + temp );
gammelTekst = ("");}
// temp=temp*Integer.parseInt(ny Tekst)
if(e.getSource() == buttonDele){
temp = temp / Integer.parseInt(nyTekst);
tekstfelt1.setText("" + temp );
gammelTekst = ("");}
if(e.getSource() == buttonc){
temp = (0);
tekstfelt1.setText("0"); }
}}