import javax.swing.*; import java.awt.*; import java.awt.event.*; public class RetailPrice extends JFrame{ private JPanel panel; private JPanel panel2; private JTextField text; private JLabel label; private JTextField text2; private JLabel label2; private JButton calculate; private int width = 350; private int heigth = 150; public RetailPrice() { setTitle("retail price"); setSize(width,heigth); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); buildPanel(); add(panel); setVisible(true); } public void buildPanel() { label = new JLabel("What is the price of the sale?"); text = new JTextField(10); label2 = new JLabel("What is the mark up price?"); text2 = new JTextField(10); calculate = new JButton("Calculate"); CalculateListener listener = new CalculateListener(); calculate.addActionListener(listener); //*****this is the line im getting the error**** it says The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments panel = new JPanel(); panel.add(label); panel.add(text); panel.add(label2); panel.add(text2); panel.add(calculate); } private class CalculateListener implements ActionListener { public void actionPerformed(ActionEvent e) { String input; int cost; double perc, add, finalPrice; input = text.getText(); cost = Integer.parseInt(input); input = text2.getText(); perc = Integer.parseInt(input)/100f; finalPrice = cost + (cost * perc); JOptionPane.showMessageDialog(null, "the final price is "+ finalPrice); } } }
im learning how to handle events with action listeners, thank you