> On Thu, Mar 24, 2011 at 14:07, Greg Brown <[email protected]> wrote: >> 1. Which class should I subclass to create my canvas component? Component? >> Image? > > Component > >> 2. How does the idea of a canvas on which I can click and draw relate to the >> concept of component skins? > > ComponentSkin (abstract) registers to receive mouse events from its > component. You can create a concrete subclass that responds to those events > in whatever way is appropriate for your component. > > > Thanks for the answer. I finally subclassed the Panel class and I'm receiving > mouse events in this class. When I tried to subclass Component, I had to > implement several methods such as getWidth which referred to the skin, which > I don't have. > > It works for me but I'm not sure if it's the right approach. Perhaps I should > subclass Container and attach a subclass of Skin. I still don't know how I > should divide my code between Component and Skin.
There's nothing wrong with subclassing Panel. However, the recommended approach would be to subclass Component and ComponentSkin. In your component's constructor, you can call setSkin(new MyComponentSkin()). That will install the skin and cause mouse, keyboard, etc. events to be directed to the skin. You'd implement your drawing code in your skin's paint() method rather than overriding Component#paint(). G
