3 Replies - 1495 Views - Last Post: 01 June 2011 - 09:09 PM Rate Topic: -----

#1 kwins  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 01-June 11

Error: Absolute is not abstract and does not override abstract method

Posted 01 June 2011 - 08:43 PM

hi everyone

i just finish writing this code for my assignment but i'm stuck at this error which I have no idea and i'm confused, I need help
Error: Absolute is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
here is my code:

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

public class Absolute extends JFrame implements ActionListener   //Absolute is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
{
 JTextField textField1,textField2,textField3;
 JLabel label1,label2,label3,label4,label5, label6;
 JComboBox compBox;
 JButton ok, close;
   
    
    //Constructor
public Absolute()
{
    JFrame frame = new JFrame();
    frame.setLayout(null);
    
    label1 = new JLabel ("First Number:");
    label1.setBounds(20,25,100,20);
    label1.setForeground(Color.BLUE);
    
    label2 = new JLabel ("Second Number:");
    label2.setBounds(20,65,100,20);
    label2.setForeground(Color.BLUE);
    
     label3 = new JLabel ("Operator");
    label3.setBounds(20,105,100,20);
    label3.setForeground(Color.RED);
    
       String Operatn[] = {"Select","Add","Mult","Divide","Sub"};  
     compBox = new JComboBox(Operatn);
    compBox.setBounds(124,105,100,20);
    
     label4 = new JLabel ("TOTAL :");
    label4.setBounds(20,200,100,20);
    label4.setForeground(Color.BLACK);
    
    textField1 = new JTextField();
    textField1.setBounds(124,25,100,20);
    textField1.setBackground(Color.YELLOW);
    
   textField2 = new JTextField();
    textField2.setBounds(124,65,100,20);
    textField2.setBackground(Color.YELLOW);
    
    JLabel label6 = new JLabel();
    label6.setBounds(124,200,100,20);
    label6.setBackground(Color.YELLOW);
    /* textField3 = new JTextField();
    textField3.setBounds(124,200,100,20);
    textField3.setBackground(Color.YELLOW);*/
    
     label5 = new JLabel ("");
    label5.setBounds(125, 300, 150, 50);
    label5.setForeground(Color.BLUE);
    
   ok = new JButton("Calculate");
   ok.addActionListener(this);
   ok.setBounds(50, 150, 90, 25);
   
    close = new JButton ("Close");
   close.setBounds(150, 150, 80, 25);
   
   frame.add(ok);
   frame.add(close);
   frame.add(label1);
   frame.add(label2);
   frame.add(label3);
   frame.add(compBox);
   frame.add(label4);
   frame.add(label5);
   frame.add(textField1);
   frame.add(textField2);
   frame.add(label6);
   //frame.add(textField3);
   
   frame.setSize(400, 350);
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setVisible(true);
                 }
    
  public void ActionPerformed(ActionEvent e)
    {
      try
      {
        String num1 = textField1.getText();
        String num2 = textField2.getText();
        
        double number1 = Double.parseDouble(num1);
        double number2 = Double.parseDouble(num2);
        
        if(compBox.getSelectedItem() == "Add")
        {
        String plus = "First Number + Second Number";
         double Total = number1 + number2;
          String dispTotal = Double.toString(Total);
          label6.setText(dispTotal);
          label5.setText(plus);
          
        }

        else if(compBox.getSelectedItem() == "Sub")
        {
          String subs = "First Number Minus Second Number";
          double minus = number1 - number2;
          String total2 = Double.toString(minus);
           label6.setText(total2);
          label5.setText(subs);
        }
        else if(compBox.getSelectedItem() == "Divide")
        {
          String divi = "First Number Devide by the Second Number";
          double divide = number1/number2;
          String total3 = Double.toString(divide);
         label6.setText(total3);
          label5.setText(divi);
        }
        else if(compBox.getSelectedItem() == "Mult")
        {
          String mult = "First Number multiply by Second Number";
          double multiply = number1 * number2;
          String total4 = Double.toString(multiply);
         label6.setText(total4);
        label5.setText(mult);
        }
        else
             System.out.println();
             
       
        
        
      }
      catch(Exception exp)
      {
       label6.setText("Error");
      }
    
    }
}


and here is my main method

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

public class mainmethod
  {
  
  public static void main(String[]args)
  {
    JFrame frame = new JFrame();   
    frame.add(new Absolute());
    
  }
}


i'm running out of time i really need this to due at the weekend, thank you for all your help in advance

Is This A Good Question/Topic? 0
  • +

Replies To: Error: Absolute is not abstract and does not override abstract method

#2 skaoth  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 90
  • View blog
  • Posts: 601
  • Joined: 07-November 07

Re: Error: Absolute is not abstract and does not override abstract method

Posted 01 June 2011 - 08:55 PM

Quote

Error: Absolute is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener


This tells you what is goinging on.

You need to define the function like this
public void actionPerformed(ActionEvent e) {
}

// Not like this. Notice the capital A
public void ActionPerformed(ActionEvent e) {
}


Was This Post Helpful? 2
  • +
  • -

#3 kwins  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 01-June 11

Re: Error: Absolute is not abstract and does not override abstract method

Posted 01 June 2011 - 09:08 PM

:oops: thanks skaoth....mannnn am i dat blind? :sweatdrop: ... :bananaman:
Was This Post Helpful? 0
  • +
  • -

#4 x68zeppelin80x  Icon User is offline

  • D.I.C Addict

Reputation: 105
  • View blog
  • Posts: 508
  • Joined: 07-March 09

Re: Error: Absolute is not abstract and does not override abstract method

Posted 01 June 2011 - 09:09 PM

By convention in Java:

Classes begin with a capital letter.

Variables and Methods do not begin with a capital letter.

Final variables are all uppercase.

http://java.about.co...conventions.htm

This post has been edited by x68zeppelin80x: 01 June 2011 - 09:11 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1