3 Replies Latest reply: Jul 9, 2007 12:10 PM by François Degrelle RSS

    My java bean makes my Forms application crashing. Any idea?

    odaboval
      Hello,

      As I said earlier, please excuse my poor skills in java !!

      Here is the problem:
      Using different sources (tutorials, code exemples, OTN forum), I think I managed to build a java bean application.

      Under jDeveloper, it works fine.. I can display a nice graph.
      But when I add the class name in the Oracle Forms bean item, Forms crashes...

      (BTW, I made a test with a very basic Java Bean, and I was able to successfully display the results in Forms)
      We use Forms 10g.
      So, there is something bad in my code ...
      Do you have any suggestion ?

      Here is the code and the java console display :
      1) the java code :
      package oracle.forms.RadarGraph;

      import oracle.forms.handler.IHandler;
      import oracle.forms.ui.CustomEvent;
      import oracle.forms.properties.ID;
      import oracle.forms.ui.VBean;
      import oracle.forms.engine.Main;

      import java.awt.Color;
      import java.awt.Dimension;
      import org.jfree.chart.ChartFactory;
      import org.jfree.chart.ChartPanel;
      import org.jfree.chart.JFreeChart;
      import org.jfree.chart.axis.NumberAxis;
      import org.jfree.chart.plot.PolarPlot;
      import org.jfree.data.xy.XYDataset;
      import org.jfree.data.xy.XYSeries;
      import org.jfree.data.xy.XYSeriesCollection;
      import javax.swing.*;
      import org.jfree.ui.ApplicationFrame;
      import org.jfree.ui.RefineryUtilities;
      import java.lang.String;

      public class PolarChart extends VBean
      {
      JFrame mainFrame;

      static oracle.forms.handler.IHandler mHandler;
      // properties you can set
      protected static final ID SETHIDDEN = ID.registerProperty("SETHIDDEN");
      protected static final ID GETBGCOLOR = ID.registerProperty("GETBGCOLOR");

      public PolarChart(String s)
      {
      mainFrame = new JFrame();
      JPanel jpanel = createPanel();
      mainFrame.setSize(600,500);
      jpanel.setPreferredSize(new Dimension(600, 500));
      mainFrame.setContentPane(jpanel);
      }

      public void init(oracle.forms.handler.IHandler handler)
      {
      super.init(handler);
      mHandler = handler;
      // put your initialisation instructions here
      }


      //
      // Set the properties to the bean
      //
      public boolean setProperty(oracle.forms.properties.ID property, Object value)
      {
      if(property == SETHIDDEN)
      {
      //System.err.printlnln("Set property 01=" + (String)value) ;
      // get the paremeter string:
      String sParam = (String)value;
      if ( sParam.equals("true") )
      setVisible(false);
      else
      setVisible(true);

      return true;
      }
      else // default behaviour
      {
      return super.setProperty(property, value);
      }
      }

      //
      // Get the properties of the bean
      //
      public Object getProperty(oracle.forms.properties.ID property)
      {
      if (property == GETBGCOLOR)
      {
      // return the color of the parent container:
      String sColor = "";
      Color color = this.getParent().getBackground();
      sColor = "r" + color.getRed() + "g" + color.getGreen() + "b" + color.getBlue();
      return sColor ;
      }
      else // default behaviour
      {
      return super.getProperty(property);
      }
      }

      //
      // Send a message to the Forms module
      //
      public void dispatch_event( ID id )
      {
      CustomEvent ce = new CustomEvent(mHandler, id);
      dispatchCustomEvent(ce);
      }


      private static XYDataset createDataset()
      {
      XYSeriesCollection xyseriescollection = new XYSeriesCollection();
      XYSeries xyseries = new XYSeries("Series 1");
      xyseries.add(0.0D, 2D);
      xyseries.add(90D, 13D);
      xyseries.add(180D, 9D);
      xyseries.add(270D, 8D);
      xyseriescollection.addSeries(xyseries);
      XYSeries xyseries1 = new XYSeries("Series 2");
      xyseries1.add(90D, -11.199999999999999D);
      xyseries1.add(180D, 21.399999999999999D);
      xyseries1.add(250D, 17.300000000000001D);
      xyseries1.add(355D, 10.9D);
      xyseriescollection.addSeries(xyseries1);
      return xyseriescollection;
      }

      private static JFreeChart createChart(XYDataset xydataset)
      {
      JFreeChart jfreechart = ChartFactory.createPolarChart("Polar Chart", xydataset, true, false, false);
      jfreechart.setBackgroundPaint(Color.white);
      PolarPlot polarplot = (PolarPlot)jfreechart.getPlot();
      polarplot.setBackgroundPaint(Color.lightGray);
      polarplot.addCornerTextItem("Mesure 1");
      polarplot.addCornerTextItem("Mesure 2");
      NumberAxis numberaxis = (NumberAxis)polarplot.getAxis();
      numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
      return jfreechart;
      }

      public static JPanel createPanel()
      {
      JFreeChart jfreechart = createChart(createDataset());
      ChartPanel chartpanel = new ChartPanel(jfreechart);
      chartpanel.setMouseZoomable(false);
      return chartpanel;
      }

      public void run()
      {
      mainFrame.setVisible(true);
      }

      public static void main(String args[])
      {
      PolarChart polarchart = new PolarChart("Polar Chart");
      //polarchart.pack();
      //RefineryUtilities.centerFrameOnScreen(polarchart);
      polarchart.run();
      // polarchart.setVisible(true);
      }
      }


      ################################
      2) the java console error :
      connectMode=HTTP, native.
      Forms Applet version is : 10.1.2.0
      java.lang.InstantiationException: oracle.forms.RadarGraph.PolarChart
           at java.lang.Class.newInstance0(Native Method)
           at java.lang.Class.newInstance(Unknown Source)
           at oracle.forms.handler.UICommon.instantiate(Unknown Source)
           at oracle.forms.handler.UICommon.onCreate(Unknown Source)
           at oracle.forms.handler.JavaContainer.onCreate(Unknown Source)
           at oracle.forms.engine.Runform.onCreateHandler(Unknown Source)
           at oracle.forms.engine.Runform.processMessage(Unknown Source)
           at oracle.forms.engine.Runform.processSet(Unknown Source)
           at oracle.forms.engine.Runform.onMessageReal(Unknown Source)
           at oracle.forms.engine.Runform.onMessage(Unknown Source)
           at oracle.forms.engine.Runform.sendInitialMessage(Unknown Source)
           at oracle.forms.engine.Runform.startRunform(Unknown Source)
           at oracle.forms.engine.Main.createRunform(Unknown Source)
           at oracle.forms.engine.Main.start(Unknown Source)
           at sun.applet.AppletPanel.run(Unknown Source)
           at java.lang.Thread.run(Unknown Source)


      In advance, thanks a lot for your help.
      Olivier