From 5d596cd7c3a600198132f65936ca59a382762a62 Mon Sep 17 00:00:00 2001 From: Brian Matzon Date: Sun, 17 Nov 2002 18:15:01 +0000 Subject: [PATCH] accompanying test for the joystick implementation --- .../org/lwjgl/input/test/JoystickTest.java | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 src/java/org/lwjgl/input/test/JoystickTest.java diff --git a/src/java/org/lwjgl/input/test/JoystickTest.java b/src/java/org/lwjgl/input/test/JoystickTest.java new file mode 100644 index 00000000..fd05f005 --- /dev/null +++ b/src/java/org/lwjgl/input/test/JoystickTest.java @@ -0,0 +1,123 @@ +/* + * JoystickTest.java + * + * Created on 13. november 2002, 22:49 + */ + +package org.lwjgl.input.test; + +import java.awt.*; +import java.awt.event.*; +import org.lwjgl.input.Joystick; + +/** + * + * @author Brian Matzon + */ +public class JoystickTest extends Panel { + + private Joystick joystick = null; + + private int counter = 0; + + public Thread animationThread; + + /** Creates a new instance of JoystickTest */ + public JoystickTest() { + joystick = new Joystick(); + try { + joystick.create(); + } catch (Exception e) { + e.printStackTrace(); + joystick = null; + } + + animationThread = new Thread() { + public void run() { + while (true) { + paint(getGraphics()); + + try { + Thread.sleep(250); + } catch (InterruptedException inte) { + inte.printStackTrace(); + } + } + } + }; + animationThread.setDaemon(true); + } + + public void paint(Graphics g) { + if (g == null) { + return; + } + + g.setColor(Color.white); + g.fillRect(0, 0, 640, 480); + + int y = 100; + int x = 100; + if (joystick != null) { + joystick.poll(); + + g.setColor(Color.blue); + g.drawString("Buttoncount: " + joystick.buttonCount, x, y); + y += 20; + g.drawString("-----------------------------------------------", x, y); + y += 20; + g.drawString("x : " + joystick.x, x, y); + y += 20; + g.drawString("y : " + joystick.y, x, y); + y += 20; + if(joystick.hasZAxis) { + g.drawString("z : " + joystick.z, x, y); + y += 20; + } + if(joystick.hasPOV) { + g.drawString("pov: " + joystick.pov, x, y); + y += 20; + } + + //paint buttons + g.drawString("btn: ", x, y); + x += g.getFontMetrics().stringWidth("btn: "); + for(int i=0; i