package cg; //------------------------------------------------------------------------------------------ import java.awt.BorderLayout; import java.awt.Label; import java.awt.TextField; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import javax.swing.JFrame; import com.jogamp.opengl.GLAutoDrawable; import com.jogamp.opengl.GLEventListener; import com.jogamp.opengl.awt.GLCanvas; import com.jogamp.opengl.util.FPSAnimator; //------------------------------------------------------------------------------------------ public class Main implements GLEventListener, MouseListener, MouseMotionListener { private static TextField tf; //------------------------------------------------------------------------------------------ public static void main(String[] args) { GLCanvas canvas = new GLCanvas(); canvas.addGLEventListener(new Main()); canvas.addMouseListener(new Main()); //canvas.addMouseMotionListener(new Main()); FPSAnimator animator = new FPSAnimator(canvas, 60); animator.start(); final int width = 800; final int height = 600; tf = new TextField(30); Label label = new Label("Click and drag the mouse"); label.addMouseMotionListener(new Main()); JFrame frame = new JFrame("OpenGL Fenster"); frame.setSize(width, height); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(canvas); frame.add(tf, BorderLayout.SOUTH); frame.add(label, BorderLayout.NORTH); frame.setVisible(true); canvas.setFocusable(true); } //------------------------------------------------------------------------------------------ public void init(GLAutoDrawable drawable) {} public void display(GLAutoDrawable drawable) {} public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {} public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {} public void dispose(GLAutoDrawable drawable) {} //------------------------------------------------------------------------------------------ @Override public void mouseClicked(MouseEvent e) { String s = "Mouse clicked: X = " + e.getX() + " Y = " + e.getY(); tf.setText(s); } @Override public void mousePressed(MouseEvent e) { System.out.println("Mouse pressed;" + "\n" + "# of clicks: " + e.getClickCount()+ "\n"); } @Override public void mouseReleased(MouseEvent e) { System.out.println("Mouse released;" + "\n" + "# of clicks: " + e.getClickCount()+ "\n"); } @Override public void mouseEntered(MouseEvent e) { System.out.println("Mouse entered: "+ "\n" + "X on screen: " + e.getXOnScreen()+ "\n" + "X: " + e.getX()); } @Override public void mouseExited(MouseEvent e) { System.out.println("Mouse exited: " + e.getPoint()); } //------------------------------------------------------------------------------------------ @Override public void mouseDragged(MouseEvent e) { System.out.println("Mouse dragged: " + e.getWhen()); } @Override public void mouseMoved(MouseEvent e) { System.out.println("Mouse moved: " + e.isShiftDown()); } }