Advertisement
ljukk

frame k muche

May 29th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.13 KB | None | 0 0
  1.  
  2. import java.util.Random;
  3.  
  4. public class Plocha extends javax.swing.JFrame {
  5.  
  6.    
  7.     public Plocha() {
  8.         initComponents();
  9.         Random generator = new Random(); // generator
  10.         for (int i = 0; i<10; i++) { // kolko much sa vytvori
  11.             int x = generator.nextInt(getWidth()); //nahodne vygenerovana sirka x muchy
  12.             int y = generator.nextInt(getHeight()); // nahodne vygenrovana vyska y muchy
  13.             this.add(new Mucha(x,y,this));  // pridavam muchu na formular
  14.         }
  15.     }
  16.  
  17.    
  18.     @SuppressWarnings("unchecked")
  19.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  20.     private void initComponents() {
  21.  
  22.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  23.  
  24.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  25.         getContentPane().setLayout(layout);
  26.         layout.setHorizontalGroup(
  27.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  28.             .addGap(0, 400, Short.MAX_VALUE)
  29.         );
  30.         layout.setVerticalGroup(
  31.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  32.             .addGap(0, 300, Short.MAX_VALUE)
  33.         );
  34.  
  35.         pack();
  36.     }// </editor-fold>                        
  37.  
  38.     /**
  39.      * @param args the command line arguments
  40.      */
  41.     public static void main(String args[]) {
  42.         /* Set the Nimbus look and feel */
  43.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  44.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  45.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  46.          */
  47.         try {
  48.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  49.                 if ("Nimbus".equals(info.getName())) {
  50.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  51.                     break;
  52.                 }
  53.             }
  54.         } catch (ClassNotFoundException ex) {
  55.             java.util.logging.Logger.getLogger(Plocha.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  56.         } catch (InstantiationException ex) {
  57.             java.util.logging.Logger.getLogger(Plocha.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  58.         } catch (IllegalAccessException ex) {
  59.             java.util.logging.Logger.getLogger(Plocha.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  60.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  61.             java.util.logging.Logger.getLogger(Plocha.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  62.         }
  63.         //</editor-fold>
  64.  
  65.         /* Create and display the form */
  66.         java.awt.EventQueue.invokeLater(new Runnable() {
  67.             public void run() {
  68.                 new Plocha().setVisible(true);
  69.             }
  70.         });
  71.     }
  72.  
  73.     // Variables declaration - do not modify                    
  74.     // End of variables declaration                  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement