Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pv112;
- import com.jogamp.opengl.util.FPSAnimator;
- import javax.media.opengl.GLCapabilities;
- import javax.media.opengl.GLProfile;
- import javax.media.opengl.awt.GLJPanel;
- public class MainWindow extends javax.swing.JFrame {
- private final GLJPanel glPanel;
- private GLProfile profile = GLProfile.get(GLProfile.GL2);
- private OpenGlListener openGlListener;
- private FPSAnimator animator;
- /**
- * Creates new form MainWindow
- */
- public MainWindow() {
- // nastavi full-screen zobrazeni
- // setUndecorated(true); // no decoration such as title bar
- // setExtendedState(MAXIMIZED_BOTH); // full screen mode
- initComponents();
- // vycentruje okno na stred plochy
- setLocationRelativeTo(null);
- // vytvori sa viditelny panel na ktorom sa bude zobrazovat nas graficky vystup
- glPanel = new GLJPanel(new GLCapabilities(profile));
- animator = new FPSAnimator(glPanel, 60, true);
- //animator.start();
- // tento panel sa umiestni na halvne okno aplikacie
- add(glPanel);
- // vytvoreni instance openGlListener
- openGlListener = new OpenGlListener(glPanel);
- // rozmery glPanela sa nastavia tak, aby sa zhodovali s rozmermi hlavneho okna
- glPanel.setSize(getWidth() - getInsets().left - getInsets().right,
- getHeight() - getInsets().top - getInsets().bottom);
- // k glPanelu pripojime OpenGLListener, aby sme mohli reagovat na udalosti
- // generovane tymto panelom
- glPanel.addGLEventListener(openGlListener);
- // k glPanelu pripojime KeyListener
- glPanel.addKeyListener(openGlListener);
- glPanel.requestFocusInWindow(); // glPanel bude moci reagovat na udalosti
- }
- /**
- * This method is called from within the constructor to initialize the form. WARNING:
- * Do NOT modify this code. The content of this method is always regenerated by the
- * Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- addWindowListener(new java.awt.event.WindowAdapter() {
- public void windowClosing(java.awt.event.WindowEvent evt) {
- formWindowClosing(evt);
- }
- });
- addComponentListener(new java.awt.event.ComponentAdapter() {
- public void componentResized(java.awt.event.ComponentEvent evt) {
- formComponentResized(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 800, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 600, Short.MAX_VALUE)
- );
- pack();
- }// </editor-fold>
- // udalost: zmena velkosti okna (events -> component -> component resized)
- private void formComponentResized(java.awt.event.ComponentEvent evt) {
- glPanel.setSize(getWidth() - getInsets().left - getInsets().right,
- getHeight() - getInsets().top - getInsets().bottom);
- }
- //udalost: zavreni okna (events -> window -> window closing)
- private void formWindowClosing(java.awt.event.WindowEvent evt) {
- // TODO
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- @Override
- public void run() {
- new MainWindow().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment