first commit
This commit is contained in:
169
CS1322/p5/SortFrame.java
Normal file
169
CS1322/p5/SortFrame.java
Normal file
@@ -0,0 +1,169 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* SortFrame.java
|
||||
*
|
||||
* Revisions: 1.0 Nov. 09, 2002
|
||||
* Created the SortFrame class
|
||||
* 1.1 Nov. 10, 2002
|
||||
* Compiled, Finished, Done
|
||||
* 1.2 Nov. 10, 2002
|
||||
* Added Final Phase methods and variables
|
||||
*
|
||||
* </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.2, Nov. 10, 2002
|
||||
*/
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class SortFrame extends JFrame implements ChangeListener{
|
||||
|
||||
/**
|
||||
*Displays the Array
|
||||
*/
|
||||
private SortBarPanel barPanel;
|
||||
|
||||
/**
|
||||
*Initiate the sort of the random array
|
||||
*/
|
||||
private JButton startButton;
|
||||
|
||||
/**
|
||||
*Drop down menu for the frame
|
||||
*/
|
||||
private JMenuBar menuBar;
|
||||
|
||||
/**
|
||||
*Menu for menubar
|
||||
*/
|
||||
private JMenu sortMenu;
|
||||
|
||||
/**
|
||||
*Sorting type buttons
|
||||
*/
|
||||
private JMenuItem bubbleItem;
|
||||
private JMenuItem quickItem;
|
||||
private JMenuItem insertionItem;
|
||||
private JMenuItem mergeItem;
|
||||
|
||||
/**
|
||||
*A curious variable who wants to know what the heck just happened
|
||||
*/
|
||||
private EventHandler eh;
|
||||
|
||||
////////////////
|
||||
//Constructors//
|
||||
////////////////
|
||||
|
||||
/**
|
||||
*Default Constructor for SortFrame()
|
||||
*Initializes window
|
||||
*/
|
||||
public SortFrame(){
|
||||
super("Sort Demo");
|
||||
eh = new EventHandler(this);
|
||||
this.initWindow(true);
|
||||
}
|
||||
|
||||
/**
|
||||
*Used in P5 driver
|
||||
*/
|
||||
public SortFrame(boolean bVerbose){
|
||||
super("Sort Demo");
|
||||
eh = new EventHandler(this,bVerbose);
|
||||
this.initWindow(false);
|
||||
}
|
||||
|
||||
/**
|
||||
*Initialize function for the window
|
||||
*@param bPretty, something I didn't have time to fully implement
|
||||
*/
|
||||
private void initWindow(boolean bPretty){
|
||||
|
||||
//init Layout
|
||||
BorderLayout BL = new BorderLayout();
|
||||
this.getContentPane().setLayout(BL);
|
||||
|
||||
//init Sort Items
|
||||
bubbleItem = new JMenuItem("Bubble Sort");
|
||||
quickItem = new JMenuItem("Quick Sort");
|
||||
insertionItem = new JMenuItem("Insertion Sort");
|
||||
mergeItem = new JMenuItem("Merge Sort");
|
||||
|
||||
//add the actionListeners
|
||||
bubbleItem.addActionListener(eh);
|
||||
quickItem.addActionListener(eh);
|
||||
mergeItem.addActionListener(eh);
|
||||
insertionItem.addActionListener(eh);
|
||||
|
||||
//init menues
|
||||
sortMenu = new JMenu("Sorts");
|
||||
sortMenu.add(bubbleItem);
|
||||
sortMenu.add(insertionItem);
|
||||
sortMenu.add(mergeItem);
|
||||
sortMenu.add(quickItem);
|
||||
|
||||
menuBar = new JMenuBar();
|
||||
menuBar.add(sortMenu);
|
||||
|
||||
//BL.addLayoutComponent(menuBar,"NORTH");
|
||||
this.setJMenuBar(menuBar);
|
||||
|
||||
barPanel = new SortBarPanel();
|
||||
this.getContentPane().add(barPanel,BL.CENTER);
|
||||
|
||||
//init button
|
||||
startButton = new JButton("Start");
|
||||
startButton.addActionListener(eh);
|
||||
this.getContentPane().add(startButton,BL.SOUTH);
|
||||
|
||||
//init window properties
|
||||
setSize(600,500);
|
||||
setResizable(false);
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
|
||||
//Display the Window
|
||||
this.show();
|
||||
|
||||
}//end initWindow()
|
||||
|
||||
|
||||
///////////
|
||||
//Methods//
|
||||
///////////
|
||||
|
||||
/**
|
||||
*Update the barPanel
|
||||
*/
|
||||
public void stateChanged(ChangeEvent ce){
|
||||
if(ce.getSource() instanceof ArrayWrapper){
|
||||
ArrayWrapper awTemp = (ArrayWrapper)ce.getSource();
|
||||
barPanel.display(awTemp.toIntArray());
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************/
|
||||
|
||||
/**
|
||||
* Debugging main for class SortFrame.
|
||||
* This method will rigorously test my code.
|
||||
*
|
||||
* <br><br>
|
||||
* @param args a String array of command line arguments.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
SortFrame f = new SortFrame();
|
||||
|
||||
}// end of main(String[] args)
|
||||
|
||||
}// end of class SortFrame
|
||||
Reference in New Issue
Block a user