FileDocCategorySizeDatePackage
HelpDesk.javaAPI DocExample2189Wed Oct 17 18:38:18 BST 2001None

HelpDesk.java

// Week 16 exercise
// prototype incomplete version
// J Harvey, Oct 2001

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.util.*;


public class HelpDesk extends Applet implements ActionListener 
{
	Button b1,b2,b3,b4;
	String work;
	TextField intext, outext;
	TextArea space;
	Vector v1;
	public void init() 
	{
	b1 = new Button ("Enter Job");
	b2 = new Button ("Completed Job");
	b3 = new Button("List Jobs");
	b4 = new Button("Clear All Jobs");
	intext = new TextField(10);
	outext = new TextField(10);
	space = new TextArea(10,40);
	v1 = new Vector ();
	b1.addActionListener(this);
	b2.addActionListener(this);
	b3.addActionListener(this);
	b4.addActionListener(this);
	intext.addActionListener(this);
	
	add(b1); add (intext); add(b2);  add (outext); add(b3); add (b4);
	add(space);
	}  // end init

	public void paint(Graphics g) 
	{
		 
	}

public void actionPerformed(ActionEvent ae)
{
	if (ae.getSource()==b1)
		{
		work = (String)intext.getText();
		intext.setText("");
		addToVector();
		}
	if (ae.getSource()==b2)
		{
		work = (String)outext.getText();
		 if (findString())
		 	outext.setText("Job removed");
		 else 
		 	outext.setText("Job not found");
		
		}
	if (ae.getSource()==b3)
		listJobs();
	if (ae.getSource()==b4)
		{
		v1.clear();
		//space.setText("");
		}
}

public void addToVector()
{
	v1.addElement(work);
}

public void getFromVector()
{
	if (!(v1.isEmpty()))
		{
			work=(String) v1.firstElement();
			v1.remove(0);
		}
	else
		work="No Jobs";
}		

public boolean findString()
{
boolean b=false;
if (!(v1.isEmpty()))

	{ 
		for (int i=0; i<v1.size(); i++)
			{
				if (work.equals((String)v1.elementAt(i)))
				{
					b = true;
					v1.remove(i);
				} // endif
			} // end for
	} //endif
	return b;
} // end findString
public void listJobs()
{
	space.setText(" ");
	 
	if (v1.size()>0)
		{
		for (int i=0; i<v1.size(); i++)
		
			{
		 	work=(String) v1.elementAt(i);
		 	space.append(work + "\n");
			}
		}
	else 
		{
		space.append("No Jobs in List");
		}

} // end listJobs


} // end class HelpDesk