// SpecTcl generated class Demo2, version 1.2

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

public class Demo2 extends Helper implements ActionListener {		

// a slot to hold an arbitrary object pointer that can
// be filled in by the app. and referenced in actions
private Object arg;

private JPanel frame_1;
private JButton button_2;
private JLabel label_1;
private JButton button_3;
private JButton button_4;
private JButton button_1;
private JLabel label_2;
protected JTextField name;
private JLabel label_3;
protected JTextField phone;
protected JLabel message;

//methods to support form introspection
private static String names[] = {
	"frame_1","button_2","label_1","button_3","button_4","button_1","label_2","name","label_3","phone","message",
};
public String[] getNames() {
	return names;
}

//There should be an easier way to do this
public Object[] getWidgets() {
	Object[] list = new Object[11];
	list[0] = frame_1;
	list[1] = button_2;
	list[2] = label_1;
	list[3] = button_3;
	list[4] = button_4;
	list[5] = button_1;
	list[6] = label_2;
	list[7] = name;
	list[8] = label_3;
	list[9] = phone;
	list[10] = message;
	return list;
}

// Application specific widget data
private static String check_private[] = {
	null, null, null, null, null, null, null, "a*", null, "999-9999", null, 
};
public String[] check() {
	return check_private;
}


public void init() {

	// main panel
	GridBagLayout grid = new GridBagLayout();
	int rowHeights[] = {0,30,30,30,5,30,13};
	int columnWidths[] = {0,30,30};
	double rowWeights[] = {0.0,0.0,0.0,0.0,1.0,0.0,0.0};
	double columnWeights[] = {0.0,0.0,1.0};
	grid.rowHeights = rowHeights;
	grid.columnWidths = columnWidths;
	grid.rowWeights = rowWeights;
	grid.columnWeights = columnWeights;

	// container frame_1 in this.
	GridBagLayout frame_1_grid = new GridBagLayout();
	int frame_1_rowHeights[] = {0,30};
	int frame_1_columnWidths[] = {0,30,30,30,5,30};
	double frame_1_rowWeights[] = {0.0,0.0};
	double frame_1_columnWeights[] = {0.0,0.0,0.0,0.0,1.0,0.0};
	frame_1_grid.rowHeights = frame_1_rowHeights;
	frame_1_grid.columnWidths = frame_1_columnWidths;
	frame_1_grid.rowWeights = frame_1_rowWeights;
	frame_1_grid.columnWeights = frame_1_columnWeights;

	frame_1 = new JPanel();
	this.getContentPane().add(frame_1);

	button_2 = new JButton();
	button_2.addActionListener(this);
	button_2.setText("get");
	frame_1.add(button_2);

	label_1 = new JLabel();
	label_1.setFont(new Font("Helvetica",Font.PLAIN + Font.BOLD , 14));
	label_1.setText("Sample database app");
	this.getContentPane().add(label_1);

	button_3 = new JButton();
	button_3.addActionListener(this);
	button_3.setText("set");
	frame_1.add(button_3);

	button_4 = new JButton();
	button_4.addActionListener(this);
	button_4.setFont(new Font("Helvetica",Font.PLAIN + Font.BOLD , 12));
	button_4.setText("save");
	frame_1.add(button_4);

	button_1 = new JButton();
	button_1.addActionListener(this);
	button_1.setText("quit");
	frame_1.add(button_1);

	label_2 = new JLabel();
	label_2.setText("name");
	this.getContentPane().add(label_2);

	name = new JTextField(20);
	name.addActionListener(this);
	this.getContentPane().add(name);

	label_3 = new JLabel();
	label_3.setText("phone");
	this.getContentPane().add(label_3);

	phone = new JTextField(20);
	phone.addActionListener(this);
	this.getContentPane().add(phone);

	message = new JLabel();
	message.setText(".");
	this.getContentPane().add(message);

	// Geometry management
	GridBagConstraints con = new GridBagConstraints();
	reset(con);
	con.gridx = 1;
	con.gridy = 5;
	con.gridwidth = 2;
	con.anchor = GridBagConstraints.CENTER;
	con.fill = GridBagConstraints.HORIZONTAL;
	grid.setConstraints(frame_1, con);

	reset(con);
	con.gridx = 1;
	con.gridy = 1;
	con.anchor = GridBagConstraints.CENTER;
	con.fill = GridBagConstraints.NONE;
	frame_1_grid.setConstraints(button_2, con);

	reset(con);
	con.gridx = 1;
	con.gridy = 1;
	con.gridwidth = 2;
	con.anchor = GridBagConstraints.CENTER;
	con.fill = GridBagConstraints.NONE;
	grid.setConstraints(label_1, con);

	reset(con);
	con.gridx = 2;
	con.gridy = 1;
	con.anchor = GridBagConstraints.CENTER;
	con.fill = GridBagConstraints.NONE;
	frame_1_grid.setConstraints(button_3, con);

	reset(con);
	con.gridx = 3;
	con.gridy = 1;
	con.anchor = GridBagConstraints.CENTER;
	con.fill = GridBagConstraints.NONE;
	frame_1_grid.setConstraints(button_4, con);

	reset(con);
	con.gridx = 5;
	con.gridy = 1;
	con.anchor = GridBagConstraints.CENTER;
	con.fill = GridBagConstraints.NONE;
	frame_1_grid.setConstraints(button_1, con);

	reset(con);
	con.gridx = 1;
	con.gridy = 2;
	con.anchor = GridBagConstraints.EAST;
	con.fill = GridBagConstraints.NONE;
	grid.setConstraints(label_2, con);

	reset(con);
	con.gridx = 2;
	con.gridy = 2;
	con.anchor = GridBagConstraints.CENTER;
	con.fill = GridBagConstraints.HORIZONTAL;
	grid.setConstraints(name, con);

	reset(con);
	con.gridx = 1;
	con.gridy = 3;
	con.anchor = GridBagConstraints.EAST;
	con.fill = GridBagConstraints.NONE;
	grid.setConstraints(label_3, con);

	reset(con);
	con.gridx = 2;
	con.gridy = 3;
	con.anchor = GridBagConstraints.CENTER;
	con.fill = GridBagConstraints.HORIZONTAL;
	grid.setConstraints(phone, con);

	reset(con);
	con.gridx = 1;
	con.gridy = 6;
	con.gridwidth = 2;
	con.anchor = GridBagConstraints.CENTER;
	con.fill = GridBagConstraints.HORIZONTAL;
	grid.setConstraints(message, con);


	// Resize behavior management and parent heirarchy
	this.getContentPane().setLayout(grid);
	//Set the Background Color
	this.getContentPane().setBackground(new Color(59293/256,60333/256,53052/256));
	frame_1.setLayout(frame_1_grid);
	//Set the Background Color
	frame_1.setBackground(new Color(59293/256,60333/256,53052/256));

	// Give the application a chance to do its initialization
	super.init();
}

public void actionPerformed(ActionEvent event) {
	if (event.getSource() == button_2) {
		getData();
	}
	if (event.getSource() == button_3) {
		db.put(name.getText(),phone.getText());
	}
	if (event.getSource() == button_4) {
		db.write();message.setText("saved");
	}
	if (event.getSource() == button_1) {
		System.exit(0);
	}
}

// code sourced from Demo2.include.java
//  This code is inserted into the SpecJava class
//  directly.  It comes from the <project>.include.java
//  file in the current directory.  It can be editted either
//  with your favorite text editor, or via the "edit code"
//  option of the edit menu.


public static void main(String[] args) {
    JFrame f = new JFrame("Demo2 Test");
    Demo2 win = new Demo2();
    f.addWindowListener(
       new WindowAdapter()
       {
             public void windowClosing(WindowEvent e)
             {
                 System.exit(0);
             }
        }
    );
    win.init();
    f.getContentPane().add("Center", win);
    f.pack();
    f.setVisible(true);
}

private void reset(GridBagConstraints con) {
    con.gridx = GridBagConstraints.RELATIVE;
    con.gridy = GridBagConstraints.RELATIVE;
    con.gridwidth = 1;
    con.gridheight = 1;
 
    con.weightx = 0;
    con.weighty = 0;
    con.anchor = GridBagConstraints.CENTER;
    con.fill = GridBagConstraints.NONE;
 
    con.insets = new Insets(0, 0, 0, 0);
    con.ipadx = 0;
    con.ipady = 0;
}

}
