/** <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
   */
  MenuBar ApplicationMenu = new MenuBar();
  Menu menu1 = new Menu();
  Menu menu2 = new Menu();
  MenuItem menuItem2 = new MenuItem();
  MenuItem menuItem1 = new MenuItem();
  Menu menu3 = new Menu();
  List before = new List();
  List after = new List();
  MenuItem menuItem3 = new MenuItem();
  Label label1 = new Label();
  Panel panel1 = new Panel();
  Label label2 = new Label();
  Panel panel2 = new Panel();
  GridLayout gridLayout2 = new GridLayout();
  BorderLayout borderLayout1 = new BorderLayout();

  CobolArrays cobolArray = new CobolArrays();
  int simpleIntegerArray[] = new int[] {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
  boolean simpleBooleanArray[] = new boolean[]
    { true,false,
      true,true, false,false,
      true,true,true,  false,false,false
    };

  float simpleFloatArray[] = new float[]
    {
      (float)0.5, (float)1.0, (float)1.5, (float)2.0, (float)2.5,
      (float)-0.5, (float)-1.0, (float)-1.5, (float)-2.0, (float)-2.5
    };

  double simpleDoubleArray[] = new double[]
    {
      (double)100.5, (double)101.0, (double)101.5, (double)102.0, (double)102.5,
      (double)-100.5, (double)-101.0, (double)-101.5, (double)-102.0,
      (double)-102.5
    };
  short simpleShortArray[] = new short[]
    {
      (short)200, (short)201, (short)201, (short)202.0, (short)203,
      (short)-200, (short)-201, (short)-201, (short)-202.0,
      (short)-203
    };
  long simpleLongArray[] = new long[]
    {
      (long)300, (long)301, (long)301, (long)302, (long)304,
      (long)-300, (long)-301, (long)-301, (long)-302,
      (long)-304
    };

  byte simpleByteArray[] = new byte[]
    {
      (byte)'C', (byte)'O', (byte)'B', (byte)'O', (byte)'L', (byte)' ',
      (byte)'&', (byte)' ',
      (byte)'J', (byte)'a', (byte)'v', (byte)'a'
    };

  char simpleCharArray[] = new char[]
    {
      (char)'C', (char)'O', (char)'B', (char)'O', (char)'L',
      (char)' ', (char)'&', (char)' ',
      (char)'J', (char)'a', (char)'v', (char)'a'
    };

  MenuItem menuItem4 = new MenuItem();
  MenuItem menuItem5 = new MenuItem();
  MenuItem menuItem6 = new MenuItem();
  MenuItem menuItem7 = new MenuItem();
  MenuItem menuItem8 = new MenuItem();
  MenuItem menuItem9 = new MenuItem();
  MenuItem menuItem10 = new MenuItem();
  GridLayout gridLayout1 = new GridLayout();

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

  /*
   * Component initialization
   */
  private void jbInit() throws Exception
  {
    this.setSize(new Dimension(598, 335));
    this.setTitle("Manipulating Java Arrays from COBOL");
    ApplicationMenu.setHelpMenu(menu2);
    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");
    menu3.setLabel("Run");
    menuItem1.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        menuItem1_actionPerformed(e);
      }
    });
    this.setLayout(borderLayout1);
    label2.setBackground(Color.lightGray);
    label2.setFont(new Font("Helvetica", 0, 16));
    label1.setBackground(Color.lightGray);
    label1.setFont(new Font("Helvetica", 0, 16));
    ApplicationMenu.add(menu1);
    ApplicationMenu.add(menu3);
    ApplicationMenu.add(menu2);
    menu2.add(menuItem2);
    this.setMenuBar(ApplicationMenu);
    menu1.add(menuItem1);
    this.add(panel2, BorderLayout.SOUTH);
    panel2.add(label2, null);
    panel2.add(label1, null);
    this.add(panel1, BorderLayout.CENTER);
    panel1.add(before, null);
    panel1.add(after, null);
    menu3.add(menuItem3);
    menu3.add(menuItem4);
    menu3.add(menuItem5);
    menu3.add(menuItem6);
    menu3.add(menuItem7);
    menu3.add(menuItem8);
    menu3.add(menuItem9);
    menu3.add(menuItem10);
    WindowListener listener = new WindowListener();
    this.addWindowListener(new java.awt.event.WindowAdapter()
    {
      public void windowOpened(WindowEvent e)
      {
        this_windowOpened(e);
      }
    });
    label1.setAlignment(1);
    label2.setAlignment(1);
    panel2.setLayout(gridLayout1);
    menuItem10.setLabel("char[] demo");
    menuItem10.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        menuItem10_actionPerformed(e);
      }
    });
    menuItem9.setLabel("byte[] demo");
    menuItem9.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        menuItem9_actionPerformed(e);
      }
    });
    menuItem8.setLabel("long[] demo");
    menuItem8.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        menuItem8_actionPerformed(e);
      }
    });
    menuItem7.setLabel("short[] demo");
    menuItem7.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        menuItem7_actionPerformed(e);
      }
    });
    menuItem6.setLabel("double[] demo");
    menuItem6.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        menuItem6_actionPerformed(e);
      }
    });
    menuItem5.setLabel("float[] demo");
    menuItem5.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        menuItem5_actionPerformed(e);
      }
    });
    menuItem4.setLabel("boolean[] demo");
    menuItem4.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        menuItem4_actionPerformed(e);
      }
    });
    panel1.setLayout(gridLayout2);
    label2.setText("Before call to COBOL");
    label1.setText("After call to COBOL");
    menuItem3.setLabel("integer[] demo");
    menuItem3.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        menuItem3_actionPerformed(e);
      }
    });
    after.setBackground(SystemColor.control);
    before.setBackground(SystemColor.control);

  }


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


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

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



  void this_windowClosed(WindowEvent e)
  {
    System.exit(0);
  }

  void menuItem3_actionPerformed(ActionEvent e)
  {
    after.removeAll();
    before.removeAll();
    cobolArray.increment(before,after,simpleIntegerArray);
  }

  void menuItem4_actionPerformed(ActionEvent e)
  {
    after.removeAll();
    before.removeAll();
    cobolArray.increment(before,after,simpleBooleanArray);
  }

  void menuItem5_actionPerformed(ActionEvent e)
  {
    after.removeAll();
    before.removeAll();
    cobolArray.increment(before,after,simpleFloatArray);
  }

  void menuItem6_actionPerformed(ActionEvent e)
  {
    after.removeAll();
    before.removeAll();
    cobolArray.increment(before,after,simpleDoubleArray);
  }

  void menuItem7_actionPerformed(ActionEvent e)
  {
    after.removeAll();
    before.removeAll();
    cobolArray.increment(before,after,simpleShortArray);
  }

  void menuItem8_actionPerformed(ActionEvent e)
  {
    after.removeAll();
    before.removeAll();
    cobolArray.increment(before,after,simpleLongArray);
   }

  void menuItem9_actionPerformed(ActionEvent e)
  {
    after.removeAll();
    before.removeAll();
    cobolArray.increment(before,after,simpleByteArray);
   }

  void menuItem10_actionPerformed(ActionEvent e)
  {
    after.removeAll();
    before.removeAll();
    cobolArray.increment(before,after,simpleCharArray);
  }

  void this_windowOpened(WindowEvent e)
  {
    before.add("");
    before.add("");
    before.add("");
    before.add("");
    before.add("Pull down 'RUN' to choose a demo");
  }

}

