//************************************
//
// CSC112b Spring 1999
// Ileana Streinu
//
//	Arithmetic expression evaluation
//	Uses fully parenthesized expressions as input
//	Simulates the stack usage step by step
//
//************************************

import java.applet.*;	// used for applets 
import java.awt.*;	// if you use any kind of graphics
import java.io.*;	// if you use any kind of I/O

//*************************
//
//	myApplet
//
//************************

public class myApplet extends Applet
{

myStack stack;	// the stack
int count;	// to generate integers to push on the stack

// graphical interface

Button bnew;		// button for starting over
Button bpush;		// push
Button bpop;		// pop


//************
//
//  init
//
//
//************

public void init() 
{

setBackground(Color.white);

stack = new myStack();

count = 10;


bnew = new Button("New");
add(bnew);
bpush = new Button("Push");
add(bpush);
bpop	 = new Button("Pop");
add(bpop);

}// end init


//*****************************
//
//     action
//
//
//*****************************


public boolean action(Event e, Object o)
{


if (e.target == bnew)
{
stack = new myStack();
count = 10;
}// end bnew

else if (e.target == bpush)
{
stack.push(new myObject(count));
count = count + 5;

}// end bpush

else if (e.target == bpop)
{
if (!stack.IsEmpty()) stack.pop();
}// end bpop

repaint();
return true;
}



//******************************************
//
//    paint
//
//
//*******************************************

public void paint(Graphics g)
{
int i;

g.setColor(Color.red);

stack.Print(); // print on Java console for verification

stack.DrawRect(g);

}//end of method paint


}// end myApplet

