/* <CODE>
 ****************************************************************
 * Copyright (C) 1997-2000 Micro Focus International Ltd.       *
 * All Rights Reserved.                                         *
 ****************************************************************
 *                                                              *
 * This COBOL program demonstrates how to read and update Java  *
 * Arrays from COBOL.                                           *
 *                                                              *
 *  Version History:                                            *
 *  @author            Micro Focus International Development    *
 *  @version           1.0, Created                             *
 ****************************************************************
 *</CODE>
 */
import java.awt.*;
import java.awt.event.*;

public class Frame1 extends Frame
{

  //Construct the frame
  BorderLayout borderLayout1 = new BorderLayout();
  MenuBar ApplicationMenu = new MenuBar();
  Menu menu1 = new Menu();
  Menu menu2 = new Menu();
  MenuItem menuItem2 = new MenuItem();
  MenuItem menuItem1 = new MenuItem();
  Label ainteger_label = new Label();
  TextField ainteger_field = new TextField();
  Label along_label = new Label();
  GridLayout gridLayout1 = new GridLayout();
  TextField along_field = new TextField();
  Label adouble_label = new Label();
  TextField adouble_field = new TextField();
  TextField afloat_field = new TextField();
  Label afloat_label = new Label();
  Label aboolean_label = new Label();
  TextField aboolean_field = new TextField();
  Label ashort_label = new Label();
  TextField ashort_field = new TextField();
  Label abyte_label = new Label();
  TextField abyte_field = new TextField();
  Label achar_label = new Label();
  TextField achar_field = new TextField();
  Menu menu3 = new Menu();
  MenuItem menuItem3 = new MenuItem();

  BasicCobcall myExample;

  public Frame1()
  {
    try 
    {
      jbInit();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
//Component initialization

  private void jbInit() throws Exception 
  {
    this.setLayout(borderLayout1);
    this.setSize(new Dimension(400, 300));
    this.setTitle("Primative Types Demo");
    menu1.setLabel("File");
    menu2.setLabel("Help");
    menuItem2.setLabel("About");
    menuItem2.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        menuItem2_actionPerformed(e);
      }
    });
    menuItem1.setLabel("Exit");
    ainteger_label.setText("A integer");
    ainteger_field.setEditable(false);
    along_label.setText("A long");
    along_field.setEditable(false);
    adouble_label.setText("A double");
    adouble_field.setEditable(false);
    afloat_field.setEditable(false);
    afloat_label.setText("A float");
    aboolean_label.setText("A boolean");
    aboolean_field.setEditable(false);
    ashort_label.setText("A short");
    ashort_field.setEditable(false);
    abyte_field.setEditable(false);
    achar_label.setText("A char");
    achar_field.setEditable(false);
    menu3.setLabel("Run");
    menuItem3.setLabel("execute \"cobcall\"");
    abyte_label.setText("A byte");
    gridLayout1.setRows(8);
    menuItem1.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        menuItem1_actionPerformed(e);
      }
    });
    this.setLayout(gridLayout1);
    ApplicationMenu.add(menu1);
    ApplicationMenu.add(menu3);
    ApplicationMenu.add(menu2);
    menu2.add(menuItem2);
    this.setMenuBar(ApplicationMenu);
    menu1.add(menuItem1);
    this.add(ainteger_label, null);
    this.add(ainteger_field, null);
    this.add(along_label, null);
    this.add(along_field, null);
    this.add(adouble_label, null);
    this.add(adouble_field, null);
    this.add(afloat_label, null);
    this.add(afloat_field, null);
    this.add(aboolean_label, null);
    this.add(aboolean_field, null);
    this.add(ashort_label, null);
    this.add(ashort_field, null);
    this.add(abyte_label, null);
    this.add(abyte_field, null);
    this.add(achar_label, null);
    this.add(achar_field, null);
    menu3.add(menuItem3);

    myExample = new BasicCobcall(1,2,3,4,false,(short)1,(byte)41,'A');
    menuItem3.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        menuItem3_actionPerformed(e);
      }
    });

    this.addWindowListener(new java.awt.event.WindowAdapter()
    {
      public void windowOpened(WindowEvent e)
      {
        this_windowOpened(e);
      }
    });

      WindowListener listener = new WindowListener();
    ApplicationMenu.setHelpMenu(menu2);
        addWindowListener(listener);
    }


    class WindowListener extends WindowAdapter
    {
        WindowListener()
        {
            super();
        }
        public void windowClosing(WindowEvent e)
        {
            System.exit(0);
        }
    }

  void updateValues()
  {
      aboolean_field.setText(myExample.myOneBoolean.toString());
      abyte_field.setText(myExample.myOneByte.toString());
      achar_field.setText(myExample.myOneChar.toString());
      adouble_field.setText(myExample.myOneDouble.toString());
      afloat_field.setText(myExample.myOneFloat.toString());
      ainteger_field.setText(myExample.myOneInt.toString());
      along_field.setText(myExample.myOneLong.toString());
      ashort_field.setText(myExample.myOneShort.toString());

  }

  void menuItem1_actionPerformed(ActionEvent e)
  {
    System.exit(1);
  }

  void menuItem2_actionPerformed(ActionEvent e)
  {
    AboutBox aboutBox = new AboutBox(this,"COBCALL Parameter Passing Demo",true);
    aboutBox.show();
  }

  void this_windowOpened(WindowEvent e)
  {
    updateValues();
  }

  void menuItem3_actionPerformed(ActionEvent e)
  {
    myExample.call();
    updateValues();
  }
 }

