/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package guidemo;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.util.*;

/**
 *
 * @author jxc064000
 */

class SimpleWindow extends JFrame
{
      private JLabel label;
      private JTextField kilometers;
      private JTextField miles;
      private JButton okButton;
      private JPanel panel;
      private JList list1;
      
      
      
        public SimpleWindow()
        {
      final int WINDOW_WIDTH = 450;   // Window width in pixels
      final int WINDOW_HEIGHT = 250;  // Window height in pixels

      // Create a window.
      
      // Set the title.
      setTitle("A Simple Window with a Panel");

      // Set the size of the window.
      setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
     
      StringTokenizer st = new StringTokenizer("A+B*(C-D)*4", "+-*()",true);
      while (st.hasMoreTokens())
      {
          System.out.println(st.nextToken());
      }
      Integer i1 = new Integer(7);
      Integer i2 = new Integer(i1);
      Integer i3 = new Integer((int) Math.sqrt(5));
      i3 = i1;
      
      Double d2 = new Double(10.0);
      d2 = d2/3;
      System.out.println("d2 = " + d2.toString());
      System.out.println("i1 in binary: " + Integer.toBinaryString(i1));
      Long l1;
      System.out.println(Long.MIN_VALUE);
      l1 = Long.MAX_VALUE;
      System.out.println(l1);
  
      // Specify what happens when the close button is clicked.
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      label = new JLabel("Enter the distance in kilometers");
      kilometers = new JTextField(10);
      miles = new JTextField(10);
      okButton = new JButton("Convert to Miles");
      panel = new JPanel();
      panel.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
      // panel.setLayout(new FlowLayout(FlowLayout.LEFT,30,20));
      panel.setLayout(new GridLayout(2,3));
      add(panel);
      JPanel panel2 = new JPanel();
      panel2.setSize(10,10);
      panel2.setLayout(new FlowLayout());
      add(panel2);
      String[] array1 = {"zzz", "def", "ghi"};
      list1 = new JList(array1);

      list1.addListSelectionListener(new ListListener());
      
      String sTemp;
      int[] a1 = new int[5];
      a1[0] = 333;
      arraytest(a1);
      System.out.println("a1=" + a1[0]);
      panel.add(list1);
      panel.add(label);
      panel.add(kilometers);
      panel.add(miles);
      panel.add(okButton);
      System.out.println(panel.toString());
      //???okButton.enable(false);
      //okButton.setVisible(false);
      okButton.addActionListener(new OKButtonListener());
      kilometers.addActionListener(new KiloListener());
      // Display the window.
      setVisible(true);
        }
        
        private void arraytest(int[] testArray)
        {
            testArray[0] = 1000;
            int[] a2 = new int[5];
            a2[0] = 444;
            testArray = a2;
        }
        
        // This class has methods that are called when a list item is selected.
        private class ListListener implements ListSelectionListener
        {
            // Show the index of the item selected.
       /* public void actionPerformed(ActionEvent e)
        {
            System.out.println("Item selected: " + list1.getSelectedIndex());
       
        }*/
        // Also show the index of the item selected.
        public void valueChanged(ListSelectionEvent e)
        {
            System.out.println("Item selected: " + list1.getSelectedIndex());
            System.out.println("List item: " + list1.getSelectedValue().toString());
        }
        }
        
        
        private class KiloListener implements ActionListener
        {
        public void actionPerformed(ActionEvent e)
        {
            System.out.println("Item selected: " + list1.getSelectedIndex());
        }
        }
        
        
        
      private class OKButtonListener implements ActionListener
      {
     public void actionPerformed(ActionEvent e)
      {
         String temp = e.getActionCommand();
      double dMiles;
      String strMiles;
      dMiles = Double.parseDouble(kilometers.getText()) * .6;
      strMiles = dMiles + " ";
      miles.setText(strMiles);
      miles.setBackground(Color.LIGHT_GRAY);

      }

   }
}

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
      SimpleWindow simple = new SimpleWindow();
      simple.setLocation(100,100);
      
    }
    
    
}

