The Artima Developer Community
Sponsored Link

Java Answers Forum
How to get values from a domino form into an applet

1 reply on 1 page. Most recent reply: Jan 2, 2003 12:42 PM by Kishori Sharan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
subha

Posts: 1
Nickname: subha
Registered: Jan, 2003

How to get values from a domino form into an applet Posted: Jan 2, 2003 4:04 AM
Reply to this message Reply
Advertisement
Hi,

I am having an applet which is embedded in a domino form.There are some hidden fields in the form,whose values i have to pass to applet(java file) for dispalying the applet..

here by I am attatching my code:

/*Program to display graphs*/

import java.awt.Paint;
import java.awt.Color;
import com.jrefinery.chart.JFreeChart;
import com.jrefinery.chart.ChartFactory;
import com.jrefinery.chart.ChartPanel;
import com.jrefinery.chart.CategoryPlot;
import com.jrefinery.chart.HorizontalCategoryAxis;
import com.jrefinery.chart.NumberAxis;
import com.jrefinery.data.DefaultCategoryDataset;
import com.jrefinery.ui.ApplicationFrame;
import com.jrefinery.ui.RefineryUtilities;
import javax.swing.JFrame;
public class AreaChart extends java.applet.Applet {
 
	public void init() {
[b]
/*here values are hardcoded but these have to come from hidden 	fields of a domino form*/[/b]
		 // create a dataset...
        double[][] data = new double[][] {
            { 1.0, 4.0, 3.0, 5.0, 5.0, 7.0, 7.0, 8.0 },
            { 5.0, 7.0, 6.0, 8.0, 4.0, 4.0, 2.0, 1.0 },
            { 4.0, 3.0, 2.0, 3.0, 6.0, 3.0, 4.0, 3.0 }
        };
 
        DefaultCategoryDataset dataset = new DefaultCategoryDataset(data);
 
        // set the series names...
        String[] seriesNames = new String[] { "First", "Second", "Third" };
        dataset.setSeriesNames(seriesNames);
 
        // set the category names...
        String[] categories = new String[] { "Type 1", "Type 2", "Type 3", "Type 4",
                                             "Type 5", "Type 6", "Type 7", "Type 8"  };
        dataset.setCategories(categories);
 
        // create the chart...
        JFreeChart chart = ChartFactory.createAreaChart("Area Chart",  // chart title
                                                        "Category",    // domain axis label
                                                        "Value",       // range axis label
                                                        dataset,       // data
                                                        true,          // include legend
                                                        true,          // tooltips
                                                        false          // urls
                                                        );
 
        // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
 
        // set the background color for the chart...
        chart.setBackgroundPaint(Color.yellow);
 
        // get a reference to the plot for further customisation...
        CategoryPlot plot = chart.getCategoryPlot();
        plot.setForegroundAlpha(0.5f);
        plot.setIntroGapPercent(0.0);
        plot.setTrailGapPercent(0.0);
        // label data points with values...
        plot.setLabelsVisible(true);
 
        // set the color for each series...
        plot.setSeriesPaint(new Paint[] { Color.green, Color.orange, Color.red });
 
 
        // change the auto tick unit selection to integer units only...
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
 
        HorizontalCategoryAxis domainAxis = (HorizontalCategoryAxis) plot.getDomainAxis();
        domainAxis.setVerticalCategoryLabels(true);
 
        // add the chart to a panel...
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        add(chartPanel);
        //setContentPane(chartPanel);
        System.out.println("finished1111111111111");
 
 
 
	}
 
 
    }

and a dominoform whichtakes the values and diplays the graph

Please help me in locating a way to set the values

Thanks in advance
Subha


Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: How to get values from a domino form into an applet Posted: Jan 2, 2003 12:42 PM
Reply to this message Reply
I am assuming that you want to read values from hidden fields in HTML form from an applet. At the end , you can find the code for the applet and HTML file. I have demonstrated this with text input in a form. However, it will work for hidden fields too.
1. Within applet you need to get the reference of the window Javascript object. You can do this inside an applet as follows.
netscape.javascript.JSObject win = netscape.javascript.JSObject.getWindow ( this );

In above code, "this" argument to getWindow() method refers to the applet itself. After this code is executed, then win is the reference to the JavaScript window object. Since you can call eval() method on window object, you do it as;
String value = (String)win.eval ( "document.form1.name1" ) ;

This way you can read the values from form fields.
2. If you have any Javascript function then yu can call it using call() method on window object as:
win.call ( "your_cunction_name", your_arguments_wrapped ) ;

Please visit this link for details:http://java.sun.com/products/plugin/1.3/docs/jsobject.html

////////////////////////////////////////////////////////
Applet code and HTML file are below...
In applet code you would be interested only in
void jButton1_actionPerformed(ActionEvent e) method code
///////////////////////////////////////////////////////

/******** Applet code ******************/
package applettojs;
 
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
 
public class TestApplet extends JApplet {
  private boolean isStandalone = false;
  private JPanel jPanel1 = new JPanel();
  private GridBagLayout gridBagLayout1 = new GridBagLayout();
  private JLabel jLabel1 = new JLabel();
  private JTextField formFieldName = new JTextField();
  private JLabel jLabel2 = new JLabel();
  private JTextField valueField = new JTextField();
  private JButton jButton1 = new JButton();
  //Get a parameter value
  public String getParameter(String key, String def) {
    return isStandalone ? System.getProperty(key, def) :
      (getParameter(key) != null ? getParameter(key) : def);
  }
 
  //Construct the applet
  public TestApplet() {
  }
  //Initialize the applet
  public void init() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  //Component initialization
  private void jbInit() throws Exception {
    this.setSize(new Dimension(400,300));
    jPanel1.setLayout(gridBagLayout1);
    jLabel1.setText("Form Field Name(Fully-qualified):");
    formFieldName.setText("document.form1.name1");
    jLabel2.setText("Field Value:");
    valueField.setText("                             ");
    jButton1.setText("Get Value");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton1_actionPerformed(e);
      }
    });
    this.getContentPane().add(jPanel1, BorderLayout.CENTER);
    jPanel1.add(jLabel1,     new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(formFieldName,   new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jLabel2,     new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(valueField,   new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(jButton1,  new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
  }
  //Start the applet
  public void start() {
  }
  //Stop the applet
  public void stop() {
  }
  //Destroy the applet
  public void destroy() {
  }
  //Get Applet information
  public String getAppletInfo() {
    return "Applet Information";
  }
  //Get parameter info
  public String[][] getParameterInfo() {
    return null;
  }
  //Main method
  public static void main(String[] args) {
    TestApplet applet = new TestApplet();
    applet.isStandalone = true;
    JFrame frame = new JFrame();
    //EXIT_ON_CLOSE == 3
    frame.setDefaultCloseOperation(3);
    frame.setTitle("Applet Frame");
    frame.getContentPane().add(applet, BorderLayout.CENTER);
    applet.init();
    applet.start();
    frame.setSize(400,320);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
    frame.setVisible(true);
  }
 
  //static initializer for setting look & feel
  static {
    try {
      //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    }
    catch(Exception e) {
    }
  }
 
  void jButton1_actionPerformed(ActionEvent e) {
    /* Get the value of the field from HTML Page */
 
    // First get the browser window reference
    netscape.javascript.JSObject win = netscape.javascript.JSObject.getWindow ( this );
 
    // Get the fully-qualified name of form field
    String fieldName = this.formFieldName.getText();
 
    // Call the method eval on window to get the value from
    // YOu can use call() method on win object to call any
    // Javascript function. See documentation for call
    String result = (String)win.eval(fieldName + ".value");
 
    // Set the result in another field
    this.valueField.setText(result);
 
  }
 
}

/************Applet code ends here *****/
/******** HTMl File content ******************/
<html>
<head>
<title>
HTML Test Page
</title>
</head>
<body>
<applet
codebase = "."
code = "applettojs.TestApplet.class"
name = "TestApplet"
width = "400"
height = "300"
hspace = "0"
vspace = "0"
align = "middle"
>
</applet>
<br/></br>Below is form1 with two fields name1 and name2:
<form name="form1">
Name1:<input type="text" name="name1" Value="105">
Name2:<input type="text" name="name2" Value="123">
</form>
</body>
</html>

/************HTML File content ends here *****/

Flat View: This topic has 1 reply on 1 page
Topic: Choosing between session.getDefaultInstance,session.getInstance in javamail Previous Topic   Next Topic Topic: Object Streams

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use