Howdy
I am new to java and I think the project I chose to teach myself was maybe a little on the ambitious side.
In essence I have 2 classes, say, Class A and Class B that are defined at the same level (i hope that makes sense)
Class A contains a linked list of instances of Class B.
Some behaviours defined in Class B need to effect or be effected by the state of the other instances of Class B in the LinkedList
An instance of Class B may receive an event that means it needs to remove it self from the list, or change the position relative to the other Class B instances .
How do i reference the other members of the linked list, How do i reference anything in the instance of Class A which contains the instance of Class B recieving the mouse event?
Any ideas?
A brief explanation of what I am trying to achieve follows.
You can think of the main form as being, say, a drafting table.
Conceptually I want to be able to add, remove, move and resize 'sheets of paper' on the drafting table and on each sheet of paper I want to be able to add, remove, move and resize shapes. These shapes could be to represent different elements of a flow chart, or electrical components in an electronic circuit, etc. The shapes should not be allowed to overlap.
For the 'sheets of paper' I have a class based on a JPanel, that handles its own resizing etc. The 'shapes' are also a class based on JPanel that handle their own resizing.
The main form or (drafting table) has a linked list of instances of 'sheet' class and each instance of 'sheet' class has a linked list of instances of 'shape' class.
Now when I want to add a shape, the instance of the 'sheet' class handles the mouse click and runs through its linked list of 'shape' class instances to see if this is a valid location, ie is does not overlap another 'shape'. If it is a valid location it adds it to the linked list.
What I am having trouble with is when i resize or move a 'shape'. the mouse event is handled in the 'shapes' class but I don not know how to check the other 'shape' class instances to see if the new location or size is valid.
thanks in advance for any help,
Shade


LinkBack URL
About LinkBacks
Reply With Quote

