failing at java, can someone solve this error?

Here's my class:

package main;

import java.awt.FlowLayout;

import java.awt.Graphics;

import java.awt.event.ActionListener;

import java.awt.event.MouseEvent;

import java.awt.event.MouseMotionListener;

import javax.swing.JButton;

import javax.swing.JComponent;

public class Button extends JComponent{

public int messageX;

public int messageY;

implements MouseMotionListener, ActionListener;

/**

*

*/

private static final long serialVersionUID = 1L;

public String Message;

JButton Button;

public Button( String message) {

Message = message;

Button = new JButton("placeholder");

setLayout( new FlowLayout() );

add( Button);

Button.addActionListener( (ActionListener) this);

addMouseMotionListener( (MouseMotionListener) this );

}

public void paintComponent( Graphics g) {

g.drawString( Message, messageX, messageY );

}

public void mouseDragged( MouseEvent e ) {

messageX = e.getX();

messageY = e.getY();

repaint();

}

public void mouseMoved( MouseEvent e) {}

}

the implements MouseMotionListener, ActionListener; gives me a syntax error:

Syntax error on token 'implements', wrong invalid type.

Can someone help me with this, I'm new at java and I took over an example from a book and changed a few things. But that part of the code should be working... I'm using java v7 update 3, while the book is made for v6, so maybe it's because of the new version.

1 Answer

Relevance
  • Taz
    Lv 4
    8 years ago
    Best Answer

    public class Button extends JComponent{

    public int messageX;

    public int messageY;

    implements MouseMotionListener, ActionListener;

    should be

    public class Button extends JComponent implements MouseMotionListener, ActionListener

    {

    public int messageX, messageY;

    Although.. I don't see where their methods are implemented inside the class..

    I suggest going to google and looking up how to properly use the MML and AL in java.

    "But I have a book!" no because no.

    Online is infinitely better.

Still have questions? Get your answers by asking now.