I’m relatively new to graphical user interfaces and I’ve created an interface that implements the functionality of a basic calculator. These methods include: add(), subtract(), multiply(), and divide(). I’m getting an error within my actionPerformed method that’s saying “the method add(int, int) in the type Operate is not applicable for the arguments (int).” I’ve tried including the variables I’ve passed into my public class Operate and I still receive this error. How can I resolve this?
Here’s my code for this method:
JButton btnNewButton_10 = new JButton("+");
btnNewButton_10.setFont(new Font("Helvetica Neue", Font.PLAIN, 15));
btnNewButton_10.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int myFunction = calculate.add(Integer.parseInt(textDisplay.getText())); // The error is specifically underlining the keyword "add"
textDisplay.setText("");
You’re attempting to
add1int, apparently your add function wants toaddtwoints together.