Results 1 to 3 of 3
Thread: MouseListener Error
- 12-13-2012, 01:12 PM #1
Member
- Join Date
- Dec 2012
- Posts
- 2
- Rep Power
- 0
MouseListener Error
Hey im Having a problem with my MouseListener method override..its saying I did not override the method mouseExited in my class..but i clearly did..Can anyone help out my situation :( I have a different class with the main method which tests this code and has the setVisible(true); method. The error im getting is Uncompilable source code - mouseevent.MouseEvent.classHandler is not abstract and does not override abstract method mouseExited(java.awt.event.MouseEvent) in java.
Java Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MouseEvent extends JFrame{ private JLabel statusBar; private JPanel mousePanel; public MouseEvent(){ super("Area"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(350,350); mousePanel = new JPanel(); mousePanel.setBackground(Color.WHITE); add(mousePanel, BorderLayout.CENTER); statusBar = new JLabel("Do something...."); add(statusBar,BorderLayout.SOUTH); classHandler handler; handler = new classHandler(); mousePanel.addMouseListener(handler); mousePanel.addMouseMotionListener(handler); } private class classHandler implements MouseListener, MouseMotionListener{ // saying mouseExited has not been overridden. public void mouseClicked(MouseEvent event){ statusBar.setText(String.format("You 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.ORANGE); } public void mouseDragged(MouseEvent event){ statusBar.setText("You are dragging the mouse"); } public void mouseMoved(MouseEvent event){ statusBar.setText("You moved the mouse"); } public void mouseExited(MouseEvent event){ statusBar.setText("You have left the area"); } } }Last edited by DarrylBurke; 12-13-2012 at 01:44 PM.
- 12-13-2012, 01:43 PM #2
Re: MouseListener Error
That's what you get for naming your class the same as an existing JDK class, moreover a JDK class that you need to use. Actually, none of the MouseListener methods are implemented; they all require a parameter of type java.awt.event.MouseEvent whereas in the context of your compilation unit -- your source code -- any unqualified MouseEvent will be treated as a reference to an instance of the containing class, also (badly) named MouseEvent.
Also, there's absolutely no need for this class to extend JFrame, as it isn't in any way a specialized JFrame, just an ordinary one -- so it could as well contain a JFrame, either as an instance field or as a (method-)local variable. Favor composition over inheritance.
dbLast edited by DarrylBurke; 12-13-2012 at 01:45 PM.
Why do they call it rush hour when nothing moves? - Robin Williams
- 12-13-2012, 01:44 PM #3
Member
- Join Date
- Dec 2012
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Delay between 2 same timings problem (Video of explanation of the problem inside)
By Lionlev in forum Advanced JavaReplies: 0Last Post: 11-07-2012, 12:44 PM -
Small problem with problem with Java, C++ parse program.
By dragstang86 in forum New To JavaReplies: 4Last Post: 10-30-2011, 03:43 AM -
Can anyone see the problem with my code? problem understanding switch (newbish)
By keith in forum New To JavaReplies: 9Last Post: 09-21-2010, 04:15 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks