Hello,
i need to have the following things:
- a JFrame window, with a JToolbar
- a custom made JPanel wich interact with the mouse
The tool selected in the toolbar modify the way that the mouse interact with the custom made panel.
Now, i build my panel with "new Panel(mainFrame)", so when i need an information about the toolbar, i wildly read public fields of the JFrame when i need it, but i don't think it's the good way.
Is there a good way (the simpler the better) to do way? Even THE way maybe ;) ?
TIA
Frank Liu - 07 Feb 2005 16:40 GMT
I would put a variable in the custom panel, then has the panel implements
ActionListener. Add an instance of the panel to the button's actionListener.
You can then set the variable in the custom panel by using the e.getsource()
method to see which button was pressed.
Frank
> Hello,
>
[quoted text clipped - 13 lines]
>
> TIA
Michael Klaus - 07 Feb 2005 20:04 GMT
> i need to have the following things:
> - a JFrame window, with a JToolbar
> - a custom made JPanel wich interact with the mouse
> The tool selected in the toolbar modify the way that the mouse interact
> with the custom made panel.
An object oriented way would be the State pattern described by GoF:
- create a Tool class which interprets mouse events and can modify your
panel in a custom way (drawing or whatever)
- add a setTool(Tool) method to your panel
- when a toolbar button is pressed, use this method to change the drawing
tool
Hope this helps :)