Objective: GUI Layout manager
Download one of the sample GUI layout
program.
Use any GUI layout to add buttons to start each sort and
display the System.nanoTime in common TextArea panel.
The question is a bit confusing so i will try to simplify it.
Using the GUI ( I made a unclick able one so you have to make it
clickable), allow a user to sort the text file based on what they
click on. example: if i click merge sort, the text file will be
merged sorted and its time will be presented.
The code I provided needs to be updated (needs):
ability to click the button to choose the sort option
to sort the text file after clicked:
ÊÊÊÊÊÊÊÊÊÊÊÊ
merge uses merge sort
ÊÊÊÊÊÊÊÊÊÊÊÊ
selection uses selection sort
ÊÊÊÊÊÊÊÊÊÊÊÊ
insertion uses insertion sort
ÊÊÊÊÊÊÊÊÊÊÊÊ
quick uses quick sort
all the sorts are provided, so you just need to call the
specific sort after the button clicked.(also slection sort uses
linked list while the rest can use arrays)
The code i provided only creates the buttons but does nothing
else.
Hopefully that helps explain a bit more of what i need.
This is the GUI I created( need to add the ability to
click):
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
public class BorderSort
{
//—————————————————————–
// Creates several bordered panels and displays them.
//—————————————————————–
public static void main (String[] args)
{
JFrame frame = new JFrame (“Border Demo”);
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setLayout (new GridLayout (0, 2, 5, 10));
panel.setBorder (BorderFactory.createEmptyBorder (8, 8, 8, 8));
JPanel p1 = new JPanel();
p1.setBorder (BorderFactory.createLineBorder (Color.red, 3));
p1.add (new JLabel (“Quick Sort”));
panel.add (p1);
JPanel p2 = new JPanel();
p2.setBorder (BorderFactory.createLineBorder (Color.red, 3));
p2.add (new JLabel (“Insertion Sort”));
panel.add (p2);
JPanel p3 = new JPanel();
p3.setBorder (BorderFactory.createLineBorder (Color.red, 3));
p3.add (new JLabel (“Merge Sort”));
panel.add (p3);
JPanel p4 = new JPanel();
p4.setBorder (BorderFactory.createLineBorder (Color.red, 3));
p4.add (new JLabel (“Selection Sort”));
panel.add (p4);
frame.getContentPane().add (panel);
frame.pack();
frame.setVisible(true);
}
}
Given Code:
//********************************************************************
// SelectionSortS.java ÊÊ
//
//********************************************************************
import java.util.Comparator;
public class SelectionSortS
{
private SortNode list;
ÊÊ
//—————————————————————–
// Creates an initially empty linked list.
//—————————————————————–
public SelectionSortS()
{
list = null;
}
//—————————————————————–
// Adds an integer to the linked list
//—————————————————————–
public void add(String value)
{
SortNode node = new SortNode(value);
SortNode current = null;
if (list == null)
list = node;
else
{
current = list;
while (current.next != null)
current = current.next;
current.next = node;
}
}
ÊÊ
//—————————————————————–
// Sorts the linked list using the selection sort.
//—————————————————————–
public void sort()
{
SortNode current = list;
SortNode min = list;
SortNode swapPos = list;
ÊÊ
ÊÊ
if (list == null)
return;
while (swapPos.next != null)
{
while (current.next != null) // find min value
{
current = current.next;
if (current.value.compareTo(min.value) <0) min = current; } // Swap the values if (min != swapPos) // a swap was found { String temp = min.value; min.value = swapPos.value; swapPos.value = temp; } swapPos = swapPos.next; current = swapPos; min = current; } } ÊÊ //----------------------------------------------------------------- // Returns a listing of the contents of the linked list. //----------------------------------------------------------------- public String toString() { String report = ""; SortNode current = list; ÊÊ if (current != null) { report += String.valueOf(current.value) + " "; while (current.next != null) { current = current.next; report += String.valueOf(current.value) + " "; } } return report; } ÊÊ //***************************************************************** // An inner class that represents a node containing String. // The public variables are only visible in the outer class. //***************************************************************** private class SortNode { public String value; public SortNode next; //-------------------------------------------------------------- // Sets up the node. //-------------------------------------------------------------- public SortNode (String current) { value = current; next = null; } } } /** Source code example for "A Practical Introduction to Data Structures and Algorithm Analysis, 3rd Edition (Java)" by Clifford A. Shaffer Copyright 2008-2011 by Clifford A. Shaffer */ // Sorting main function for testing correctness of sort algorithm. // To use: [+/-] // + means increasing values, - means decreasing value and no // parameter means random values; // where controls the number of objects to be sorted; // and controls the threshold parameter for certain sorts, e.g., // cutoff point for quicksort sublists. import java.io.*; public class QuickSort { static int THRESHOLD = 0; static int ARRAYSIZE = 0; static > void Sort(E[] A) {
qsort(A, 0, A.length-1);
}
static int MAXSTACKSIZE = 1000;
static >
void qsort(E[] A, int i, int j) { // Quicksort
int pivotindex = findpivot(A, i, j); // Pick a pivot
DSutil.swap(A, pivotindex, j); // Stick pivot at end
// k will be the first position in the right subarray
int k = partition(A, i-1, j, A[j]);
DSutil.swap(A, k, j); // Put pivot in place
if ((k-i) > 1) qsort(A, i, k-1); // Sort left partition
if ((j-k) > 1) qsort(A, k+1, j); // Sort right partition
}
static >
int partition(E[] A, int l, int r, E pivot) {
do { // Move bounds inward until they meet
while (A[++l].compareTo(pivot)<0); while ((r!=0) && (A[--r].compareTo(pivot)>0));
DSutil.swap(A, l, r); // Swap out-of-place values
} while (l < r); // Stop when they cross DSutil.swap(A, l, r); // Reverse last, wasted swap return l; // Return first position in right partition } static >
int findpivot(E[] A, int i, int j)
{ return (i+j)/2; }
}
/** Source code example for “A Practical Introduction to
Data
Structures and Algorithm Analysis, 3rd Edition (Java)”
by Clifford A. Shaffer
Copyright 2008-2011 by Clifford A. Shaffer
*/
// Sorting main function for testing correctness of sort
algorithm.
// To use: [+/-]
// + means increasing values, – means decreasing value and no
// parameter means random values;
// where controls the number of objects to be sorted;
// and controls the threshold parameter for certain sorts,
e.g.,
// cutoff point for quicksort sublists.
import java.io.*;
public class MergeSort {
static int THRESHOLD = 0;
static int ARRAYSIZE = 0;
@SuppressWarnings(“unchecked”) // Generic array allocation
static > void Sort(E[] A) {
E[] temp = (E[])new Comparable[A.length];
mergesort(A, temp, 0, A.length-1);
}
static >
void mergesort(E[] A, E[] temp, int l, int r) {
int mid = (l+r)/2; // Select midpoint
if (l == r) return; // List has one element
mergesort(A, temp, l, mid); // Mergesort first half
mergesort(A, temp, mid+1, r); // Mergesort second half
for (int i=l; i<=r; i++) // Copy subarray to temp temp[i] = A[i]; // Do the merge operation back to A int i1 = l; int i2 = mid + 1; for (int curr=l; curr<=r; curr++) { if (i1 == mid+1) // Left sublist exhausted A[curr] = temp[i2++]; else if (i2 > r) // Right sublist exhausted
A[curr] = temp[i1++];
else if (temp[i1].compareTo(temp[i2])<0) // Get smaller A[curr] = temp[i1++]; else A[curr] = temp[i2++]; } } } /** Source code example for "A Practical Introduction to Data Structures and Algorithm Analysis, 3rd Edition (Java)" by Clifford A. Shaffer Copyright 2008-2011 by Clifford A. Shaffer */ // Sorting main function for testing correctness of sort algorithm. // To use: [+/-] // + means increasing values, - means decreasing value and no // parameter means random values; // where controls the number of objects to be sorted; // and controls the threshold parameter for certain sorts, e.g., // cutoff point for quicksort sublists. import java.io.*; public class InsertionSort { static int THRESHOLD = 0; static int ARRAYSIZE = 0; static >
void Sort(E[] A, int l) {
for (int i=1; i
(a[j].compareto(a[j-1])<0);="" j--)DSutil.swap(A, j, j-1);
}
}
/** Source code example for "A Practical Introduction to
Data
Structures and Algorithm Analysis, 3rd Edition (Java)"
by Clifford A. Shaffer
Copyright 2008-2011 by Clifford A. Shaffer
*/
import java.util.*;
import java.math.*;
/** A bunch of utility functions. */
class DSutil {
/** Swap two Objects in an array
@param A The array
@param p1 Index of one Object in A
@param p2 Index of another Object A
*/
public static void swap(E[] A, int p1, int p2) {
E temp = A[p1];
ÊÊ A[p1] = A[p2];
ÊÊ A[p2] = temp;
}
/** Randomly permute the Objects in an array.
@param A The array
*/
// int version
// Randomly permute the values of array "A"
static void permute(int[] A) {
for (int i = A.length; i > 0; i–) // for each i
swap(A, i-1, DSutil.random(i)); // swap A[i-1] with
} // a random element
public static void swap(int[] A, int p1, int p2) {
int temp = A[p1];
ÊÊ A[p1] = A[p2];
ÊÊ A[p2] = temp;
}
/** Randomly permute the values in array A */
static void permute(E[] A) {
for (int i = A.length; i > 0; i–) // for each i
swap(A, i-1, DSutil.random(i)); // swap A[i-1] with
} // a random element
/** Initialize the random variable */
static private Random value = new Random(); // Hold the Random
class object
/** Create a random number function from the standard Java
Random
class. Turn it into a uniformly distributed value within the
range 0 to n-1 by taking the value mod n.
@param n The upper bound for the range.
@return A value in the range 0 to n-1.
*/
static int random(int n) {
ÊÊ return Math.abs(value.nextInt()) % n;
}
}
Text File (part):
HO09C1068A,HONDA,FIT,Front bumper license plate,2015,7.00
HO11F1213B,HONDA,ODYSSEY,RT Front bumper molding,2014,7.00
KI17B1042A,KIA,FORTE SDN,LT Front bumper cover
retainer,2015,7.00
KI17B1043A,KIA,FORTE KOUP,RT Front bumper cover
retainer,2015,7.00
SU04D1042D,SUBARU,FORESTER,LT Rear bumper cover
retainer,2015,7.00
SU04D1043D,SUBARU,FORESTER,RT Rear bumper cover
retainer,2015,7.00
HO11F1213A,HONDA,ODYSSEY,RT Front bumper molding,2014,8.00
HO11F2598A,HONDA,ODYSSEY,LT Front fog lamp cover,2014,9.00
HO11F2599A,HONDA,ODYSSEY,RT Front fog lamp cover,2014,9.00
HY03G2599A,HYUNDAI,ELANTRA SEDAN,RT Front fog lamp
cover,2013,9.00
HY03G2598A,HYUNDAI,ELANTRA SEDAN,LT Front fog lamp
cover,2013,9.00
SU04D1042C,SUBARU,FORESTER,LT Rear bumper cover
retainer,2015,9.00
SU04D1043C,SUBARU,FORESTER,RT Rear bumper cover
retainer,2015,9.00
VW11E2513B,VOLKSWAGEN,GOLF,RT Fog Lamp Ring Bezel,2014,9.00
DG06C1042A,DODGE,AVENGER,LT Front bumper cover
support,2010,10.00
SZ10C2599A,SUZUKI,GRAND VITARA,RT Front fog lamp
cover,2013,11.00
SZ10C2599B,SUZUKI,GRAND VITARA,RT Front fog lamp
cover,2013,11.00
SZ10C2598B,SUZUKI,GRAND VITARA,LT Front fog lamp
cover,2013,11.00
SZ10C2598A,SUZUKI,GRAND VITARA,LT Front fog lamp
cover,2013,12.00Category
Why Work with Us
Top Quality and Well-Researched Papers
We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.
Professional and Experienced Academic Writers
We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.
Free Unlimited Revisions
If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.
Prompt Delivery and 100% Money-Back-Guarantee
All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.
Original & Confidential
We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.
24/7 Customer Support
Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.
Try it now!
How it works?
Follow these simple steps to get your paper done
Place your order
Fill in the order form and provide all details of your assignment.
Proceed with the payment
Choose the payment system that suits you most.
Receive the final file
Once your paper is ready, we will email it to you.
Our Services
No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.
Essays
No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.
Admissions
Admission Essays & Business Writing Help
An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.
Reviews
Editing Support
Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.
Reviews
Revision Support
If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.