Guest User

Untitled

a guest
Jan 7th, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.16 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 07.01.2014
  11.   * @author  Matthias Borkowski & Lukasz Pecherczyk
  12.   */
  13.  
  14. public class Cyber extends JFrame {
  15.   // Anfang Attribute
  16.   private JButton jButton1 = new JButton();
  17.   private JTextArea a = new JTextArea("");
  18.     private JScrollPane aScrollPane = new JScrollPane(a);
  19.   private static JTextField b = new JTextField();
  20.   private JLabel jLabel1 = new JLabel();
  21.   private JLabel jLabel2 = new JLabel();
  22.   // Ende Attribute
  23.  
  24.   public Cyber(String title) {
  25.     // Frame-Initialisierung
  26.     super(title);
  27.     setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  28.     int frameWidth = 300;
  29.     int frameHeight = 310;
  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.    
  39.     // Anfang Komponenten
  40.     jButton1.setBounds(104, 80, 97, 33);
  41.     jButton1.setText("Generiere");
  42.     jButton1.setMargin(new Insets(2, 2, 2, 2));
  43.     jButton1.addActionListener(new ActionListener() {
  44.       public void actionPerformed(ActionEvent evt) {
  45.         jButton1_ActionPerformed(evt);
  46.       }
  47.     });
  48.     jButton1.setBorderPainted(false);
  49.     jButton1.setBackground(new Color(0x53C7FF));
  50.     jButton1.setContentAreaFilled(true);
  51.     jButton1.setCursor(new Cursor(Cursor.HAND_CURSOR));
  52.     jButton1.setFont(new Font("Century Gothic", Font.BOLD, 16));
  53.     jButton1.setFocusPainted(false);
  54.     cp.add(jButton1);
  55.     cp.setBackground(new Color(0xA6E2FF));
  56.     aScrollPane.setBounds(16, 160, 105, 65);
  57.     aScrollPane.setBorder(null);
  58.     a.setBackground(new Color(0xA6E2FF));
  59.     a.setEditable(false);
  60.     a.setForeground(Color.BLACK);
  61.  
  62.     cp.add(aScrollPane);
  63.     b.setBounds(168, 144, 105, 105);
  64.     b.setBackground(new Color(0x93DCFF));
  65.     b.setEditable(false);
  66.     b.setForeground(Color.BLACK);
  67.     b.setBorder(javax.swing.BorderFactory.createEmptyBorder());
  68.  
  69.     cp.add(b);
  70.     jLabel1.setBounds(0, 8, 299, 60);
  71.     jLabel1.setText("Lucky Button");
  72.     jLabel1.setFont(new Font("Century Gothic", Font.BOLD, 48));
  73.     cp.add(jLabel1);
  74.     jLabel2.setBounds(112, 264, 180, 19);
  75.     jLabel2.setText("© by Cyberkosmographisch AG");
  76.     cp.add(jLabel2);
  77.     setUndecorated(false);
  78.     // Ende Komponenten
  79.    
  80.     setVisible(true);
  81.   } // end of public Cyber
  82.  
  83.   // Anfang Methoden
  84.   public void jButton1_ActionPerformed(ActionEvent evt) {
  85.    
  86.     int rzahlen[] = new int[6];
  87.     int j = 0;
  88.    
  89.     //Array füllen.    
  90.     for (int i = 0; i < rzahlen.length; i++) {
  91.       rzahlen[i] = (int) (Math.random()*50);
  92.     }
  93.    
  94.     //Sortierung.
  95.     int i, startwert, temp;
  96.    
  97.     for (i = rzahlen.length - 1; i > 0; i-- ){
  98.       startwert = 0;
  99.       for(j = 1; j <= i; j++){             //Das kleinste Element zwischen 1 und i wird ermittelt.
  100.         if(rzahlen[j] > rzahlen[startwert])        
  101.         startwert = j;
  102.       }
  103.       temp = rzahlen[startwert];   //Der kleinste Wert wird mit "i" getauscht.
  104.       rzahlen[startwert] = rzahlen[i];
  105.       rzahlen[i] = temp;
  106.     }
  107.    
  108.     //Array auslesen!
  109.     a.setText("Gewinnerzahlen: \n\n");
  110.     for (int p = 0; p < rzahlen.length; p++) {
  111.       a.append(String.valueOf(rzahlen[p])+" ");
  112.     } // end of for
  113.   } // end of jButton1_ActionPerformed
  114.   // Ende Methoden
  115.  
  116.   public static void main(String[] args) {
  117.     new Cyber("Cyber");
  118.     int eingabe;
  119.     int ezahlen[] = new int[6];
  120.    
  121.    
  122.     //Zahlen abfragen und ins Array stecken!
  123.     for (int i = 0; i < ezahlen.length; i++) {
  124.       String s = javax.swing.JOptionPane.showInputDialog("Bitte Zahl zwischen 0 und 49 eingeben");
  125.       eingabe = Integer.parseInt(s);
  126.       ezahlen[i] = eingabe;
  127.     } // end of for
  128.    
  129.    
  130.     //Ausgabe des Arrays!
  131.     for (int h = 0; h < ezahlen.length; h++) {
  132.       b.setText(String.valueOf(ezahlen[h])+" ");
  133.     } // end of for
  134.    
  135.   } // end of main
  136.  
  137.  
  138. } // end of class Cyber
Advertisement
Add Comment
Please, Sign In to add comment