• Post Reply Bookmark Topic Watch Topic
  • New Topic

managing listeners on many containers and components.  RSS feed

 
Samer Telawi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dears,
currently I am working on some application which has functions look like Cisco Packet tracer,
so I have Jpanel that contains JButtons which represent different devices.
and drawing Jpanel on which the devices will be added and connected ( design the required structure form the available components)
till now I wrote some code so I can add components, delete them, moving these components.
but I am facing a problem with listeners on which component I should add the listener for example:
I have a class
public class DrawingPanel extends JPanel impelements MouseMotionListener, MouseListener

this works with me when adding components into the drawing panel and moving them but
if I want to draw a line between two components on this panel and the line should be dragaable and only starts form the specific component till it reach an acceptable type of devices ...
I am a little bit confused where to this function and how to solve it .... beside if I want to draw a rectangle by pressing the mouse and dragging to select many devices ....
so I can post some code about the application I need some suggestion about how to manage listeners when we have many components with many features like adding components moving them linking them and moving them after being linked ..
I really appreciate any help and for more question please just let me know
Filename: final.bmp
File size: 65 Kbytes
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had difficulty opening your file, so I asked the other mods and was given another link. Does it look like this?
 
Samer Telawi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot,
yes that is the picture it was taken form Cisco packet Tracer because I am working on some application look a little bit like it.
the upper part form the picture shows how to draw a line form the component on the drawing area in the application
and second one shows drawing a rectangle by using press and drag by the mouse to select multiple components to execute some action on all of them
the part in the bottom shows a panel of button that would be used to draw different components on the drawing panel.
so now I have many graphical component like buttons I need to click on to choose a component to be drawn on the drawing panel and this component should be movable and capable to be liked with other
component by drawing some lines ...
many functions the problem is that I tried to write some code
it works like adding components, moving , deleting , but drawing lines works with many mistakes
the problem is with all these components I am confused how to manage the listeners on which component I should implement each one
so for some cases if you know some plan to follow some pattern ... I do not know ..
if code is needed i can provide some .
thanks
best regards
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!