[C++ Projects] [My Resume] [Home Page]

CIS 4850a - Java


CIS 4850 Project Number 3
At this moment only the summit button is working.
The rest of the functionality will be implemented later on.

The items in the Choice boxes will change depending on the item
selected in the Manufacturer Choice box.


ButtonHandler.java.

Send me E-mail: gs03ann@panther.gsu.edu
Revised: 26 March 1999

This is the source Code:


import java.awt.*;
import javax.swing.*;
public class InvView extends java.applet.Applet 
{
	TextField txfldPrice = new TextField(10);
	TextField txfldQty = new TextField(10);
	TextArea msg = new TextArea("Product Description",3,3);
	
	Label lblSelect = new Label("Press Summit", Label.LEFT);
	Label lblManuf = new Label("Manufacturer",Label.LEFT);
	Label lblStyle = new Label("Style",Label.LEFT);
	Label lblColor = new Label("Color",Label.LEFT);
	Label lblPrice = new Label("Price",Label.LEFT);
	Label lblQty = new Label("Qty in Stock",Label.LEFT);
	Label lblDollars = new Label("Dollars",Label.LEFT);
	Label lblYards = new Label("Yards in stock",Label.LEFT);
	Choice menuBrand = new Choice();
	Choice menuStyle = new Choice();	
	public void init()
	{
		setBackground(Color.white);
		GridBagLayout gb = new GridBagLayout();
		GridBagConstraints gbc = new GridBagConstraints();
		setLayout(gb);
		
		
		
		Font selbl = new Font("Helvetica",Font.BOLD,14);
		
		
		
		menuBrand.add("Waverly");
		menuBrand.add("Western");
		menuBrand.add("Kaufman");
		menuBrand.add("Richloom");
		
		
		menuStyle.add("wa12343");
		menuStyle.add("wa33422");
		menuStyle.add("wa39433");
		menuStyle.add("wa34321");
		
		Choice menuColor = new Choice();
		menuColor.add("Red");
		menuColor.add("Black");
		menuColor.add("Blue");
		menuColor.add("Yellow");
	    
		Checkbox cbxView = new Checkbox("View Description");
		
		
		
		//Select label  Row 1
		
		buildConstraints(gbc,0,0,1,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(lblSelect,gbc);
		add(lblSelect);
								
		//Row 2	
		
		buildConstraints(gbc,0,1,1,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(lblManuf,gbc);
		add(lblManuf);
				
		buildConstraints(gbc,0,2,2,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(menuBrand,gbc);
		add(menuBrand);
				
		//Row 3
		buildConstraints(gbc,1,1,1,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(lblStyle,gbc);
		add(lblStyle);
				
		buildConstraints(gbc,1,2,2,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(menuStyle,gbc);
		add(menuStyle);
				
		//Row 4
		buildConstraints(gbc,2,1,1,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(lblColor,gbc);
		add(lblColor);
		
		buildConstraints(gbc,2,2,2,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(menuColor,gbc);
		add(menuColor);
						
		//Row 5
				
		buildConstraints(gbc,0,4,1,1,0,0);
		gbc.fill  = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cbxView,gbc);
		add(cbxView);
		
		
		buildConstraints(gbc,1,4,1,1,100,100);
		Button btnSummit = new Button("Summit");
		gbc.fill  = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(btnSummit,gbc);
		
		buttonHandler bhandle2 = new buttonHandler(this,menuBrand,menuStyle,menuColor);
		btnSummit.addActionListener(bhandle2);
		add(btnSummit);
		
		buildConstraints(gbc,2,4,1,1,100,100);
		Button btnAdd = new Button("Buy Item");
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(btnAdd,gbc);
		
		buttonHandler bhandle1 = new buttonHandler(this,menuBrand,menuStyle,menuColor);
		btnAdd.addActionListener(bhandle1);
		add(btnAdd);
		
		//Row 6
		
		
		//Row 7
		
						
		//Row 8
		buildConstraints(gbc,0,5,1,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(lblPrice,gbc);
		add(lblPrice);
		
		buildConstraints(gbc,1,5,1,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(txfldPrice,gbc);
		add(txfldPrice);
		
		//Row 9
		buildConstraints(gbc,0,6,1,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(lblYards,gbc);
		add(lblYards);
		
		buildConstraints(gbc,1,6,1,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(txfldQty,gbc);
		add(txfldQty);
		
		Font txt = new Font("Helvetica",Font.PLAIN,12);
		
		gbc.fill = GridBagConstraints.BOTH;
		buildConstraints(gbc,0,7,3,3,0,0);
		gb.setConstraints(msg,gbc);
		add(msg);
		
		setFont(selbl);
		
		
	}	
	public void setTextField(String p, String y)
	{
		txfldPrice.setText(p);
		txfldQty.setText(y);
		
	}
	public void setMsg(String m)
	{
		msg.setText(m);
	}
	
	
	public Insets insets()
		{
			return new Insets(10,30,10,30);
		}	
	//Helper class for setting grid constraints
	void buildConstraints(GridBagConstraints gbc, int x, int y, int w,
										int h, int wx, int wy)
	{
		gbc.gridx = x;
		gbc.gridy = y;
		gbc.gridwidth = w;
		gbc.gridheight = h;
		gbc.weightx = wx;
		gbc.weighty = wy;
	}
	
		
	}	import java.awt.*;
import javax.swing.*;
public class InvView extends java.applet.Applet 
{
	TextField txfldPrice = new TextField(10);
	TextField txfldQty = new TextField(10);
	TextArea msg = new TextArea("Product Description",3,3);
	
	Label lblSelect = new Label("Press Summit", Label.LEFT);
	Label lblManuf = new Label("Manufacturer",Label.LEFT);
	Label lblStyle = new Label("Style",Label.LEFT);
	Label lblColor = new Label("Color",Label.LEFT);
	Label lblPrice = new Label("Price",Label.LEFT);
	Label lblQty = new Label("Qty in Stock",Label.LEFT);
	Label lblDollars = new Label("Dollars",Label.LEFT);
	Label lblYards = new Label("Yards in stock",Label.LEFT);
	Choice menuBrand = new Choice();
	Choice menuStyle = new Choice();	
	public void init()
	{
		setBackground(Color.white);
		GridBagLayout gb = new GridBagLayout();
		GridBagConstraints gbc = new GridBagConstraints();
		setLayout(gb);
		
		
		
		Font selbl = new Font("Helvetica",Font.BOLD,14);
		
		
		
		menuBrand.add("Waverly");
		menuBrand.add("Western");
		menuBrand.add("Kaufman");
		menuBrand.add("Richloom");
		
		
		menuStyle.add("wa12343");
		menuStyle.add("wa33422");
		menuStyle.add("wa39433");
		menuStyle.add("wa34321");
		
		Choice menuColor = new Choice();
		menuColor.add("Red");
		menuColor.add("Black");
		menuColor.add("Blue");
		menuColor.add("Yellow");
	    
		Checkbox cbxView = new Checkbox("View Description");
		
		
		
		//Select label  Row 1
		
		buildConstraints(gbc,0,0,1,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(lblSelect,gbc);
		add(lblSelect);
								
		//Row 2	
		
		buildConstraints(gbc,0,1,1,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(lblManuf,gbc);
		add(lblManuf);
				
		buildConstraints(gbc,0,2,2,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(menuBrand,gbc);
		add(menuBrand);
				
		//Row 3
		buildConstraints(gbc,1,1,1,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(lblStyle,gbc);
		add(lblStyle);
				
		buildConstraints(gbc,1,2,2,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(menuStyle,gbc);
		add(menuStyle);
				
		//Row 4
		buildConstraints(gbc,2,1,1,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(lblColor,gbc);
		add(lblColor);
		
		buildConstraints(gbc,2,2,2,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(menuColor,gbc);
		add(menuColor);
						
		//Row 5
				
		buildConstraints(gbc,0,4,1,1,0,0);
		gbc.fill  = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cbxView,gbc);
		add(cbxView);
		
		
		buildConstraints(gbc,1,4,1,1,100,100);
		Button btnSummit = new Button("Summit");
		gbc.fill  = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(btnSummit,gbc);
		
		buttonHandler bhandle2 = new buttonHandler(this,menuBrand,menuStyle,menuColor);
		btnSummit.addActionListener(bhandle2);
		add(btnSummit);
		
		buildConstraints(gbc,2,4,1,1,100,100);
		Button btnAdd = new Button("Buy Item");
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(btnAdd,gbc);
		
		buttonHandler bhandle1 = new buttonHandler(this,menuBrand,menuStyle,menuColor);
		btnAdd.addActionListener(bhandle1);
		add(btnAdd);
		
		//Row 6
		
		
		//Row 7
		
						
		//Row 8
		buildConstraints(gbc,0,5,1,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(lblPrice,gbc);
		add(lblPrice);
		
		buildConstraints(gbc,1,5,1,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(txfldPrice,gbc);
		add(txfldPrice);
		
		//Row 9
		buildConstraints(gbc,0,6,1,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(lblYards,gbc);
		add(lblYards);
		
		buildConstraints(gbc,1,6,1,1,100,100);
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(txfldQty,gbc);
		add(txfldQty);
		
		Font txt = new Font("Helvetica",Font.PLAIN,12);
		
		gbc.fill = GridBagConstraints.BOTH;
		buildConstraints(gbc,0,7,3,3,0,0);
		gb.setConstraints(msg,gbc);
		add(msg);
		
		setFont(selbl);
		
		
	}	
	public void setTextField(String p, String y)
	{
		txfldPrice.setText(p);
		txfldQty.setText(y);
		
	}
	public void setMsg(String m)
	{
		msg.setText(m);
	}
	
	
	public Insets insets()
		{
			return new Insets(10,30,10,30);
		}	
	//Helper class for setting grid constraints
	void buildConstraints(GridBagConstraints gbc, int x, int y, int w,
										int h, int wx, int wy)
	{
		gbc.gridx = x;
		gbc.gridy = y;
		gbc.gridwidth = w;
		gbc.gridheight = h;
		gbc.weightx = wx;
		gbc.weighty = wy;
	}
	
		
	}	  
1