Advertisement
Guest User

Untitled

a guest
Jan 27th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.06 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import javax.swing.event.*;
  5.  
  6. /**
  7.   *
  8.   * Beschreibung
  9.   *
  10.   * @version 1.0 vom 26.01.2014
  11.   * @author
  12.   */
  13.  
  14. public class Bubblesort2 extends JFrame {
  15.   // Anfang Attribute
  16.   private JTextArea jTextArea1 = new JTextArea("");
  17.     private JScrollPane jTextArea1ScrollPane = new JScrollPane(jTextArea1);
  18.   private JTextArea jTextArea2 = new JTextArea("");
  19.     private JScrollPane jTextArea2ScrollPane = new JScrollPane(jTextArea2);
  20.   private JButton jButton1 = new JButton();
  21.    int array [] = new int [10];
  22.   // Ende Attribute
  23.  
  24.   public Bubblesort2(String title) {
  25.     // Frame-Initialisierung
  26.     super(title);
  27.     setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  28.     int frameWidth = 300;
  29.     int frameHeight = 300;
  30.     setSize(frameWidth, frameHeight);
  31.     Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  32.     int x = (d.width - getSize().width) / 2;
  33.     int y = (d.height - getSize().height) / 2;
  34.     setLocation(x, y);
  35.     setResizable(false);
  36.     Container cp = getContentPane();
  37.     cp.setLayout(null);
  38.     // Anfang Komponenten
  39.    
  40.     jTextArea1ScrollPane.setBounds(8, 16, 89, 241);
  41.     cp.add(jTextArea1ScrollPane);
  42.     jTextArea2ScrollPane.setBounds(192, 24, 81, 233);
  43.     cp.add(jTextArea2ScrollPane);
  44.     jButton1.setBounds(120, 80, 57, 33);
  45.     jButton1.setText("jButton1");
  46.     jButton1.setMargin(new Insets(2, 2, 2, 2));
  47.     jButton1.addActionListener(new ActionListener() {
  48.       public void actionPerformed(ActionEvent evt) {
  49.         jButton1_ActionPerformed(evt);
  50.       }
  51.     });
  52.     cp.add(jButton1);
  53.     // Ende Komponenten
  54.    
  55.     setVisible(true);
  56.   } // end of public Bubblesort2
  57.  
  58.   // Anfang Methoden
  59.   public static void quicksort (int array[],int l,int r){
  60.     int i = l;
  61.     int j = r;
  62.     int mitte = array [(l+r)/2];
  63.    
  64.     while (i<j) {
  65.       while  (array[i]<mitte) {
  66.         i++;
  67.       } // end of if
  68.       while  (mitte<array[i]) {
  69.         j--;
  70.       } // end of if
  71.       if (i<=j) {
  72.         int merke =array[i];
  73.         array[i] = array [j];
  74.         array [j] = merke ;
  75.         i++;
  76.         j--;
  77.       } // end of if
  78.       if (i<j) {
  79.         quicksort(array,l,j);
  80.       } // end of if
  81.       if (l<r) {
  82.         quicksort(array,l,r);
  83.       } // end of if
  84.     } // end of while
  85.   }
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.   public void jButton1_ActionPerformed(ActionEvent evt) {
  97.     for (int i =0;i<10;i++) {
  98.       array [i] = i+1;
  99.       jTextArea1.append(Integer.toString(array[i]));
  100.       jTextArea1.append("\n");
  101.     } // end of for  // TODO hier Quelltext einfügen
  102.     quicksort(array,1,2);
  103.     for (int i =0;i<10;i++) {
  104.       array [i] = i+1;
  105.       jTextArea2.append(Integer.toString(array[i]));
  106.       jTextArea2.append("\n");
  107.     } // end of for  // TODO hier Quelltext einfügen
  108.    
  109.    
  110.   } // end of jButton1_ActionPerformed
  111.  
  112.   // Ende Methoden
  113.    
  114.   public static void main(String[] args) {
  115.     new Bubblesort2("Bubblesort2");
  116.   } // end of main
  117.    
  118.   } // end of class Bubblesort2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement