// SpecTcl generated class CupDemo, version 1.2

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

public class CupDemo extends JApplet 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 JLabel label_2;
private JRadioButton radiobutton_1;
private ButtonGroup type = new ButtonGroup();
private Cup canvas_1;
private JRadioButton radiobutton_2;
private JRadioButton radiobutton_3;
private JRadioButton radiobutton_4;
private JButton button_2;

//methods to support form introspection
private static String names[] = {
	"label_2","type","radiobutton_1","canvas_1","radiobutton_2","radiobutton_3","radiobutton_4","button_2",
};
public String[] getNames() {
	return names;
}

//There should be an easier way to do this
public Object[] getWidgets() {
	Object[] list = new Object[8];
	list[0] = label_2;
	list[1] = type;
	list[2] = radiobutton_1;
	list[3] = canvas_1;
	list[4] = radiobutton_2;
	list[5] = radiobutton_3;
	list[6] = radiobutton_4;
	list[7] = button_2;
	return list;
}

public void init() {

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

	label_2 = new JLabel();
	label_2.setText("Choose your beverage");
	this.getContentPane().add(label_2);

	radiobutton_1 = new JRadioButton();
	type.add(radiobutton_1);
	radiobutton_1.setText("water");
	this.getContentPane().add(radiobutton_1);

	canvas_1 = new Cup();
	canvas_1.init(this);	// Cup initialization
	canvas_1.setBackground(new Color(48830/256,48830/256,48830/256));
	this.getContentPane().add(canvas_1);

	radiobutton_2 = new JRadioButton();
	type.add(radiobutton_2);
	radiobutton_2.setText("milk");
	this.getContentPane().add(radiobutton_2);

	radiobutton_3 = new JRadioButton();
	type.add(radiobutton_3);
	radiobutton_3.setText("tea");
	this.getContentPane().add(radiobutton_3);

	radiobutton_4 = new JRadioButton();
	type.add(radiobutton_4);
	radiobutton_4.setText("other");
	this.getContentPane().add(radiobutton_4);

	button_2 = new JButton();
	button_2.addActionListener(this);
	button_2.setText("OK");
	this.getContentPane().add(button_2);

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

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

	reset(con);
	con.gridx = 2;
	con.gridy = 2;
	con.gridheight = 4;
	con.anchor = GridBagConstraints.CENTER;
	con.fill = GridBagConstraints.BOTH;
	grid.setConstraints(canvas_1, con);

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

	reset(con);
	con.gridx = 1;
	con.gridy = 4;
	con.anchor = GridBagConstraints.WEST;
	con.fill = GridBagConstraints.NONE;
	grid.setConstraints(radiobutton_3, con);

	reset(con);
	con.gridx = 1;
	con.gridy = 5;
	con.anchor = GridBagConstraints.WEST;
	con.fill = GridBagConstraints.NONE;
	grid.setConstraints(radiobutton_4, con);

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


	// Resize behavior management and parent heirarchy
	this.getContentPane().setLayout(grid);
	//Set the Background Color
	this.getContentPane().setBackground(new Color(59293/256,60333/256,59293/256));
	radiobutton_1.addItemListener(
		new ItemListener() {
			public void itemStateChanged( ItemEvent e )
			{
				if (e.getStateChange() == ItemEvent.SELECTED )
				{
				}
			}
		}
	);
	radiobutton_2.addItemListener(
		new ItemListener() {
			public void itemStateChanged( ItemEvent e )
			{
				if (e.getStateChange() == ItemEvent.SELECTED )
				{
				}
			}
		}
	);
	radiobutton_3.addItemListener(
		new ItemListener() {
			public void itemStateChanged( ItemEvent e )
			{
				if (e.getStateChange() == ItemEvent.SELECTED )
				{
				}
			}
		}
	);
	radiobutton_4.addItemListener(
		new ItemListener() {
			public void itemStateChanged( ItemEvent e )
			{
				if (e.getStateChange() == ItemEvent.SELECTED )
				{
				}
			}
		}
	);

	// Give the application a chance to do its initialization
	
}

public void actionPerformed(ActionEvent event) {
	if (event.getSource() == button_2) {
		System.exit(1);
	}
}

public static void main(String[] args) {
    JFrame f = new JFrame("CupDemo Test");
    CupDemo win = new CupDemo();
    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;
}

}
