Having trouble turning Java application into applet

here is the regular application:

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.text.DecimalFormat;

publicclass TravelExpensesextends JFrameimplements ActionListener{

private JPanel iPanel;// To hold a text field

private JPanel buttonPanel;// To hold a button

private JTextField days, airfare, carRental, milesDriven, parkingFees, taxiCharges, confrenceFees, lodgingCharges, expenses, excess, saved;

private JLabel message1, message2, message3, message4, message5, message6, message7, message8, message9, message10, message11, message12, message13, message14, message15, message16, message17;

private JButton YesButton, YesButton2, YesButton3, YesButton4, YesButton5, YesButton6;

public TravelExpenses(){

setTitle("Travel Expense Calculator");

setSize(900, 700);

buildIpanel();

// buildCpanel();

buildButtonPanel();

setLayout(new BorderLayout());

//Add the panels to the content pane.

add(iPanel,BorderLayout.CENTER);

add(buttonPanel, BorderLayout.SOUTH);

setVisible(true);

}

privatevoid buildIpanel()

{

iPanel =new JPanel();

iPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));

message1 =new JLabel("Number of days on the trip: ");

days =new JTextField(10);

days.setText("0");

message2 =new JLabel("Did you have any airfare?");

YesButton =new JButton("Yes");

YesButton.addActionListener(this);

message3 =new JLabel("Please enter the amount of airfare: ");

message3.setVisible(false);

airfare =new JTextField(10);

airfare.setVisible(false);

airfare.setText("0");

message4 =new JLabel("Did you have any car rental fees?");

YesButton2 =new JButton("Yes");

YesButton2.addActionListener(this);

message5 =new JLabel("Please enter the amount of car rental fees: ");

message5.setVisible(false);

carRental =new JTextField(10);

carRental.setVisible(false);

carRental.setText("0");

message6 =new JLabel("Did you use a private vehicle?");

YesButton3 =new JButton("Yes");

YesButton3.addActionListener(this);

message7 =new JLabel("Please enther the number of miles driven: ");

message7.setVisible(false);

milesDriven =new JTextField(10);

milesDriven.setVisible(false);

milesDriven.setText("0");

message8 =new JLabel("Did you have any parking fees?");

YesButton4 =new JButton("Yes");

YesButton4.addActionListener(this);

message9 =new JLabel("Please enter the amount of parking fees: ");

message9.setVisible(false);

parkingFees =new JTextField(10);

parkingFees.setVisible(false);

parkingFees.setText("0");

message10 =new JLabel("Did you have any taxi charges?");

YesButton5 =new JButton("Yes");

YesButton5.addActionListener(this);

message11 =new JLabel("Please enter the amount of taxi charges: ");

message11.setVisible(false);

taxiCharges =new JTextField(10);

taxiCharges.setVisible(false);

taxiCharges.setText("0");

message12 =new JLabel("Did you have any conference or seminar registration fees?");

YesButton6 =new JButton("Yes");

YesButton6.addActionListener(this);

message13 =new JLabel("Please enter the amount of conference and/or seminar registration fees: ");

message13.setVisible(false);

confrenceFees =new JTextField(10);

confrenceFees.setVisible(false);

confrenceFees.setText("0");

message14 =new JLabel("Please enter the amount of Lodging charges(required): ");

lodgingCharges =new JTextField(10);

message15 =new JLabel("Total expenses incurred: ");

expenses =new JTextField(10);

message16 =new JLabel("Excess amount paid by business person: ");

excess =new JTextField(10);

excess.setVisible(false);

message17 =new JLabel("Amount saved by business person: ");

saved =new JTextField(10);

saved.setVisible(false);

iPanel.setLayout(new GridLayout(17, 2));

// Add the label and text field to the panel.

iPanel.add(message1);

iPanel.add(days);

iPanel.add(message2);

iPanel.add(YesButton);

iPanel.add(message3);

iPanel.add(airfare);

iPanel.add(message4);

iPanel.add(YesButton2);

iPanel.add(message5);

iPanel.add(carRental);

iPanel.add(message6);

iPanel.add(YesButton3);

iPanel.add(message7);

iPanel.add(milesDriven);

iPanel.add(message8);

iPanel.add(YesButton4);

iPanel.add(message9);

iPanel.add(parkingFees);

iPanel.add(message10);

iPanel.add(YesButton5);

iPanel.add(message11);

iPanel.add(taxiCharges);

iPanel.add(message12);

iPanel.add(YesButton6);

iPanel.add(message13);

iPanel.add(confrenceFees);

iPanel.add(message14);

iPanel.add(lodgingCharges);

iPanel.add(message15);

iPanel.add(expenses);

iPanel.add(message16);

iPanel.add(excess);

iPanel.add(message17);

iPanel.add(saved);

setLayout(new BorderLayout());

}

privatevoid buildButtonPanel()

{

// Create the panel.

buttonPanel =new JPanel();

buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));

// Create a button with the text "Convert".

JButton CalcButton =new JButton("Calculate");

JButton ExitButton =new JButton("Exit");

// Add an action listener to the button.

CalcButton.addActionListener(new CalcButtonListener());

ExitButton.addActionListener(new ExitButtonListener());

// Add the button to the panel.

buttonPanel.add(CalcButton);

buttonPanel.add(ExitButton);

//setVisible(true);

}

privateclass ExitButtonListenerimplements ActionListener

{

publicvoid actionPerformed(ActionEvent e)

{

System.exit(0);

}

}

privateclass CalcButtonListenerimplements ActionListener

{

publicvoid actionPerformed(ActionEvent e)

{

double totalExpenses, day, account, parking, air,

car, miles, taxi, confrence, lodging, mileExpense;

day = Double.parseDouble(days.getText());

air = Double.parseDouble(airfare.getText());

car = Double.parseDouble(carRental.getText());

miles = Double.parseDouble(milesDriven.getText());

parking = Double.parseDouble(parkingFees.getText());

taxi = Double.parseDouble(taxiCharges.getText());

confrence = Double.parseDouble(confrenceFees.getText());

lodging = Double.parseDouble(lodgingCharges.getText());

// Create a DecimalFormat object to format numbers.

DecimalFormat formatter =new DecimalFormat("0.0");

mileExpense = miles * .27;

totalExpenses = air + car + mileExpense + parking + taxi + confrence + lodging;

account = 37 * day;// $37 for food

if (parking > 10 * day)

{

parking -= 10 * day;

account -= parking;

}

if (taxi > 20 * day)

{

taxi -= 20 * day;

account -= taxi;

}

if (lodging > 95 * day)

{

lodging = lodging - (95 * day);

account = account - lodging;

}

if (account > 0)

{

saved.setVisible(true);

saved.setText(formatter.format(account));

}

if (account < 0)

{

account = Math.abs(account);// Turn the negitave into a positive

excess.setVisible(true);

excess.setText(formatter.format(account));

}

expenses.setText(formatter.format(totalExpenses));

}

}

publicvoid actionPerformed(ActionEvent e){

if (e.getSource().equals(YesButton)){

message3.setVisible(true);

airfare.setVisible(true);

}elseif (e.getSource().equals(YesButton2)){

message5.setVisible(true);

carRental.setVisible(true);

}elseif (e.getSource().equals(YesButton3)){

message7.setVisible(true);

milesDriven.setVisible(true);

}elseif (e.getSource().equals(YesButton4)){

message9.setVisible(true);

parkingFees.setVisible(true);

}elseif (e.getSource().equals(YesButton5)){

message11.setVisible(true);

taxiCharges.setVisible(true);

}elseif (e.getSource().equals(YesButton6)){

message13.setVisible(true);

confrenceFees.setVisible(true);

}

}

publicstaticvoid main(String[] args)

{

TravelExpenses mc =new TravelExpenses();

}

}

and here is the applet - i cant compile it

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.text.DecimalFormat;

publicclass TravelExpenses1extends JApplet{

private JPanel iPanel;// To hold a text field

private JPanel buttonPanel;// To hold a button

private JTextField days, airfare, carRental, milesDriven, parkingFees, taxiCharges, confrenceFees, lodgingCharges, expenses, excess, saved;

private JLabel message1, message2, message3, message4, message5, message6, message7, message8, message9, message10, message11, message12, message13, message14, message15, message16, message17;

private JButton YesButton, YesButton2, YesButton3, YesButton4, YesButton5, YesButton6;

public TravelExpenses1(){

//setTitle("Travel Expense Calculator");

//setSize(900, 700);

buildIpanel();

// buildCpanel();

buildButtonPanel();

//setLayout(new BorderLayout());

//Add the panels to the content pane.

add(iPanel,BorderLayout.CENTER);

add(buttonPanel, BorderLayout.SOUTH);

//setVisible(true);

}

privatevoid buildIpanel()

{

iPanel =new JPanel();

iPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));

message1 =new JLabel("Number of days on the trip: ");

days =new JTextField(10);

days.setText("0");

message2 =new JLabel("Did you have any airfare?");

YesButton =new JButton("Yes");

YesButton.addActionListener(this);

message3 =new JLabel("Please enter the amount of airfare: ");

message3.setVisible(false);

airfare =new JTextField(10);

airfare.setVisible(false);

airfare.setText("0");

message4 =new JLabel("Did you have any car rental fees?");

YesButton2 =new JButton("Yes");

YesButton2.addActionListener(this);

message5 =new JLabel("Please enter the amount of car rental fees: ");

message5.setVisible(false);

carRental =new JTextField(10);

carRental.setVisible(false);

carRental.setText("0");

message6 =new JLabel("Did you use a private vehicle?");

YesButton3 =new JButton("Yes");

YesButton3.addActionListener(this);

message7 =new JLabel("Please enther the number of miles driven: ");

message7.setVisible(false);

milesDriven =new JTextField(10);

milesDriven.setVisible(false);

milesDriven.setText("0");

message8 =new JLabel("Did you have any parking fees?");

YesButton4 =new JButton("Yes");

YesButton4.addActionListener(this);

message9 =new JLabel("Please enter the amount of parking fees: ");

message9.setVisible(false);

parkingFees =new JTextField(10);

parkingFees.setVisible(false);

parkingFees.setText("0");

message10 =new JLabel("Did you have any taxi charges?");

YesButton5 =new JButton("Yes");

YesButton5.addActionListener(this);

message11 =new JLabel("Please enter the amount of taxi charges: ");

message11.setVisible(false);

taxiCharges =new JTextField(10);

taxiCharges.setVisible(false);

taxiCharges.setText("0");

message12 =new JLabel("Did you have any conference or seminar registration fees?");

YesButton6 =new JButton("Yes");

YesButton6.addActionListener(this);

message13 =new JLabel("Please enter the amount of conference and/or seminar registration fees: ");

message13.setVisible(false);

confrenceFees =new JTextField(10);

confrenceFees.setVisible(false);

confrenceFees.setText("0");

message14 =new JLabel("Please enter the amount of Lodging charges(required): ");

lodgingCharges =new JTextField(10);

message15 =new JLabel("Total expenses incurred: ");

expenses =new JTextField(10);

message16 =new JLabel("Excess amount paid by business person: ");

excess =new JTextField(10);

excess.setVisible(false);

message17 =new JLabel("Amount saved by business person: ");

saved =new JTextField(10);

saved.setVisible(false);

iPanel.setLayout(new GridLayout(17, 2));

// Add the label and text field to the panel.

iPanel.add(message1);

iPanel.add(days);

iPanel.add(message2);

iPanel.add(YesButton);

iPanel.add(message3);

iPanel.add(airfare);

iPanel.add(message4);

iPanel.add(YesButton2);

iPanel.add(message5);

iPanel.add(carRental);

iPanel.add(message6);

iPanel.add(YesButton3);

iPanel.add(message7);

iPanel.add(milesDriven);

iPanel.add(message8);

iPanel.add(YesButton4);

iPanel.add(message9);

iPanel.add(parkingFees);

iPanel.add(message10);

iPanel.add(YesButton5);

iPanel.add(message11);

iPanel.add(taxiCharges);

iPanel.add(message12);

iPanel.add(YesButton6);

iPanel.add(message13);

iPanel.add(confrenceFees);

iPanel.add(message14);

iPanel.add(lodgingCharges);

iPanel.add(message15);

iPanel.add(expenses);

iPanel.add(message16);

iPanel.add(excess);

iPanel.add(message17);

iPanel.add(saved);

setLayout(new BorderLayout());

}

privatevoid buildButtonPanel()

{

// Create the panel.

buttonPanel =new JPanel();

buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));

// Create a button with the text "Convert".

JButton CalcButton =new JButton("Calculate");

JButton ExitButton =new JButton("Exit");

// Add an action listener to the button.

CalcButton.addActionListener(new CalcButtonListener());

ExitButton.addActionListener(new ExitButtonListener());

// Add the button to the panel.

buttonPanel.add(CalcButton);

buttonPanel.add(ExitButton);

//setVisible(true);

}

privateclass ExitButtonListenerimplements ActionListener

{

publicvoid actionPerformed(ActionEvent e)

{

System.exit(0);

}

}

privateclass CalcButtonListenerimplements ActionListener

{

publicvoid actionPerformed(ActionEvent e)

{

double totalExpenses, day, account, parking, air,

car, miles, taxi, confrence, lodging, mileExpense;

day = Double.parseDouble(days.getText());

air = Double.parseDouble(airfare.getText());

car = Double.parseDouble(carRental.getText());

miles = Double.parseDouble(milesDriven.getText());

parking = Double.parseDouble(parkingFees.getText());

taxi = Double.parseDouble(taxiCharges.getText());

confrence = Double.parseDouble(confrenceFees.getText());

lodging = Double.parseDouble(lodgingCharges.getText());

// Create a DecimalFormat object to format numbers.

DecimalFormat formatter =new DecimalFormat("0.0");

mileExpense = miles * .27;

totalExpenses = air + car + mileExpense + parking + taxi + confrence + lodging;

account = 37 * day;// $37 for food

if (parking > 10 * day)

{

parking -= 10 * day;

account -= parking;

}

if (taxi > 20 * day)

{

taxi -= 20 * day;

account -= taxi;

}

if (lodging > 95 * day)

{

lodging = lodging - (95 * day);

account = account - lodging;

}

if (account > 0)

{

saved.setVisible(true);

saved.setText(formatter.format(account));

}

if (account < 0)

{

account = Math.abs(account);// Turn the negitave into a positive

excess.setVisible(true);

excess.setText(formatter.format(account));

}

expenses.setText(formatter.format(totalExpenses));

}

}

publicvoid actionPerformed(ActionEvent e){

if (e.getSource().equals(YesButton)){

message3.setVisible(true);

airfare.setVisible(true);

}elseif (e.getSource().equals(YesButton2)){

message5.setVisible(true);

carRental.setVisible(true);

}elseif (e.getSource().equals(YesButton3)){

message7.setVisible(true);

milesDriven.setVisible(true);

}elseif (e.getSource().equals(YesButton4)){

message9.setVisible(true);

parkingFees.setVisible(true);

}elseif (e.getSource().equals(YesButton5)){

message11.setVisible(true);

taxiCharges.setVisible(true);

}elseif (e.getSource().equals(YesButton6)){

message13.setVisible(true);

confrenceFees.setVisible(true);

}

}

}

[30612 byte] By [PoleVaulta] at [2007-11-27 2:56:06]
# 1
> and here is the applet - i cant compile itWhy not?If you get a message from the compiler copy paste and post the entire message. Indicate which line of your code is the one mentioned in the compier message.
pbrockway2a at 2007-7-12 3:33:27 > top of Java-index,Java Essentials,New To Java...
# 2
TravelExpenses1.java:46: addActionListener(java.awt.event.ActionListener) in javax.swing.AbstractButton cannot be applied to (TravelExpenses1)YesButton.addActionListener(this);all the actionListner buttons are having this prob
PoleVaulta at 2007-7-12 3:33:27 > top of Java-index,Java Essentials,New To Java...
# 3

> TravelExpenses1.java:46: addActionListener(java.awt.event.ActionListener) in

> javax.swing.AbstractButton cannot be applied to (TravelExpenses1)

The argument used with addActionListener must be an

ActionListener. Now your TravelExpenses1 has an

actionPerformed() mehod - but you forgot to say

"implements ActionListener" like you did for the JFrame.

pbrockway2a at 2007-7-12 3:33:27 > top of Java-index,Java Essentials,New To Java...
# 4
Thanks a lot!
PoleVaulta at 2007-7-12 3:33:27 > top of Java-index,Java Essentials,New To Java...
# 5
You're welcome.
pbrockway2a at 2007-7-12 3:33:27 > top of Java-index,Java Essentials,New To Java...