Help! ActionListener is Abstract; cannot be instantiated
843789May 21 2009 — edited May 21 2009Hi, When I try to add an action Listener to a button, I get the error, "java.awt.event.Actionlistener is Abstract; cannot be instantiated
What I'm trying to do is create three radio buttons and group together. Then whatever box is selected, it would execute it's method.
{code}import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JApplet;
public class Speedlimit extends JApplet implements ActionListener
{
double totalInt;
private JLabel speedLimit, speed, tickets, pTickets, total;
private TextField speedLimit1, speed1, tickets1, pTickets1, court, total1;
//private JButton execute;
private JRadioButton restart, exit, calculate;
public void init()
{
//Create the Container and set the Layout
Container c = getContentPane();
c.setLayout(new GridLayout());
//Initialize the JLabels
speedLimit = new JLabel("Enter Speed Limit");
speed = new JLabel("Enter Actual Speed");
tickets = new JLabel("Enter amount of tickets recieved");
pTickets = new JLabel("Enter tickets receieved before") ;
total = new JLabel("Total");
//Initialize the TextFields
speedLimit1 = new TextField("");
speed1 = new TextField("");
tickets1 = new TextField("");
pTickets1 = new TextField("");
court = new TextField("");
court.setEditable(false);
total1 = new TextField("");
total1.setEditable(false);
//Create the RadioButtons, the group them
restart = new JRadioButton("Restart");
exit = new JRadioButton("Exit");
calculate = new JRadioButton("Calculate");
ButtonGroup gr = new ButtonGroup();
gr.add(restart);
gr.add(exit);
gr.add(calculate);
//Create the button that executes whatever choice from the radio button
JButton execute = new JButton("Execute");
execute.addActionListener(new ActionListener());
//Create a panel, then add components onto the panel
JPanel i = new JPanel();
i.setLayout(new GridLayout(7 , 2));
i.add(speedLimit); i.add(speedLimit1);
i.add(speed); i.add(speed1);
i.add(tickets); i.add(tickets1);
i.add(pTickets); i.add(pTickets1);
i.add(total); i.add(court);
i.add(restart); i.add(exit); i.add(calculate);
i.add(execute);
//Adds the Panel to the Container
add(i);
}
public void actionPerformed(ActionEvent e)
{
double limit2 = Double.parseDouble(speedLimit1.getText());
double speed2 = Double.parseDouble(speed1.getText());
double tickets2 = Double.parseDouble(tickets1.getText());
//Calculations
double b =tickets2 * 20;
double a = speed2 - limit2;
totalInt = a * 10;
totalInt = b + a + 53.20 ;
}
}
{code}