boolean results -> Exceptions

This commit is contained in:
Elias Naur 2003-09-30 10:52:05 +00:00
parent 42e8f13cbe
commit dd72b04c90
9 changed files with 77 additions and 79 deletions

View file

@ -171,9 +171,7 @@ public class Controller {
return;
}
if (!nCreate()) {
throw new Exception("The controller could not be created.");
}
nCreate();
created = true;
}
@ -248,10 +246,8 @@ public class Controller {
/**
* Native method to create the controller
*
* @return true if the controller was created
*/
private static native boolean nCreate();
private static native void nCreate() throws Exception;
/**
* Native method the destroy the controller

View file

@ -286,17 +286,14 @@ public class Keyboard {
initialize();
if (created)
return;
if (!nCreate())
throw new Exception("The keyboard could not be created.");
nCreate();
created = true;
}
/**
* Native method to create the keyboard
*
* @return true if the keyboard was created
*/
private static native boolean nCreate();
private static native void nCreate() throws Exception;
/**
* @return true if the keyboard has been created
@ -359,27 +356,26 @@ public class Keyboard {
/**
* Enable keyboard translation. Must be called after the keyboard is created,
* and keyboard buffering must be enabled.
* @return false if translation cannot be enabled; true if it can
*/
public static boolean enableTranslation() {
public static void enableTranslation() throws Exception {
assert created : "The keyboard has not been created.";
assert readBuffer != null : "Keyboard buffering has not been enabled.";
translationEnabled = nEnableTranslation();
return translationEnabled;
nEnableTranslation();
translationEnabled = true;
}
/**
* Native method to enable the translation buffer
*/
private static native boolean nEnableTranslation();
private static native void nEnableTranslation() throws Exception;
/**
* Enable keyboard buffering. Must be called after the keyboard is created.
* @return the size of the keyboard buffer in events, or 0 if no buffering
* can be enabled for any reason
*/
public static int enableBuffer() {
public static int enableBuffer() throws Exception {
assert created : "The keyboard has not been created.";
int buf_len = nEnableBuffer();
if (readBuffer != null)
@ -392,7 +388,7 @@ public class Keyboard {
* @return the size of the buffer allocated, in events (1 event is 2 bytes),
* or 0 if no buffer can be allocated
*/
private static native int nEnableBuffer();
private static native int nEnableBuffer() throws Exception;
/**
* Checks to see if a key is down.

View file

@ -146,7 +146,7 @@ public class Mouse {
}
/** Native method to set the native cursor */
private static native void nSetNativeCursor(int handle);
private static native void nSetNativeCursor(int handle) throws Exception;
/**
* Gets the minimum size of a native cursor. Can only be called if
@ -210,9 +210,7 @@ public class Mouse {
if (created) {
return;
}
if (!nCreate()) {
throw new Exception("The mouse could not be created.");
}
nCreate();
created = true;
currentCursor = null;
@ -225,7 +223,7 @@ public class Mouse {
*
* @return true if the mouse was created
*/
private static native boolean nCreate();
private static native void nCreate();
/**
* @return true if the mouse has been created

View file

@ -107,6 +107,8 @@ public class KeyboardTest {
private void createKeyboard() {
try {
Keyboard.create();
Keyboard.enableBuffer();
Keyboard.enableTranslation();
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
@ -114,8 +116,6 @@ public class KeyboardTest {
}
private void wiggleKeyboard() {
Keyboard.enableBuffer();
Keyboard.enableTranslation();
while (!Window.isCloseRequested()) {
Window.update();