I worked on a simple project on my own, which was to develop a calculator using Java, but I am getting the wrong output:
I asked everyone, I looked over my code and I could not find the solution. Most people say my code's logic is code.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JTextField;
public class ButtonListener implements ActionListener {
JTextField text;
String display = "";
String button[];
JButton buttons[];
public ButtonListener(JTextField text, String[] button, JButton[] buttons) {
this.text = text;
this.button = button;
this.buttons = buttons;
}
public void Display(String button) {
display = display + button;
// return display;
}
public void actionPerformed(ActionEvent Buttonpress) {
/******************** Constants ********************/
// Planks Constant
if (Buttonpress.getSource() == buttons[0]) {
// display+=button[0];
Display(button[0]);
}
// Elementary Charge
if (Buttonpress.getSource() == buttons[8]) {
// display+=Buttonpress.getSource();
Display(button[8]);
}
text.setText(display);
}
}