-1

I seem to get this error whenever I compile the code:

Test is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener public class Test extends JFrame implements ActionListener ^

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Test extends JFrame implements ActionListener {

    Font Ft = new Font("Verdana",Font.BOLD,14);
    JLabel Lb1 = new JLabel("Select an add-on to your burger");
    JCheckBox Egg = new JCheckBox("Egg Php10");
    JCheckBox Cheese = new JCheckBox("Cheese Php10");
    JCheckBox Bacon = new JCheckBox("Bacon Php15");
    JButton UnCheck = new JButton("UnCheck All");
    JButton CheckAll = new JButton("Check All");
    JButton Submit = new JButton("Submit");
    JLabel Lb2 = new JLabel("Total Amount: ");
    JLabel Lb3 = new JLabel("");

    public Test()//Swing Components
    {
        setTitle("Color Settings");
        setSize(300,420);
        setLayout(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        getContentPane().setBackground(Color.BLACK);

        Lb1.setFont(Ft);
        Lb1.setBounds(20,30,300,20);
        Lb1.setForeground(Color.YELLOW);

        Egg.setFont(Ft);
        Egg.setBounds(40,65,300,20);
        Egg.setForeground(Color.WHITE);
        Egg.setBackground(Color.BLACK);

        Cheese.setFont(Ft);
        Cheese.setBounds(40,95,300,20);
        Cheese.setForeground(Color.WHITE);
        Cheese.setBackground(Color.BLACK);

        Bacon.setFont(Ft);
        Bacon.setBounds(40,125,300,20);
        Bacon.setForeground(Color.WHITE);
        Bacon.setBackground(Color.BLACK);

        UnCheck.setBounds(20,160,100,20);
        CheckAll.setBounds(150,160,100,20);
        Submit.setBounds(70,200,100,20);

        Lb2.setFont(Ft);
        Lb2.setBounds(20,250,300,20);
        Lb2.setForeground(Color.YELLOW);

        Lb3.setFont(Ft);
        Lb3.setBounds(150,250,300,20);
        Lb3.setForeground(Color.YELLOW);

        add(Lb1);
        add(Egg);
        add(Cheese);
        add(Bacon);
        add(UnCheck);
        add(CheckAll);
        add(Submit);
        add(Lb2);
        add(Lb3);     

        UnCheck.addActionListener(new ActionListener()//First button to have a separate action.
        {
            public void actionPerformed(ActionEvent E)
            {
                Egg.setSelected(false);
                Cheese.setSelected(false);
                Bacon.setSelected(false);
            }
        });
        CheckAll.addActionListener(new ActionListener()//Second button to have a separate action.
        {
            public void actionPerformed(ActionEvent E)
            {
                Egg.setSelected(true);
                Cheese.setSelected(true);
                Bacon.setSelected(true);
            }
        });
        Submit.addActionListener(new ActionListener()//Third button to have a separate action.
        {
            public void actionPerformed(ActionEvent E)
            {
                int price;

                if (Egg.isSelected())
                {
                    price = price + 10;
                }
                if (Cheese.isSelected())
                {
                    price = price +10;
                }
                if (Bacon.isSelected())
                {
                   price = price + 15;
                }
                Lb3.setText("Php" + price);
            }
        });
    }
    public static void main (String[] args)
    {
        Test Fr = new Test();
        Fr.setVisible(true);
    }
}
António Ribeiro
  • 4,129
  • 5
  • 32
  • 49
  • 3
    You are getting this error because your class implements 'ActionListener', which is an interface. Yet, you did not create/implement the `actionPerformed()` method required. – pczeus Feb 20 '16 at 01:08
  • Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). – Andrew Thompson Feb 20 '16 at 02:21

1 Answers1

2

Start by having a look at How to Write an Action Listeners.

Your Test class implements the ActionListener interface but does not implement the actionPerformed method described by the contract, instead you use a series of anonymous classes

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366