[ASK] Make Object as a layer
Hi, I want to make a application about paint Application, but i want to make every Object As a Layer (like a Photoshop Application). in Example : I draw a Line in Canvas. That Line i want to make a Layer.
My premise to do that because if i created many object and i developed them to Layers.
If Sometimes i want to delete Each One, it can possible.
How can I do that in Java ? Thanks Before !
Re: [ASK] Make Object as a layer
Several different ways to implement this. A simple way would be the following.
1) Write an object that represents a layer. In the most basic sense, this object should have a method to draw, set visibility, set color, etc...
2) Create an object (call it say MyCanvas) which extends JPanel. This will actually draw all your layers. This object should hold a list of all your layer objects you have or will create.
3) Should you wish to draw using the mouse, you need to add Mouse and MouseMotionListeners to this object and deal with the movements accordingly (add new layers, etc..).
4) Add methods to MyCanvas which can add or delete layers in the list that it holds.
4) Override the paintComponent method of the JPanel. In this method iterate through your list of layers and call their drawing routine.
Again there is more than one way to design something like this, and the above is just one basic way to do so. Hopefully it will help you get the ball rolling
Re: [ASK] Make Object as a layer
Wow... Thanks Before for your Explained !
But I want to ask again for the same topic. hehe.... ^^
Yesterday, My friend told me about JComponent. He said, to make an Object which can be deleted, moved, and resized , I should make the Object as JComponent. But I didn't understand "How JComponent worked in Java".