/* This is called when the window needs to be repainted for some reason. A return code of JNI_TRUE means that things worked out; otherwise something went wrong. */ int handOffWindowExposed(JNIEnv *env, jobject widget) { jobject paintEvent; paintEvent = newPaintEvent(env, widget, "PAINT", 0, 0, 0, 0); return handOff(env, widget, paintEvent); }
/* This is called when the window was opened for the very first time. We create a window event for it and then call the widget's handleEvent method with a WindowEvent. A return code of JNI_TRUE means things worked out; otherwise something went wrong. */ int handOffWindowActivated(JNIEnv *env, jobject widget) { jobject windowActivatedEvent; windowActivatedEvent = newWindowEvent(env, widget, "WINDOW_ACTIVATED"); if (windowActivatedEvent == NULL) return JNI_FALSE; return handOff(env, widget, windowActivatedEvent); }
/* This is called when we want to pass on a mouse down event. We return JNI_FALSE if something went wrong and JNI_TRUE if everything worked out ok. */ int handOffMouseDown(JNIEnv *env, jobject widget, int x, int y) { jobject mouseEvent; /* The event for this mouse down. */ mouseEvent = newMouseEvent(env, widget, "MOUSE_PRESSED", 0, 0, x, y, 0, JNI_FALSE); if (mouseEvent == NULL) { return JNI_FALSE; } return handOff(env, widget, mouseEvent); }
/* This handles resizing the window. We set the widget's height and width to the supplied values with setSize(), and then call handOffEvent. We return JNI_FALSE if things went badly and JNI_TRUE if all is well.*/ int handOffWindowResized(JNIEnv *env, jobject widget, int width, int height) { jclass widgetClass; /* The class of our widget jobject. */ jmethodID setSizeMethodID; /* The setSize(int width, int height) method. */ jobject componentEvent; widgetClass = (*env)->GetObjectClass(env, widget); if (widgetClass == NULL) return JNI_FALSE; setSizeMethodID = (*env)->GetMethodID(env, widgetClass, "setSize", "(II)V"); if (setSizeMethodID == 0) return JNI_FALSE; (*env)->CallObjectMethod(env, widget, setSizeMethodID, width, height); componentEvent = newComponentEvent(env, widget, "COMPONENT_RESIZED"); return handOff(env, widget, componentEvent); }
/* This is used by other methods that accept key events. We set the event's keycode to the supplied value and then invoke the widget's handleEvent. */ static int handOffKeyEvent(JNIEnv *env, jobject widget, int keyCode, const char *keyEventType) { jobject keyEvent; long modifiers; jclass eventClass; eventClass = getClass(env, "java/awt/event/InputEvent", "Unable to get java.awt.event.InputEvent class"); modifiers = GetModifiers(env, eventClass, 0); keyEvent = newKeyEvent(env, widget, keyEventType, /* when */ 0, modifiers, keyCode); if (keyEvent == NULL) { return JNI_FALSE; } return handOff(env, widget, keyEvent); }
void cexit() { printf(ANSI_COLOR_BLUE"Saliendo!" ANSI_COLOR_RESET "\n"); clfree(); handOff(0); exit(0); }