/* * Title: 3 way Sorter (unfinished [Bubble sort only]) * written by: Arthur Gapusan * http://www.planet-java.biz.ly * * - Sorts the values from a file(input.txt) * - create the file input.txt with 1 value per line. * */ import java.awt.*; // import for the Abstract Window Toolkit import java.awt.event.*; // import for Listeners import java.util.*; // import for Vector Class import java.io.*; // import for FileReader class class ReadFile { Vector v = new Vector(); // Vector is one of Java's built-in Collection Framework int count; void readFile() { String str = null; count = 0; try { FileReader fr = new FileReader("input.txt"); BufferedReader br = new BufferedReader(fr); str = new String(); while ((str = br.readLine()) != null) { count++; v.add(str); } } catch (IOException e) { System.out.println("IO error"); } } } /* * * |------------------------| * | Sort 'em out | * |------------------------| * */ class Sorter extends Frame implements ActionListener { TextArea ta1, ta2, ta3; Button start; TextField input, output; int[] num; int len; // Manual Layouting looks better Sorter() { setLayout(null); setBackground(new Color(230, 230, 230)); // Background color(Red, Green, Blue) ta1 = new TextArea(); add(ta1); ta1.setFont(new Font("Verdana", Font.BOLD, 14)); ta1.setForeground(Color.gray); ta1.setBounds(20, 80, 100, 200); ta2 = new TextArea(); add(ta2); ta2.setBounds(140, 80, 100, 200); ta3 = new TextArea(); add(ta3); ta3.setBounds(260, 80, 100, 200); Label l1 = new Label("Bubble Sort"); l1.setFont(new Font("SansSerif", Font.BOLD, 14)); l1.setBounds(20,55, 100, 30); l1.setForeground(new Color(120, 160, 200)); add(l1); Label l2 = new Label("Quick Sort"); l2.setFont(new Font("SansSerif", Font.BOLD, 14)); l2.setBounds(140,55, 100, 30); l2.setForeground(new Color(120, 160, 200)); add(l2); Label l3 = new Label("Radix Sort"); l3.setFont(new Font("SansSerif", Font.BOLD, 14)); l3.setBounds(260,55, 100, 30); l3.setForeground(new Color(120, 160, 200)); add(l3); Label top = new Label("Input Data: "); top.setFont(new Font("SansSerif", Font.BOLD, 16)); top.setBounds(20,25, 90, 30); top.setForeground(new Color(33, 88, 33)); add(top); input = new TextField(30); input.setBounds(110, 28, 250, 25); input.setFont(new Font("Sylfaen", Font.BOLD, 16)); add(input); start = new Button("Start"); start.setBounds(20,295, 60, 25); start.setForeground(new Color(50, 190, 50)); start.setFont(new Font("SansSerif", Font.BOLD, 16)); add(start); Label ol = new Label("Output: "); ol.setFont(new Font("SansSerif", Font.BOLD, 16)); ol.setBounds(95, 295, 60, 30); ol.setForeground(new Color(33, 88, 33)); add(ol); output = new TextField(30); output.setBounds(160, 295, 200, 25); output.setFont(new Font("SansSerif", Font.BOLD, 16)); add(output); start.addActionListener(this); addWindowListener(new Window()); getInputs(); // get values from the file String str = String.valueOf(num[0]); // display those values for (int i=1;inum[j]) { int temp = num[i]; num[i] = num[j]; num[j] = temp; displaySort(); // display the values every swap } } } } void displaySort() { try { String record = String.valueOf(num[0]); for (int s=1;s