///////////////////////////////////////////////////////////////////////////////
//                   ALL STUDENTS COMPLETE THESE SECTIONS
// Title:            Satisfiability Test
// Files:            ABMatrix.java, CdbTuple.java, Dialog1.java, Frame1.java,
//                   JTableHeaderToolTips.java, Mytest.java, RowNumberHeader.java
// Semester:         Spring 2007
//
// Author:           Hang Yue, yuehang366@gmail.com
// CS Login:         hyue
// Lecturer's Name:  Dr.Peter Revesz
// Lab Section:      (your lab section number)
//
//                   PAIR PROGRAMMERS COMPLETE THIS SECTION
// Pair Partner:     (name of your pair programming partner)
// CS Login:         (partner's login name)
// Lecturer's Name:  (name of your partner's lecturer)
// Lab Section:      (your partner's lab section number)
//
//                   STUDENTS WHO GET HELP FROM ANYONE OTHER THAN THEIR PARTNER
// Credits:          Scot Anderson
//////////////////////////// 80 columns wide //////////////////////////////////
package satisfiablitytest;

import java.awt.*;
import java.awt.event.*;
import java.io.Serializable;
import javax.swing.*;

public class Frame1 extends JFrame implements Serializable
{
	/**
	 * for Serializable interface
	 */
	 private static final long serialVersionUID = 5334532903567570867L;
	     
	     private JPanel contentPane;
	     private JLabel jLabel1;
	     private JButton jButton1;
	     private JTextField jTextField1;
	     private JButton jButton2;
	     private GridBagLayout gridBagLayout1;
	     private Dialog1 dlg;
	     
	     String [] columnNames = new String [50];
	     
     public Frame1()
     {
          jLabel1 = new JLabel();
          jButton1 = new JButton();
          jTextField1 = new JTextField();
          jButton2 = new JButton();
          gridBagLayout1 = new GridBagLayout();
          dlg = new Dialog1();

          try
          {
        	  contentPane = (JPanel)getContentPane();
              jButton2.setText("EXIT");
              jButton2.addActionListener(new jButton2_actionPerformed());
              contentPane.setLayout(gridBagLayout1);
              setSize(new Dimension(320, 210));
              setTitle("Evaluation with Gap-Graphs");
              setDefaultCloseOperation(2);
              setResizable(false);
              jLabel1.setText("Matrix Variables No.:");  
              setEnabled(true);
              jButton1.setText("OK");
              jTextField1.setText("");
              contentPane.add(jButton1, new GridBagConstraints(0, 6, 1, 1, 0.0D, 0.0D, 13, 0, new Insets(16, 14, 6, 5), 13, 0));
              contentPane.add(jButton2, new GridBagConstraints(1, 6, 2, 1, 0.0D, 0.0D, 17, 0, new Insets(16, 14, 6, 0), 13, 0));   
              contentPane.add(jTextField1, new GridBagConstraints(1, 1, 1, 1, 1.0D, 0.0D, 10, 0, new Insets(3, 0, 2, 3), 69, 1));
              contentPane.add(jLabel1, new GridBagConstraints(0, 0, 1, 2, 0.0D, 0.0D, 14, 0, new Insets(2, 22, 2, 1), 2, 4));
              jButton1.addMouseListener(new MouseAdapter(){
            	 /**
          		 * This method initializes the table values, according to the value that is typed into in textfield
          		 * @param filename
          		 */           
              public void mouseClicked (MouseEvent e)
              {   
                   try
                   {
                        dlg.rows = Integer.parseInt(jTextField1.getText());
                        dlg.setSize(450, 200);
  
                        for(int r = 0; r < dlg.rows; r++)
                        {  dlg.model.addRow(dlg.rowDate);
                           String s = String.valueOf(r+1);
                           columnNames [r]= s;
                           dlg.model.addColumn(columnNames[r]);
                        }       

                        for (int i=0; i<dlg.rows; i++)
             			 for (int j=0; j<dlg.rows; j++)
             				{
             					dlg.model.setValueAt("-¡Þ", i, j);
             				}
                           dlg.setSize(new Dimension(350, 200));
                           dlg.setVisible(true);
                   }
                   catch(NumberFormatException e2)
                   {      
                        System.out.println("input string null");
                   }
                   catch(Exception e3)
                   {
                	   System.out.println("maybe the number of variables is too large");
                   }
              }
              });

          }
          catch(Exception e)
          {
               e.printStackTrace();
          }
     }

     protected void processWindowEvent(WindowEvent e)
     {
          super.processWindowEvent(e);
          if(e.getID() == 201)
               System.exit(0);
     }

     class jButton2_actionPerformed implements ActionListener
     {
      public void actionPerformed (ActionEvent e)
      { 
    	  dispose();
      }
     }

}
