Files
GTSchoolShit/CS1322/p5/EventHandler.java
2025-06-07 01:59:34 -04:00

138 lines
3.5 KiB
Java

/**
* <PRE>
* EventHandler.java
*
* Revisions: 1.0 Nov. 10, 2002
* Created the EventHandler class
* 1.1 Nov. 10, 2002
* Compiled, Commented, Finished
*
* </PRE>
*
* Collaboration Statement:
* I worked on the homework assignment alone, using only
* course materials.
*
* Created with JCreatorLE, some indents are off when viewed through notepad
* or EMACS
*
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
* @version Version 1.0, Nov. 10, 2002
*/
import java.awt.event.*;
import javax.swing.event.*;
import java.util.*;
import javax.swing.*;
public class EventHandler implements ActionListener{
/**
*Displays user actions to console (y/n)
*/
public static boolean bVerbose;
//similar to bDebug, but doesn't interefere with the program
/**
*Holds the currently selected sort
*/
private AbstractSort sort;
/**
*ChangeListener, notified of changes
*/
private ChangeListener chgListener;
////////////////
//Constructors//
////////////////
/**
*Default Constructor
*@param cl, the Listener it will Handle
*/
public EventHandler(ChangeListener cl){
chgListener = cl;
bVerbose = true;
}
/**
*Constructor that is used for the P5 driver
*sets bVerbose to false
*/
public EventHandler(ChangeListener cl, boolean bVerbose){
chgListener = cl;
this.bVerbose = bVerbose;
}
///////////
//Methods//
///////////
/**
*Handles the events taken from the ChangeListener
*@param ae, the ActionEvent to be analyzed
*/
public void actionPerformed(ActionEvent ae){
if(ae.getSource() instanceof JMenuItem){
if(bVerbose)System.out.print("Creating Array...");
ArrayWrapper aw =
new ArrayWrapper(ArrayWrapper.getRandomIntegerArray(60));
aw.addChangeListener(chgListener);
if(bVerbose)System.out.println("Done.");
String str = ae.getActionCommand();
if(str.equals("Bubble Sort")){
if(bVerbose)System.out.println("User chose Bubble Sort");
BubbleSort bs = new BubbleSort(aw);
sort = bs;
}
else if(str.equals("Insertion Sort")){
if(bVerbose)System.out.println("User chose Insertion Sort");
InsertionSort is = new InsertionSort(aw);
sort = is;
}
else if(str.equals("Merge Sort")){
if(bVerbose)System.out.println("User chose Merge Sort");
MergeSort M$ = new MergeSort(aw);
sort = M$;
}
else{//if(str.equals("Quick Sort"){
if(bVerbose)System.out.println("User chose Quick Sort");
QuickSort qs = new QuickSort(aw);
sort = qs;
}
}//end if(ae.getSource() instanceof JMenuItem)
else if(ae.getSource() instanceof JButton){
if(sort == null){
if(bVerbose)
System.out.println(
"User attempted to start without selecting a sort");
}
else{
if(bVerbose)System.out.println("User selected Begin Sort");
sort.doSort();
}
}//end if(ae.getSource() instanceof JButton
}//end actionPerformed()
/***********************************************************************/
/**
* Debugging main for class EventHandler.
* This method will rigorously test my code.
*
* <br><br>
* @param args a String array of command line arguments.
*/
public static void main(String[] args) {
}// end of main(String[] args)
}// end of class EventHandler