Jump to content

Abstract override fail

- - - - -

  • Please log in to reply
2 replies to this topic

#1
7SLEVIN

7SLEVIN

    Newbie

  • Members
  • PipPip
  • 23 posts
Hi! Im following a tut on mouse events, though i seem to be getting an error which is absent in the tut. I have MouseEvent.java, which is run in Main.java.

MouseEvent.java:
package gui;


// MouseEvent

// The New Boston: Java Programming Tutorial - 70+71


// Imports

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;


public class MouseEvent extends JFrame {


    private JPanel mousePanel;

    private JLabel statusBar;


    public MouseEvent() {

        super("The Title");


        mousePanel = new JPanel();

        mousePanel.setBackground(Color.WHITE);

        add(mousePanel, BorderLayout.CENTER);


        statusBar = new JLabel("Default");

        add(statusBar, BorderLayout.SOUTH);


        Handler myHandler = new Handler();

        mousePanel.addMouseListener(myHandler);

        mousePanel.addMouseMotionListener(myHandler);

    }


    private class Handler implements MouseListener, MouseMotionListener {

        // MouseListener events

        public void mouseClicked(MouseEvent event) {

            statusBar.setText(String.format("Clicked at %d, %d", event.getX(), event.getY()));

        }

        public void mousePressed(MouseEvent event) {

            statusBar.setText("You pressed down the mouse");

        }

        public void mouseReleased(MouseEvent event) {

            statusBar.setText("You released the mouse");

        }

        public void mouseEntered(MouseEvent event) {

            statusBar.setText("You entered the area");

            mousePanel.setBackground(Color.RED);

        }

        public void mouseExited(MouseEvent event) {

            statusBar.setText("You exited the area");

            mousePanel.setBackground(Color.WHITE);

        }

        // MouseMotion events

        public void mouseDragged(MouseEvent event) {

            statusBar.setText("You're dragging!");

        }

        public void mouseMoved(MouseEvent event) {

            statusBar.setText("You're moving");

        }

    }


}


Main.java:
package gui;


/**

 *  @author markus

 *

 */


import javax.swing.JFrame;


public class Main {


    public static void main(String[] args) {


        MouseEvent gui = new MouseEvent();


        gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        gui.setSize(400, 180);

        gui.setVisible(true);


    }


}

Here is compilators output:
init:

deps-clean:

Updating property file: /home/markus/IT/Java/workspace/GUI/build/built-clean.properties

Deleting directory /home/markus/IT/Java/workspace/GUI/build

clean:

init:

deps-jar:

Created dir: /home/markus/IT/Java/workspace/GUI/build

Updating property file: /home/markus/IT/Java/workspace/GUI/build/built-jar.properties

Created dir: /home/markus/IT/Java/workspace/GUI/build/classes

Created dir: /home/markus/IT/Java/workspace/GUI/build/empty

Compiling 10 source files to /home/markus/IT/Java/workspace/GUI/build/classes

/home/markus/IT/Java/workspace/GUI/src/gui/MouseEvent.java:31: gui.MouseEvent.Handler is not abstract and does not override abstract method mouseExited(java.awt.event.MouseEvent) in java.awt.event.MouseListener

    private class Handler implements MouseListener, MouseMotionListener {

1 error

/home/markus/IT/Java/workspace/GUI/nbproject/build-impl.xml:413: The following error occurred while executing this line:

/home/markus/IT/Java/workspace/GUI/nbproject/build-impl.xml:199: Compile failed; see the compiler error output for details.

BUILD FAILED (total time: 0 seconds)


The part which i see relevant is the "gui.MouseEvent.Handler is not abstract and does not override abstract method mouseExited(java.awt.event.MouseEvent) in java.awt.event.MouseListener". I havent had this error before, working with very simular code.

Thanks for any help :)

#2
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
I'm almost sure that mouseExited(MouseEvent event) isn't using java.awt.MouseEvent.

You named one of your classes MouseEvent, and I believe the mouseExited method is using this class instead of java.awt.MouseEvent.

#3
7SLEVIN

7SLEVIN

    Newbie

  • Members
  • PipPip
  • 23 posts
You go it!

I renamed my MouseEvent.java to MouseEvt.java, and there you go.

Thanks lethalwire ;)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users