package ndp.geneousproperties.rentals;


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import houses.HouseElement;
import java.lang.reflect.*;

public class InfoColumn extends JPanel
{
    protected static HouseElement[] house;
    protected static JTextField nameTextCO, shortTextCO;

    public InfoColumn(HouseElement[] hse)
    {
        house = hse;

        setLayout (new GridLayout (2, 2));
        setBackground (Color.GREEN);
        setVisible(true);

        JLabel nameCO = new JLabel ("Name: ");
        nameTextCO =
              new JTextField(house[Control.getSelectedHse()].getHOUSENAME(), 8);

        JLabel shortCO = new JLabel ("Short: ");
        shortTextCO =
              new JTextField(house[Control.getSelectedHse()].getSHORTNAME(), 8);

        nameTextCO.addActionListener (new NameListener());
        shortTextCO.addActionListener (new NameListener());

        String firstWord = "Hello ";
      String secondWord = "everybody.";
      String bothWords = append(firstWord, secondWord);
      System.out.println(bothWords);


        add(nameCO);
        add(nameTextCO);
        add(shortCO);
        add(shortTextCO);
    }

   //*****************************************************************
   //  Repaint HOUSE NAMES on Names Panel.
   //*****************************************************************
   private static void repaintNames()
   {
       nameTextCO.setText(house[Control.getSelectedHse()].getHOUSENAME());
       shortTextCO.setText(house[Control.getSelectedHse()].getSHORTNAME());
   }

   //*****************************************************************
   //  Represents an action listener for the temperature input field.
   //*****************************************************************
   private class NameListener implements ActionListener
   {
      //--------------------------------------------------------------
      //  Grabs and stores into internal Arrays of XML Document when
      //  the enter key is pressed in the text field.
      //--------------------------------------------------------------
      public void actionPerformed (ActionEvent event)
      {
         house[Control.getSelectedHse()].setHOUSENAME(nameTextCO.getText());
         house[Control.getSelectedHse()].setSHORTNAME(shortTextCO.getText());
         repaintNames();
      }
   }

 public static String append(String firstWord, String secondWord)   //Sun
 {                                                                  //Sun
    String result = null;                                           //Sun
    String result2 = null;                                          //me
    Class c = String.class;                                         //Sun
    Class c2 = house.getClass();                                    //me
    Class[] parameterTypes = new Class[] {String.class};            //Sun
    Method concatMethod;                                            //Sun
    Method houseGetMethod;                                          //me
    Method houseSetMethod;                                          //me
    Object[] arguments = new Object[] {secondWord};                 //Sun
    System.out.println(nameTextCO.getText());                       //me
    String shortName = nameTextCO.getText();                        //me
    Object[] arguments2 = new Object[] {shortName};                 //me
    try {                                                           //Sun
      concatMethod = c.getMethod("concat", parameterTypes);         //Sun
      houseGetMethod = c2.getMethod("getHOUSENAME", null);          //me
      result = (String) concatMethod.invoke(firstWord, arguments);  //Sun
      result2 = (String) houseGetMethod.invoke(house[0], null);     //me
      System.out.println(result2);                                  //me
    } catch (NoSuchMethodException e) {                             //Sun
        System.out.println(e);                                      //Sun
    } catch (IllegalAccessException e) {                            //Sun
        System.out.println(e);                                      //Sun
    } catch (InvocationTargetException e) {                         //Sun
        System.out.println(e);                                      //Sun
    }                                                               //Sun
    return result;                                                  //Sun
 }

}

