-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUI.java
80 lines (69 loc) · 2.58 KB
/
GUI.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* -------------------------------------------------------
Jun Simons
June 2021
GUI.java
SortingAlgorithimVisualizer
------------------------------------------------------- */
package com.company;
import javax.swing.*;
import java.util.Scanner;
public class GUI {
private static DrawSort util;
private JFrame window;
public static final int WIDTH = 1400;
public static final int HEIGHT = 800;
static Scanner input = new Scanner(System.in);
//Constructor
public GUI() { //initialize JFrame GUI
window = new JFrame("JUN-SORT");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
util = new DrawSort(); //All graphics happen in DrawSort
window.add(util);
util.repaint();
window.pack();
window.setVisible(true);
}
public static void main(String... args) {
GUI gui = new GUI(); //initiate everything
//main input loop
while(true) {
System.out.println("Which sorting algorithm would you like to see");
System.out.println("1: Selection Sort\n2: Quick Sort\n3: Bubble Sort\n4: Insertion Sort\n5: Merge Sort\n-1 to exit program");
switch(input.nextInt()) { //get input and call correct method
case 1 -> {
System.out.println("You chose Selection Sort");
util.selectionSort();
}
case 2 -> {
System.out.println("You chose Quick Sort");
util.quickSort();
}
case 3 ->{
System.out.println("You chose Bubble Sort");
util.bubbleSort();
}
case 4 -> {
System.out.println("You chose Insertion Sort");
util.insertionSort();
}
case 5 -> {
System.out.println("You chose Merge Sort");
util.mergeSort();
}
case -1 -> {
System.out.println("Exiting program...");
System.exit(0);
}
default -> {
System.out.println("Invalid response, please try again");
}
}
System.out.println("The array is now sorted");
System.out.println("Enter any key to shuffle the array and continue: ");
input.next();
//shuffle and repaint with cool shuffling graphics :)
if (input.hasNextLine()) util.visualizeShuffle();
util.repaint();
}
}
}