<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">import java.awt.*;

/*
PQTest - An applet/application for testing PriorityQueue.
*/
public class PQTest extends java.applet.Applet {
	
	private PQString pq = new PQString();	// Our PriorityQueue.
	private Label display;				// Displays PriorityQueue.
	private boolean isApplication = false;	// True iff running as application.
	
	//applet initialization
	public void init() {
		setBackground(Color.green);		//Background color.
		setLayout(new BorderLayout());	//Placement scheme.

		// Panel for inserting.
		Panel ip = new Panel();
		ip.setBackground(Color.gray);
		ip.add(new Button("jan")); 
		ip.add(new Button("feb")); 
		ip.add(new Button("mar")); 
		ip.add(new Button("apr")); 
		ip.add(new Button("may")); 
		ip.add(new Button("jun")); 
		ip.add(new Button("jul"));
		ip.add(new Button("aug"));
		ip.add(new Button("sep"));
		ip.add(new Button("oct"));
		ip.add(new Button("nov"));
		ip.add(new Button("dec"));
		add("North",ip);
	
		// Panel for deleting.
		Panel dp = new Panel();
		dp.setBackground(Color.gray);
		dp.add(new Button("Get"));
		dp.add(new Button("Clear"));
		add("South",dp);

		// Display area.
		display = new Label(pq.toString(),Label.CENTER);
		add("Center",display);
	}

	/*
      The main() method acts as the applet's entry point when it is run
	as a standalone application. It is ignored if the applet is run from
	within an HTML page.
	*/
	public static void main(String args[])
	{
		Frame frame = new Frame();		//create a window
		frame.resize(600,200);			//choose a size
		frame.setTitle("Queue Window");	//give it a title
		PQTest applet = new PQTest();		//create the applet
		applet.isApplication = true;		//indicate application
		frame.add("Center",applet);		//put the applet in the window
		applet.init();				//standard applet initializaion
		applet.start();				//standard applet start
		frame.show();				//make it visible
	}


	//standard method for reporting information about an applet.
	public String getAppletInfo() {
		return "Name: QTest\r\n" +
		       "Author: Nick Danger\r\n" +
		       "Created with Microsoft Visual J++ Version 6.0";
	}


	/*
	Standard method for handling control events.  This is where
	we can set things up to handle events generated by buttons
	or other standard controls.
	e = the Event
	arg = the Event's argument; for a Button this is the Button's name
	return true iff the Event has been handled
	*/
	public boolean action(Event e,Object arg) {

		//if it's not a button, forget about it
		if (!(e.target instanceof Button)) return false;
		if (arg.equals("Clear")) pq.clear();
		else if (arg.equals("Get")) {
		    if (!pq.isEmpty()) pq.get();
		}
		//put the button's String into the priority queue
		else pq.insert(arg);
		
		//display the queue's contents
		String contents = pq.toString();
		display.setText(contents);
		if (isApplication) System.out.println(contents);
		return true;	//indicates event has been handled
	}
}

/*
This class represents a PriorityQueue that is ordered by alphabetic
order among Strings.  The before method is overrridden so that
it gives the proper ordering.
*/
class PQString extends PriorityQueue {

     //return true iff a is before b
	public boolean before(Object a,Object b) {
		String stringA = (String)a;
		String stringB = (String)b;
		return stringA.compareTo(stringB) &lt; 0;
	}
}
</pre></body></html>