ljukk

frame ku kamenu

May 29th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.56 KB | None | 0 0
  1. public class NewJFrame extends javax.swing.JFrame {
  2.  
  3.     /**
  4.      * Creates new form NewJFrame
  5.      */
  6.    
  7.     Kamen kamene[]; //1 rozemrne pole
  8.    
  9.     public NewJFrame() {
  10.         initComponents();
  11.         kamene = new Kamen[10];  //vyhradim priestor pre pole 10 kamenov
  12.        
  13.         for (int i=0; i<10; i++) { // 10 kamenov
  14.                     kamene[i] = new Kamen(10 + i*40,50,i,kamene); // pamatam si adresy jednotlivych objektov v 1 rozmernom poli
  15.                     this.add(kamene[i]);
  16.                     this.repaint();
  17.                 }
  18.         zamiesaj();
  19.             }
  20.  
  21.     /**
  22.      * This method is called from within the constructor to initialize the form.
  23.      * WARNING: Do NOT modify this code. The content of this method is always
  24.      * regenerated by the Form Editor.
  25.      */
  26.    
  27.    
  28.    
  29.     private void zamiesaj(){
  30.         for (int i = 0; i<10; i++) {
  31.             int x = (int)(Math.random()*10);
  32.             kamene[x].otocKamen();
  33.         }
  34.     }
  35.    
  36.     @SuppressWarnings("unchecked")
  37.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  38.     private void initComponents() {
  39.  
  40.         jButton1 = new javax.swing.JButton();
  41.  
  42.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  43.  
  44.         jButton1.setText("Zamiesaj");
  45.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  46.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  47.                 jButton1ActionPerformed(evt);
  48.             }
  49.         });
  50.  
  51.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  52.         getContentPane().setLayout(layout);
  53.         layout.setHorizontalGroup(
  54.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  55.             .addGroup(layout.createSequentialGroup()
  56.                 .addContainerGap()
  57.                 .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
  58.                 .addContainerGap(363, Short.MAX_VALUE))
  59.         );
  60.         layout.setVerticalGroup(
  61.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  62.             .addGroup(layout.createSequentialGroup()
  63.                 .addContainerGap()
  64.                 .addComponent(jButton1)
  65.                 .addContainerGap(121, Short.MAX_VALUE))
  66.         );
  67.  
  68.         pack();
  69.     }// </editor-fold>                        
  70.  
  71.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  72.        
  73.         zamiesaj();
  74.      
  75.            
  76.        
  77.        
  78.     }                                        
  79.  
  80.     /**
  81.      * @param args the command line arguments
  82.      */
  83.     public static void main(String args[]) {
  84.         /* Set the Nimbus look and feel */
  85.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  86.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  87.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  88.          */
  89.         try {
  90.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  91.                 if ("Nimbus".equals(info.getName())) {
  92.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  93.                     break;
  94.                 }
  95.             }
  96.         } catch (ClassNotFoundException ex) {
  97.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  98.         } catch (InstantiationException ex) {
  99.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  100.         } catch (IllegalAccessException ex) {
  101.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  102.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  103.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  104.         }
  105.         //</editor-fold>
  106.  
  107.         /* Create and display the form */
  108.         java.awt.EventQueue.invokeLater(new Runnable() {
  109.             public void run() {
  110.                 new NewJFrame().setVisible(true);
  111.             }
  112.         });
  113.     }
  114.  
  115.     // Variables declaration - do not modify                    
  116.     private javax.swing.JButton jButton1;
  117.     // End of variables declaration                  
  118. }
Add Comment
Please, Sign In to add comment