Witiko

Untitled

Feb 25th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.68 KB | None | 0 0
  1. package pv112;
  2.  
  3. import com.jogamp.opengl.util.FPSAnimator;
  4. import javax.media.opengl.GLCapabilities;
  5. import javax.media.opengl.GLProfile;
  6. import javax.media.opengl.awt.GLJPanel;
  7.  
  8. public class MainWindow extends javax.swing.JFrame {
  9.  
  10.     private final GLJPanel glPanel;
  11.     private GLProfile profile = GLProfile.get(GLProfile.GL2);
  12.     private OpenGlListener openGlListener;
  13.     private FPSAnimator animator;
  14.  
  15.     /**
  16.      * Creates new form MainWindow
  17.      */
  18.     public MainWindow() {
  19.  
  20.         // nastavi full-screen zobrazeni
  21. //        setUndecorated(true);     // no decoration such as title bar
  22. //        setExtendedState(MAXIMIZED_BOTH);  // full screen mode
  23.  
  24.         initComponents();
  25.  
  26.         // vycentruje okno na stred plochy
  27.         setLocationRelativeTo(null);
  28.  
  29.         // vytvori sa viditelny panel na ktorom sa bude zobrazovat nas graficky vystup
  30.         glPanel = new GLJPanel(new GLCapabilities(profile));
  31.         animator = new FPSAnimator(glPanel, 60, true);
  32.         //animator.start();
  33.  
  34.         // tento panel sa umiestni na halvne okno aplikacie
  35.         add(glPanel);
  36.        
  37.         // vytvoreni instance openGlListener
  38.         openGlListener = new OpenGlListener(glPanel);
  39.  
  40.         // rozmery glPanela sa nastavia tak, aby sa zhodovali s rozmermi hlavneho okna
  41.         glPanel.setSize(getWidth() - getInsets().left - getInsets().right,
  42.                 getHeight() - getInsets().top - getInsets().bottom);
  43.  
  44.         // k glPanelu pripojime OpenGLListener, aby sme mohli reagovat na udalosti
  45.         // generovane tymto panelom
  46.         glPanel.addGLEventListener(openGlListener);
  47.  
  48.         // k glPanelu pripojime KeyListener
  49.         glPanel.addKeyListener(openGlListener);
  50.         glPanel.requestFocusInWindow(); // glPanel bude moci reagovat na udalosti
  51.  
  52.  
  53.     }
  54.  
  55.     /**
  56.      * This method is called from within the constructor to initialize the form. WARNING:
  57.      * Do NOT modify this code. The content of this method is always regenerated by the
  58.      * Form Editor.
  59.      */
  60.     @SuppressWarnings("unchecked")
  61.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  62.     private void initComponents() {
  63.  
  64.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  65.         addWindowListener(new java.awt.event.WindowAdapter() {
  66.             public void windowClosing(java.awt.event.WindowEvent evt) {
  67.                 formWindowClosing(evt);
  68.             }
  69.         });
  70.         addComponentListener(new java.awt.event.ComponentAdapter() {
  71.             public void componentResized(java.awt.event.ComponentEvent evt) {
  72.                 formComponentResized(evt);
  73.             }
  74.         });
  75.  
  76.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  77.         getContentPane().setLayout(layout);
  78.         layout.setHorizontalGroup(
  79.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  80.             .addGap(0, 800, Short.MAX_VALUE)
  81.         );
  82.         layout.setVerticalGroup(
  83.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  84.             .addGap(0, 600, Short.MAX_VALUE)
  85.         );
  86.  
  87.         pack();
  88.     }// </editor-fold>                        
  89.  
  90.     // udalost: zmena velkosti okna (events -> component -> component resized)
  91.     private void formComponentResized(java.awt.event.ComponentEvent evt) {                                      
  92.         glPanel.setSize(getWidth() - getInsets().left - getInsets().right,
  93.                 getHeight() - getInsets().top - getInsets().bottom);
  94.     }                                    
  95.  
  96.     //udalost: zavreni okna (events -> window -> window closing)
  97.     private void formWindowClosing(java.awt.event.WindowEvent evt) {                                  
  98.         // TODO
  99.     }                                  
  100.  
  101.     /**
  102.      * @param args the command line arguments
  103.      */
  104.     public static void main(String args[]) {
  105.         /* Set the Nimbus look and feel */
  106.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  107.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  108.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  109.          */
  110.         try {
  111.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  112.                 if ("Nimbus".equals(info.getName())) {
  113.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  114.                     break;
  115.                 }
  116.             }
  117.         } catch (ClassNotFoundException ex) {
  118.             java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  119.         } catch (InstantiationException ex) {
  120.             java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  121.         } catch (IllegalAccessException ex) {
  122.             java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  123.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  124.             java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  125.         }
  126.         //</editor-fold>
  127.  
  128.         /* Create and display the form */
  129.         java.awt.EventQueue.invokeLater(new Runnable() {
  130.             @Override
  131.             public void run() {
  132.                 new MainWindow().setVisible(true);
  133.             }
  134.         });
  135.     }
  136.     // Variables declaration - do not modify                    
  137.     // End of variables declaration                  
  138. }
Advertisement
Add Comment
Please, Sign In to add comment