I'm pretty new to Java, and as such still struggle from basic problems.

My problem is how to do I link an action event from a button to a mouse event. This is being used in a program to allow users to draw a square, oval etc on a canvas by clicking their mouse button. They choose which shape to draw from the corresponding button. My problem is that the button is not reflecting the mouse click and vice-versa.

My code so far is as follows,

From the DrawToolCanvas class:

import java.awt.*;
import java.awt.event.*;

public class DrawToolCanvas extends Canvas implements MouseListener, ActionListener

public void paint(Graphics g)

public void actionPerformed(ActionEvent event)
{ if (event.getActionCommand().equals("square"))
else if (event.getActionCommand().equals("circle"))

public void square()
{ Graphics g = getGraphics();
int x=e.getX(), y=e.getY();
g.fillRect( x, y, x = 40, y = 40 );

public void circle()
{ Graphics g = getGraphics();
int x=getX(), y=getY();
g.fillOval( x, y, x = 40, y = 40 );


public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseClicked(MouseEvent e) {}


Any help would be gratefully appreciated!

Many thanks