I am new to java and trying to figure this out, the error im getting is;

week1SR4Frame.java:28: week1SR4Frame is not abstract and does not override abstract method windowDeactivated(java.awt.event.WindowEvent) in java.awt.event.WindowListener
public class week1SR4Frame extends JFrame implements WindowListener, ActionListener

I am trying to "endButton.addActionListener(this);"

i have added the above code also to the;

public void actionPerformed(WindowEvent event) {

to no avail i just get a different error


thanks for your help

Well, the actionPerformed method takes an actionEvent, not a windowEvent. As long as your class implements ActionListener and contains the method void actionPerformed(actionEvent e) then you should be able to add "this" to the endButton.addActionListener().

Alternatively, you could also just do this:

endButton.addActionListener(new ActionListener(){
	public void actionPerformed(ActionEvent e){
		//stuff
	}
});

google an ActionListener. Your class that has the listener has to implement ActionListener, ( capitalization on that?).

i.e. class mypanel extends JPanel implements ActionListener
(above is from memory , check spelling syntax but i think that works)

when you extend you are using inheritance, you can only extend from one other class. you inherit its methods. when you implmement you are using an interface. you can implment multiple interfaces.

This sounds like the issue.
Mike

yea make sure you stay with actionlistener for a button. there are different listeners. a mouse has its own for mouse movement for example.

Ok thanks for the help but i get even more errors, here is the un-edited code, now i realize that its incomplete, at this point i am focusing on the ActionListeners

//import section
import javax.swing.*;
import javax.swing.JToolBar;
import javax.swing.event.*;

import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.AWTEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import java.io.*;

import java.text.NumberFormat;

    public class week1SR4Frame extends JFrame //implements WindowListener, ActionListener           // This line names the Public class
   {
        //Create frame panels
        JPanel topPanel = new JPanel();
      JPanel bottomPanel = new JPanel();
      JPanel radioPanel = new JPanel();    

      //Set up Layout

      FlowLayout flowLayout = new FlowLayout();
      BorderLayout borderLayout = new BorderLayout();



        //Setup Buttons and Button Labels

     JLabel amountLabel = new JLabel("Loan Amount");
     JTextField loanAmount = new JTextField(10);

     JLabel termLabel = new JLabel("Term");
     JTextField termYears = new JTextField(10);

     JLabel rateLabel = new JLabel("Rate");
     JTextField interestRate = new JTextField(10);

     JButton calcButton = new JButton("Calculate");

     JButton resetButton = new JButton("Reset");

     JButton endButton = new JButton("End");


      JScrollPane scroll = new JScrollPane(
           JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
          JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);


        //Frame contructor
    public week1SR4Frame(String title)
      {
        setTitle("GUI Mortgage Calculator");
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setVisible(true);

        //endButton.addActionListener(this);

       //add topPanel
      topPanel.setLayout(flowLayout);


       //layout for options
       topPanel.add(amountLabel);
      topPanel.add(loanAmount);
      topPanel.add(termLabel);
      topPanel.add(termYears);
      topPanel.add(rateLabel);
      topPanel.add(interestRate);


      //add bottomPanel          
      bottomPanel.add(calcButton);
      bottomPanel.add(resetButton);
      bottomPanel.add(endButton);
      calcButton.setBackground(Color.gray);
      resetButton.setBackground(Color.gray);
      endButton.setBackground(Color.gray);

      //add Container
      Container pane = getContentPane();
                pane.setLayout(borderLayout);
                pane.add(topPanel, BorderLayout.NORTH);
                pane.add(bottomPanel, BorderLayout.SOUTH);
                     pane.add(scroll);
      pack();





       }//end week1SR4Frame constructor

  public void actionPerformed(WindowEvent event) {

       try {
          Object source = event.getSource();

          if (source == calcButton) {
               calcProg();

          }
          if (source == resetButton) {
               reset();

          }
          if (source == endButton) {
               end();

          }
             }catch (InterruptedException e) {
            }

            }//end of ActionPerformed constructor

 void calcProg() throws InterruptedException
      {


double loanAmount = 0;                //principal
int termYears = 0;                      //term
double interestRate= 0;             //interest rate
double monthlyPayments;                 //Monthly payment variable
double monthlyInterestAmount;       //Monthly interest amount
int numberOfPmnts;                      //Number of payments variable
double monthlyPrincipalAmount;      //Monthly principal amount variable
int count = 12;                         //The two lines set the                        
int lineCount = 0;                  //variables for the timer and pause mechanism                     
//The above is the section that declares the varibles 
//for use through the program


monthlyPayments = ((interestRate / 12) * loanAmount)
                   /(1- (Math.pow (1+ (interestRate / 12), (termYears * -12))));
numberOfPmnts = termYears * 12;
//The above performs all the calculations to figure the monthly payment amount       


System.out.println("This is an outline of the total " +
     "mortgage information with an Interest rate of " + 
      (interestRate*100) + "% for a term of " + termYears + " years.");
System.out.println("Your monthly payment is " 
                    + NumberFormat.getCurrencyInstance().format(monthlyPayments) + "\n");
    //The above outputs the monthly mortgage payment
System.out.println("Payment number\t\tInterest Amount\t\tPrincipal Amount\t\tLoan Amount"); 
System.out.println("------------------\t------------------\t----------------\t\t------------\t");
   //This formats the output block


while(numberOfPmnts > 0){           //This line begins the loop for the monthyly payment output

      numberOfPmnts--;             //This line decrements the line number

monthlyInterestAmount = ((interestRate*100)/(12*100))*loanAmount;               
//The above line sets the monthly interest amount
monthlyPrincipalAmount = monthlyPayments - monthlyInterestAmount ;
//The above line sets the monthly principal amount
loanAmount = loanAmount - monthlyPrincipalAmount;
//This line subtract whats paid to the principal each month from the loan amount
  System.out.println( 
                            numberOfPmnts + "\t\t" + "\t\t" +
                            NumberFormat.getCurrencyInstance().format(monthlyInterestAmount)+
                            "\t" + "\t\t" + 
                            NumberFormat.getCurrencyInstance().format(monthlyPrincipalAmount)
                             + "\t" +
                            "\t\t" + NumberFormat.getCurrencyInstance().format(loanAmount));
                        //The above line output the payment number, interest amount, principal amount, and 
                        //the total balance of the loan 
                        if (lineCount == count) {
                            lineCount = 1;
                            System.out.println("\n\n\n");
                             Thread.sleep(4000);
                             }//end if 
                             //The above section is the line count test and the paues and count for 4 seconds
                        else {
                              lineCount++;
                            }//The above line increments the line count

                    }
            }



        // resets the values for all fields
  void reset() {

          loanAmount.setText(null);
          termYears.setText(null);
          interestRate.setText(null);
     }//end reset

     // closes programs and exits the window
 void end() {
          System.exit(0);
     }//end of end function



}//end week2SR4Frame class
public class week1SR4Frame extends JFrame //implements WindowListener, ActionListener // This line names the Public class

why // implments. you look like you are commenting it out, i didnt spot that there was a another class that was suppose to do the work of implementing

also see http://java.sun.com/j2se/1.4.2/docs/api/java/awt/event/ActionListener.html

the method according to sun doesnt take a window event parameter.

refering to this:

public void actionPerformed(WindowEvent event)

I had tryed to get it to work with and without it, so i commented it out,

public class week1SR4Frame extends JFrame //implements WindowListener, ActionListener // This line names the Public class

why // implments. you look like you are commenting it out, i didnt spot that there was a another class that was suppose to do the work of implementing

i edited my post with a second issue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.