Results 1 to 5 of 5

Thread: How to write a Simple Bean?

  1. #1
    Join Date
    Aug 2006
    Posts
    201

    How to write a Simple Bean?

    Hi Friends,
    I have done some basic things in Java and now I have turned towards the Java Bean. I am totally new for the Beans. Its like I am kid when you consider the bean. So expecting some help from you. Please tell me how to write a Simple Bean.?? Since I am new to beans, please explain me in details.!!
    Don't be afraid of darkness, it's in your heart anyway.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How to write a Simple Bean?

    I think that before moving to the features or the coding for Java Beans, I think that you should know about the beans in details. Java beans are reusable software components for Java that can be manipulated visually in a builder tool. That means you can use the Beans again and again. This you will understand when you do the coding of the JavaBeans. Beans are used to encapsulate many objects into a single object, so that they can be passed around as a single bean object instead of as multiple individual objects. A JavaBean is a Java Object that is serializable. Hope that you understand the basic things.

  3. #3
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to write a Simple Bean?

    Before doing the Java Beans, you should know much about the Java. Hope that you know enough so that you can go for the beans. The following code will help you to write the code for the beans which is much simple :
    Code:
    import java.awt.Color;
    import java.beans.XMLDecoder;
    import javax.swing.JLabel;
    import java.io.Serializable;
    
    public class BeanDemo extends JLabel 
                            implements Serializable {
        public BeanDemo() {
            setText( "Hello world!" );
            setOpaque( true );
            setBackground( Color.BLUE );
            setForeground( Color.RED );
            setVerticalAlignment( CENTER );
            setHorizontalAlignment( CENTER );
        } 
    }

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: How to write a Simple Bean?

    You should also know about the classes that gets extended while using the beans. The bean class, for example the 'BeanDemo' used in coding of 'absolute55', extends the javax.swing.JLabel graphic component and inherits its properties. Due to which the BeanDemo becomes a visual component. BeanDemo also implements the java.io.Serializable interface. Your bean may implement either the Serializable or the Externalizable interface. Hope that this helps you .!!

  5. #5
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to write a Simple Bean?

    An object class has some rules which are called as conventions about method naming, construction, and behavior. JavaBeans are usual Java classes which adhere to certain coding conventions. The class must have a public default constructor. You should remember the following things while doing the coding :
    • You should always implements java.io.Serializable interface.
    • You should not provide any argument constructor.
    • The coding provides getter and setter methods for accessing it's properties.

Similar Threads

  1. Media is write protected error cannot write to disk
    By Bracken in forum Operating Systems
    Replies: 14
    Last Post: 22-08-2011, 08:58 AM
  2. Cannot write to drive "Media is write protected"
    By Charlton in forum Vista Hardware Devices
    Replies: 4
    Last Post: 11-05-2011, 10:54 PM
  3. What are the Bean Persistence?
    By hatred in forum Software Development
    Replies: 5
    Last Post: 17-02-2010, 05:57 AM
  4. Write-through and Write-back cache
    By Klaty in forum Motherboard Processor & RAM
    Replies: 5
    Last Post: 29-01-2010, 01:52 PM
  5. Replies: 0
    Last Post: 16-09-2007, 09:32 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,259,048.73315 seconds with 17 queries