GETTING ERROR ON NETBEANS using Code explained in 76th Video

0 RAQUIB BUKSH · April 19, 2015
// I am getting an error in this code----  Gui.Handlerclass is not abstract and doesnot override abstract method MouseExited(MouseEvent)------------------------------I am absolutely new to JAVA and I have been practicing from your videos. I am stuck now on 76th video. Please help


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

public class Gui extends JFrame{
    private JPanel mousepanel;
    private JLabel statusbar;
    
    public Gui (){
        super ("MOUSE_EVENTS");
        
        mousepanel = new JPanel();
        mousepanel.setBackground(Color.WHITE);
        add(mousepanel, BorderLayout.CENTER);
        
        statusbar = new JLabel("INFO");
        add(statusbar, BorderLayout.SOUTH);
        
        Handlerclass handler = new Handlerclass();
        mousepanel.addMouseListener(handler);
        mousepanel.addMouseMotionListener(handler);
    }
    
    private class Handlerclass implements MouseListener, MouseMotionListener {
        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");
        }
        public void mouseReleased(MouseEvent event){
         statusbar.setText("You Released Down");
        }
        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);
        }
        public void mouseDragged(MouseEvent event){
        statusbar.setText("U r dragging the mouse");
        }
        public void mouseMoved(MouseEvent event){
        statusbar.setText("U r moving the mouse");
        }
    }
    
}

Post a Reply

Replies

Oldest  Newest  Rating
0 steven kitchener · April 19, 2015
Hi Raquib,

Im having trouble trying to recreate your error using the code youve provided above, everything runs as it should. (Im using Eclipse, but i cant see why that would make a difference)

I would guess that for some reason Java isnt recognising that you have overriden the method mouseExited and therefor you are getting that error. There are a couple of things you can do:-
   firstly make sure that you havent accidently commented out any of the code
   make sure your braces are aligned correctly, missing a closing brace can cause lots of problems
   refresh NetBeans and hopefully that will flush out any weird things that shouldnt be there
   Clean+Build your project. Sometimes this will solve any weird errors you may be getting.

If none of these things work then i guess your only other option would be to delete your inner class and write it again, and hope that you dont get that same weird error.

Hope this helps,

Steven
  • 1

Java / Android Development

106,961 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator