Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

Error - "...is not abstract and does not override abstract method..."


Tags:

I'm getting the following error in my java class JMyNewHome using TextPad:

JMyNewHome is not abstract and does not override abstract method itemStateChanged(java.awt.event.ItemEvent) in java.awt.event.ItemListener
public class JMyNewHome extends JFrame implements ItemListener
^
1 error

Tool completed with exit code 1

Here is my program:

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

public class JMyNewHome extends JFrame implements ItemListener
{
final int[] HOME_PRICE = {100000,120000,180000,250000};
final int twoBed = 2, threeBed = 3, fourBed = 4;
final int zeroCar = 0, oneCar = 1, twoCar = 2, threeCar = 3;
int addRoom = 10500;
int addCarSpace = 7775;
int totalPrice = addRoom * 2;

JLabel welcomeLabel = new JLabel("Eric Homes Ltd.");

JLabel homeChoice = new JLabel("Home Selection: Choose one of the following");
String[] homeName = {"The Aspen $" + HOME_PRICE[1],
"The Brittany $" + HOME_PRICE[2],
"The Colonial $" + HOME_PRICE[3],
"The Dartmoor $" + HOME_PRICE[4]};
JComboBox homeBox = new JComboBox(homeName);

JLabel num_Bdrm = new JLabel("Number of Bedrooms:");
JCheckBox two_Bdrm = new JCheckBox(twoBed + "Bedrooms", true);
JCheckBox three_Bdrm = new JCheckBox(threeBed + "Bedrooms", false);
JCheckBox four_Bdrm = new JCheckBox(fourBed + "Bedrooms", false);

JLabel car_Space = new JLabel("Choice of Garage:");
JCheckBox no_Car = new JCheckBox("No Garage", false);
JCheckBox one_Car = new JCheckBox(oneCar + " Car Garage", false);
JCheckBox two_Car = new JCheckBox(twoCar + " Car Garage", false);
JCheckBox three_Car = new JCheckBox(threeCar + "Car Garage", false);

JTextField totPrice = new JTextField(30);

Container con;
JPanel panel = new JPanel();

public JMyNewHome()
{
super("My New Home");
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
con = getContentPane();
con.add(panel);
panel.add(welcomeLabel);
panel.add(homeChoice);
panel.add(homeBox);

ButtonGroup bedroomGroup = new ButtonGroup();
bedroomGroup.add(two_Bdrm);
bedroomGroup.add(three_Bdrm);
bedroomGroup.add(four_Bdrm);
panel.add(two_Bdrm);
panel.add(three_Bdrm);
panel.add(four_Bdrm);

ButtonGroup garageGroup = new ButtonGroup();
garageGroup.add(no_Car);
garageGroup.add(one_Car);
garageGroup.add(two_Car);
garageGroup.add(three_Car);
panel.add(no_Car);
panel.add(one_Car);
panel.add(two_Car);
panel.add(three_Car);
panel.add(totPrice);
totPrice.setText("$" + totalPrice);

two_Bdrm.addItemListener(this);
three_Bdrm.addItemListener(this);
four_Bdrm.addItemListener(this);
no_Car.addItemListener(this);
one_Car.addItemListener(this);
two_Car.addItemListener(this);
three_Car.addItemListener(this);

}

public static void main(String[] args)
{
JMyNewHome aFrame = new JMyNewHome();
final int HEIGHT = 300;
final int WIDTH = 600;
aFrame.setSize(WIDTH,HEIGHT);
aFrame.setVisible(true);

}

public void itemStageChanged(ItemEvent event)
{
Object source = event.getSource();
int select = event.getStateChange();
int homePrice = 0;
if(source == homeBox)
{
int homeSelected = homeBox.getSelectedIndex();
homePrice = HOME_PRICE[homeSelected];
}
else
{

homePrice = HOME_PRICE[0];
totalPrice += homePrice;

if(three_Bdrm.isSelected())
totalPrice += addRoom * threeBed;
else if(four_Bdrm.isSelected())
totalPrice += addRoom * fourBed;
else
totalPrice += addRoom * twoBed;

if(no_Car.isSelected())
totalPrice += addCarSpace * zeroCar;
else if(four_Bdrm.isSelected())
totalPrice += addCarSpace * oneCar;
else if(four_Bdrm.isSelected())
totalPrice += addCarSpace * twoCar;
else if(four_Bdrm.isSelected())
totalPrice += addCarSpace * threeCar;
}
totPrice.setText("$" + totalPrice);
}
}