Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2005

Tip: Looking for answers? Try searching our database.

Question about GUI internal design

Thread view: 
test - 07 Feb 2005 15:05 GMT
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 :)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.