00001
00025 import java.awt.*;
00026 import java.awt.event.*;
00027 import java.util.*;
00028
00029 import sorting.*;
00030
00031
00047 public class DoxygenExample extends Frame
00048 {
00049
00050
00051 private Panel ssPanel = new Panel(null);
00052 private Panel isPanel = new Panel(null);
00053 private Panel bsPanel = new Panel(null);
00054
00055
00056 private Label label1 = new Label();
00057 private Label label2 = new Label();
00058 private Label label3 = new Label();
00059
00060
00061 private Panel buttonPanel = new Panel(null);
00062
00063 private Button startButton = new Button();
00064 private Button randomizeButton = new Button();
00065 private Button randStartButton = new Button();
00066 private Button ssButton = new Button();
00067 private Button isButton = new Button();
00068 private Button bsButton = new Button();
00069 private Button exitButton = new Button();
00070
00071
00072 private Label ssTimeLabel = new Label();
00073 private Label isTimeLabel = new Label();
00074 private Label bsTimeLabel = new Label();
00075
00076 private int[] ssArray = new int[210];
00077 private int[] isArray = new int[210];
00078 private int[] bsArray = new int[210];
00079
00080
00088 public DoxygenExample(String title)
00089 {
00090 super(title);
00091
00092 addWindowListener(new WindowAdapter() {
00093 public void windowClosing(WindowEvent evt) { System.exit(0); }
00094 });
00095
00096 int frameWidth = 900;
00097 int frameHeight = 400;
00098 setSize(frameWidth, frameHeight);
00099 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
00100 int x = (d.width - getSize().width) / 2;
00101 int y = (d.height - getSize().height) / 2 ;
00102 setLocation(x, y);
00103 Panel cp = new Panel(null);
00104 add(cp);
00105
00106 this.setBackground(new Color(240, 240, 240));
00107
00108 ssPanel.setBounds(16, 40, 250, 200);
00109 cp.add(ssPanel);
00110 isPanel.setBounds(324, 40, 250, 200);
00111 cp.add(isPanel);
00112 bsPanel.setBounds(632, 40, 250, 200);
00113 cp.add(bsPanel);
00114 label1.setBounds(16, 16, 90, 16);
00115 label1.setText("Selectionsort");
00116 label1.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
00117 cp.add(label1);
00118 label2.setBounds(324, 16, 90, 16);
00119 label2.setText("Insertionsort");
00120 label2.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
00121 cp.add(label2);
00122 label3.setBounds(632, 16, 90, 16);
00123 label3.setText("Bubblesort");
00124 label3.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
00125 cp.add(label3);
00126 buttonPanel.setBounds(16, 280, 860, 81);
00127 cp.add(buttonPanel);
00128 startButton.setBounds(140, 48, 110, 25);
00129 randomizeButton.setBounds(16, 48, 110, 25);
00130 randStartButton.setBounds(380, 48, 110, 25);
00131 ssButton.setBounds(16,5,230,25);
00132 ssButton.setLabel("start");
00133 startButton.setLabel("start sorting");
00134 randomizeButton.setLabel("ramdomize");
00135 randStartButton.setLabel("randomized start");
00136 buttonPanel.add(randStartButton);
00137 buttonPanel.add(startButton);
00138 buttonPanel.add(randomizeButton);
00139 buttonPanel.add(ssButton);
00140 buttonPanel.add(isButton);
00141 buttonPanel.add(bsButton);
00142
00143 ssButton.setBounds(16,10,220,25);
00144 ssButton.setLabel("start selectionsort");
00145 isButton.setBounds(324,10,220,25);
00146 isButton.setLabel("start insertionsort");
00147 bsButton.setBounds(632,10,220,25);
00148 bsButton.setLabel("start bubblesort");
00149
00150 ssPanel.setBackground(new Color(128,128,128));
00151 isPanel.setBackground(new Color(128,128,128));
00152 bsPanel.setBackground(new Color(128,128,128));
00153 buttonPanel.setBackground(new Color(192,192,192));
00154
00155
00156 randomizeButton.addActionListener(new ActionListener() {
00157 public void actionPerformed(ActionEvent evt) {
00158 randomizeButtonActionPerformed(evt);
00159 }
00160 });
00161
00162 randStartButton.addActionListener(new ActionListener() {
00163 public void actionPerformed(ActionEvent evt) {
00164 randStartButtonActionPerformed(evt);
00165 }
00166 });
00167
00168 startButton.addActionListener(new ActionListener() {
00169 public void actionPerformed(ActionEvent evt) {
00170 startButtonActionPerformed(evt);
00171 }
00172 });
00173
00174 ssButton.addActionListener(new ActionListener() {
00175 public void actionPerformed(ActionEvent evt) {
00176 ssButtonActionPerformed(evt);
00177 }
00178 });
00179
00180 isButton.addActionListener(new ActionListener() {
00181 public void actionPerformed(ActionEvent evt) {
00182 isButtonActionPerformed(evt);
00183 }
00184 });
00185
00186 bsButton.addActionListener(new ActionListener() {
00187 public void actionPerformed(ActionEvent evt) {
00188 bsButtonActionPerformed(evt);
00189 }
00190 });
00191
00192
00193 exitButton.setBounds(772, 48, 75, 25);
00194 exitButton.setLabel("exit");
00195 buttonPanel.add(exitButton);
00196
00197 exitButton.addActionListener(new ActionListener() {
00198 public void actionPerformed(ActionEvent evt) {
00199 exitButtonActionPerformed(evt);
00200 }
00201 });
00202
00203 ssTimeLabel.setBounds(16, 256, 120, 16);
00204 ssTimeLabel.setText(" ");
00205 ssTimeLabel.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
00206 cp.add(ssTimeLabel);
00207 isTimeLabel.setBounds(324, 256, 120, 16);
00208 isTimeLabel.setText(" ");
00209 isTimeLabel.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
00210 cp.add(isTimeLabel);
00211 bsTimeLabel.setBounds(632, 256, 120, 16);
00212 bsTimeLabel.setText(" ");
00213 bsTimeLabel.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
00214 cp.add(bsTimeLabel);
00215
00216 setResizable(false);
00217 setVisible(true);
00218
00219 this.randomizeArrays();
00220 }
00221
00222
00226 public void randomizeArrays()
00227 {
00228
00229
00230 Random r = new Random(System.currentTimeMillis());
00231
00232 for (int i=0; i<210; i++)
00233 {
00234 ssArray[i] = 1 + (Math.abs(r.nextInt()) % 180);
00235
00236 isArray[i] = ssArray[i];
00237 bsArray[i] = ssArray[i];
00238 }
00239
00240
00241 Paint.showArray(ssArray, ssPanel);
00242 Paint.showArray(isArray, isPanel);
00243 Paint.showArray(bsArray, bsPanel);
00244 }
00245
00249 public void startSelectionSort()
00250 {
00251 SelectionSort sSort = new SelectionSort();
00252 sSort.setSettings(this.ssArray, this.ssPanel, this.ssTimeLabel);
00253 Thread ssThread = new Thread(sSort);
00254
00255 ssThread.start();
00256
00257
00258 try
00259 {
00260 ssThread.join();
00261 }
00262 catch (InterruptedException ie)
00263 {
00264
00265 }
00266 }
00267
00271 public void startInsertionSort()
00272 {
00273 InsertionSort iSort = new InsertionSort();
00274 iSort.setSettings(this.isArray, this.isPanel, this.isTimeLabel);
00275 Thread isThread = new Thread(iSort);
00276
00277
00278 isThread.start();
00279
00280
00281 try
00282 {
00283 isThread.join();
00284 }
00285 catch (InterruptedException ie)
00286 {
00287
00288 }
00289 }
00290
00294 public void startBubbleSort()
00295 {
00296 BubbleSort bSort = new BubbleSort();
00297 bSort.setSettings(this.bsArray, this.bsPanel, this.bsTimeLabel);
00298 Thread bsThread = new Thread(bSort);
00299
00300
00301 bsThread.start();
00302
00303
00304 try
00305 {
00306 bsThread.join();
00307 }
00308 catch (InterruptedException ie)
00309 {
00310
00311 }
00312 }
00313
00317 public void sortArrays()
00318 {
00319 SelectionSort sSort = new SelectionSort();
00320 sSort.setSettings(this.ssArray, this.ssPanel, this.ssTimeLabel);
00321 Thread ssThread = new Thread(sSort);
00322
00323 InsertionSort iSort = new InsertionSort();
00324 iSort.setSettings(this.isArray, this.isPanel, this.isTimeLabel);
00325 Thread isThread = new Thread(iSort);
00326
00327 BubbleSort bSort = new BubbleSort();
00328 bSort.setSettings(this.bsArray, this.bsPanel, this.bsTimeLabel);
00329 Thread bsThread = new Thread(bSort);
00330
00331
00332
00333
00334
00335
00336 ssThread.start();
00337 isThread.start();
00338 bsThread.start();
00339
00340
00341
00342 try
00343 {
00344 ssThread.join();
00345 }
00346 catch (InterruptedException ie)
00347 {
00348
00349 }
00350
00351 try
00352 {
00353 isThread.join();
00354 }
00355 catch (InterruptedException ie)
00356 {
00357
00358 }
00359
00360 try
00361 {
00362 bsThread.join();
00363 }
00364 catch (InterruptedException ie)
00365 {
00366
00367 }
00368 }
00369
00374 public void ssButtonActionPerformed(ActionEvent evt)
00375 {
00376 this.startSelectionSort();
00377 }
00378
00383 public void isButtonActionPerformed(ActionEvent evt)
00384 {
00385 this.startInsertionSort();
00386 }
00387
00392 public void bsButtonActionPerformed(ActionEvent evt)
00393 {
00394 this.startBubbleSort();
00395 }
00396
00401 public void randomizeButtonActionPerformed(ActionEvent evt)
00402 {
00403 this.randomizeArrays();
00404 }
00405
00411 public void randStartButtonActionPerformed(ActionEvent evt)
00412 {
00413 this.randomizeArrays();
00414 this.sortArrays();
00415 }
00416
00422 public void startButtonActionPerformed(ActionEvent evt)
00423 {
00424 this.sortArrays();
00425 }
00426
00431 public void exitButtonActionPerformed(ActionEvent evt)
00432 {
00433 System.exit(0);
00434 }
00435
00440 public static void main(String[] args)
00441 {
00442 new DoxygenExample("Selectionsort, Insertionsort and Bubblesort");
00443 }
00444 }
00445