Java
While I was working with Oracle Forms, I needed to add a JavaBean to my form. But when I wanted to determine Implementation Class property of the bean item, I got an error of FRM-13008: Cannot find JavaBean with name ‘oracle.forms.mybean’. This was the time when I decided to write my own JavaBean and add this component to Netbeans IDE. Because I wanted to be sure if there was something wrong with my JavaBean or not.
- Open Netbeans IDE.
- Choose File/New Project. In the opened window choose Java/Java Application. In the next step write SimpleBean as a project name. ( Java is a case-sensitive language. ) Uncheck Create Main Class. Then press Finish.
- Right click project name, you created. Choose New/Java Class and then Finish.
- Write the code below in SimpleBean.java:
import java.awt.Color;
import java.beans.XMLDecoder;
import javax.swing.JLabel;
import java.io.Serializable;public class SimpleBean extends JLabel
implements Serializable {
public SimpleBean() {
setText( “Hello world!” );
setOpaque( true );
setBackground( Color.RED );
setForeground( Color.YELLOW );
setVerticalAlignment( CENTER );
setHorizontalAlignment( CENTER );
}
} - In the Project Window that is in the left hand side of NetBeans IDE Window, right click SimpleBean.java, choose Compile File.
- While NetBeans is compiling your java code, it is also creating class file, too. You can findĀ this file’s path by right clicking SimpleBean.java from Project Window and choose Properties, Runtime Classpath. Check if there is a file called SimpleBean.class in that path.
- We need to create a jar file from our class file. Open command prompt. Go to the path where your jar.exe is. It must be under the bin directory of your jdk. Execute your command that is like:
C:\Program Files\Java\jdk1.6.0_10\bin>jar cvf SimpleBean.jar C:\Duygu\Java\beanPrj\build\classes\SimpleBean.class
This command will write SimpleBean.jar file in the same directory where the jar.exe is. - Right click your project name in the Project Window, choose New/JFrame Form.
- Right click Palette that is in the right handside, choose Palette Manager to add your Bean as a component. Click Add From Jar… button, find your SimpleBean.jar file, select Beans from Palette category. You will see your new component under the Beans category in the Palette window.
