Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: [ASK] Make Object as a layer

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Thanked 1 Time in 1 Post

    Default [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 !

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 833 Times in 772 Posts
    Blog Entries

    Default 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

  3. The Following User Says Thank You to copeg For This Useful Post:

    bocahTuaNakalzz (October 24th, 2009)

  4. #3
    Junior Member
    Join Date
    Sep 2009
    Thanked 1 Time in 1 Post

    Default 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".

Similar Threads

  1. Object o = new Object(); need help
    By zeeshanmirza in forum Object Oriented Programming
    Replies: 11
    Last Post: January 6th, 2010, 10:01 PM
  2. Having trouble printing object information in main class
    By KingLane in forum Object Oriented Programming
    Replies: 1
    Last Post: October 11th, 2009, 06:53 PM
  3. make textbox in canvas
    By mahdi in forum Java ME (Mobile Edition)
    Replies: 2
    Last Post: October 6th, 2009, 07:10 AM
  4. How can i make the components resizable?
    By ces_31 in forum AWT / Java Swing
    Replies: 4
    Last Post: October 1st, 2009, 10:46 AM
  5. Java algorithm for bank program to connect database
    By araujo3rd in forum Algorithms & Recursion
    Replies: 1
    Last Post: December 10th, 2008, 01:34 PM