Mouse Sensitive Shapes

This browser does not have a Java Plug-in.
Get the latest Java Plug-in here.

Processing shapes (ellipses, rectangles, triangles and polygons) that can fire mouse events to a custom method which responds to them. Move mouse over shapes above and try dragging objects.

To use, download shapes.zip and open 'shapes' from within Processing (alternatively copy all the 'J' source files below to your existing Processing project). The J files should not be modified. For example of how to create and use these objects, see the shapes source code See also the API documentation for creating shape objects.

Source code: shapes JEllipse JPolygon JRectangle JShape JShapeAdapter JShapeListener JTriangle

For a simple example of how to use:

JShape circle;

void setup()
{
  size(300,300);
  
  circle = new JEllipse(150,150,100,100);
  circle.addShapeListener(new MyListener());
}

void draw()
{
  background(255);
  circle.draw();
}

class MyListener extends JShapeAdapter
{
  // Highlights the circle when a mouse is over it.
  void shapeEntered(JShape shape)
  {
    shape.setFillColour(color(120,40,40));
  }
  
  // Returns circle to its default appearance when mouse leaves it.
  void shapeExited(JShape shape)
  {
    shape.setDefaultAppearance();
  }
}