Quick Java Number pad problems
Basically I am trying to finish code for a simple GUI number pad and I am having issues with the very last bit. When I click the decimal Button(buttonDot) I want it to drop the default 0 after the decimal point, and then when I press another number button I want it to go where the 0 was.
Code Java:
public class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent arg0) {
JButton clickedOn = (JButton)arg0.getSource();
String s=label1.getText();
int length=s.length()-1;
int d=0;
if(decimal==false) {
if(clickedOn == buttonDot) {
decimal=true;
}
else if(label1.getText()=="0.0"){
label1.setText(clickedOn.getText()+".0");
} else {
s=label1.getText();
label1.setText(s.substring(0,length1)+clickedOn.getText()+s.substring(length-1,length+1));
d++;
}
}
if(decimal==true) {
if(clickedOn == buttonDot) {
return;
}
if(label1.getText().substring(length-1,length)==".0"){
label1.setText(s.substring(0,length-1)+clickedOn.getText());
System.out.println("f");
}
else {
label1.setText(s+clickedOn.getText());
System.out.println("u");
}
}
if(clickedOn == clear) {
decimal=false;
label1.setText("0.0");
}
}
}
}
Thanks for any help you can give me.
Re: Quick Java Number pad problems
Hello SkippyTHEpimp. Welcome to the Java Programming Forums.
Can you please post all of your code so we can attempt to compile it.
It looks like there are parts missing from the above code.
Thanks.