2
« on: June 02, 2009, 04:11:14 pm »
I did some tests and realised it happens when moving the mouse and pressing the button at the same time.
import com.threed.jpct.*;
//import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.KeyListener;
//import java.awt.Insets;
import javax.swing.JFrame;
public class mousebutton extends JFrame implements MouseListener,
MouseMotionListener,KeyListener {
public static World world;
private FrameBuffer buffer;
public JFrame frame;
public void keyPressed(KeyEvent e)
{}
public void keyTyped(KeyEvent e)
{
if (e.getKeyCode()==KeyEvent.VK_A)
{
//System.out.println("typed a");
}
//nothing
}
public void keyReleased(KeyEvent e)
{
if (e.getKeyCode()==KeyEvent.VK_W)
{
//System.out.println("released a");
}
//nothing
}
public static void main(String[] args) throws Exception {
new mousebutton().loop();
}
public void mouseEntered( MouseEvent e ) {}
public void mouseExited( MouseEvent e ) {}
public void mouseReleased( MouseEvent e ){
System.out.println("mouse released");
}
public void mouseClicked( MouseEvent e ){
System.out.println("mouse clicked");
}
public void mousePressed( MouseEvent e )
{
}
public void mouseMoved( MouseEvent e ) {
int x = e.getX();
int y = e.getY();
}
public void mouseDragged( MouseEvent e )
{
// get the mouse's coordinates:
}
public mousebutton() throws Exception {
frame=new JFrame("Hello world");
frame.setSize(800, 600);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}
private void loop() throws Exception {
FrameBuffer buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
Canvas canvas=buffer.enableGLCanvasRenderer();
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
frame.add(canvas);
canvas.addMouseListener( this );
canvas.addMouseMotionListener( this );
canvas.addKeyListener(this);
while (frame.isShowing()) {
buffer.clear(java.awt.Color.BLACK);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.displayGLOnly();
canvas.repaint();
//Bullet.update_bullets();
Thread.sleep(10);
//System.out.println(Mouse.getDX());
}
//buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
// buffer.dispose();
frame.dispose();
System.exit(0);
}
}
notice only mouse release events are generated, when moving the mouse