MousEvent无法正常工作,因为MouseListener工具表现得非常奇怪

时间:2017-04-17 22:33:14

标签: java mouseevent mouselistener mousemotionlistener

在过去的半小时里我一直忙于这个但是我无法弄清楚为什么我的Handlerclass在实现MouseListener和MouseMotionListener需要的每个方法时都会给出一个不抽象的方法的错误。请帮忙。这是代码:

public class PanelClass extends JFrame {
private JPanel m;
private JLabel s;

public PanelClass() {
    super("Testing");

    m = new JPanel();
    m.setBackground(Color.RED);
    add(m, BorderLayout.CENTER);
    s = new JLabel("Hello and welcome. We're showing you what your mouse does in this bar. Let's get started!");
    add(s, BorderLayout.SOUTH);

    Handlerclass handler = new Handlerclass();
    m.addMouseListener(handler);
    m.addMouseMotionListener(handler);

}

private class Handlerclass implements MouseListener, MouseMotionListener {


    public void mouseClicked(MouseEvent event) {
        s.setText("You cliced the mouse.");
    }


    public void mousePressed(MouseEvent event) {
        s.setText(String.format ("You pressed the mouse"));
    }


    public void mouseReleased(MouseEvent event) {
        s.setText("You ain't clickin' shit boi..");
    }


    public void mouseEntered(MouseEvent event) {
        s.setText("The mouse has entered the panel..");
        m.setBackground(Color.PINK);
    }


    public void mouseExited(MouseEvent event) {
        s.setText("The mouse has left the panel..");
        m.setBackground(Color.BLUE);
    }

    public void mouseDragged(MouseEvent event) {
       s.setText("You been dragging. ");
    }

    public void mouseMoved(MouseEvent event) {
        s.setText("Moving around.");
    }

}

}

0 个答案:

没有答案