Question

I have 2 classes, A and B. A is a subclass of Program (i.e. acm.program.*) and B is a subclass of GCanvas(i.e. acm.graphics.*).

In Class A I have an init method which initiates and adds class B.

In Class B I have 2 things I want to achieve: I want to respond to changes in the window size and mouse clicks. I can achieve the window size changes by adding component listeners. I cannot achieve the mouse clicking events.

Now, I know how I would do it in a situation where I didn't care about responding to window re-sizing. I would have 1 class, extend GraphicsProgram, and add mouselisteners and not have any problem.

What is your recommendation? How do I have these two events handlers exist concurrently within a single GCanvas? Thank you.

Was it helpful?

Solution

As a GCanvas is, from the documentation, an awt Component, you can always call this class addMouseListener() or addMouseMotionListener() method and do what you want with mouse events.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top