# KX SDK for Java - Example Programs

## Introduction

The example project was created with Oracle Java 8 and eclipse IDE. It may or may not work with newer Java versions. Project files for eclipse are included. Other Java IDEs will also work, but the users must create projects for these environments themselves.

By opening the project in a Java IDE like eclipse or IntelliJ IDEA, the example code can be studied and the Package Explorer can be used to study the content of the Java classes, along with their documentation.

In case the example project starts up successfully one can try to open a connection to a KX KVM switch using the Connection panel. Besides of IP address, TCP port and credentials also a KVM port needs to be identified in the element Port ID. This can be either:

- The "Unique Port ID" of the KVM port. This port ID is an arbitrary, unique identifier for a particular port.
- The port number. This is the number of the port as written to the back side panel of the KX (starting with 1).

## Content

The example app contains of the following files:

- example/.project the project file for eclipse IDE
- example/.classpath the classpath file for eclipse IDE
- example/com/raritan/kvm/example/KvmExample.java the Java class of the GUI based example program
- example/com/raritan/kvm/example/InMemoryExample.java the Java class of the in-memory based example program

### The GUI based example program

The GUI based example program (KvmExample.java) demonstrates the use of the SDK within a Java/Swing based GUI. The remote console of the target computer is embedded into the GUI of the example.

The example's main class shows the following:

- The void connect() method shows how to load an instance of RCCore by calling any of the RCCoreFactory.loadGraphicalRCCore() method. The KVM control is put into the main form GUI.
  Then, the event listeners are attached to the RCCore (currently a ConnectionEventListener only).
  The last part is then connecting the RCCore to the KX and the target server.
- The method void disconnect() show how close a KVM session.
- The method void placeRcComponent() show how to set scaling modes (scaled, unscaled with scroll bars).
- The method void sendHelloWorld() sends some keyboard commands to the target server.
- The method void sendMouseMove() sends some mouse commands to the target server, including a simulated double click.
- The rcEventListeners field shows how to implement event listeners and attach them to RCCore.

### The In-Memory example program

The In-Memory example program (InMemoryExample.jave) shows how to use RCCore without embedding GUI components. Instead, all the video decoding is done im memory and users can pull snapshot images from the RCCore object.

The example's main class shows the following:

- The void connect() and void disconnect() methods are the same as in the GUI based example.
- The static void configureEventDispatcher() method and the exampleEventDispatcher class show how to create and attach an event dispatcher. In the example, all events are dispatched via the Java Swing event dispatch thread. This is useful because the example uses a Swing based GUI.
  This is the default behavior of RCCore, so in this case, a special event dispatcher is not necessary. However, it shows how to create one for other purposes, e.g. the user may create an event dispatcher based on a self created thread queue.
- The rcEventListeners field shows how to implement event listeners and attach them to RCCore.
  Of special interest is the void videoDataUpdated(Rectangle rect) method of this listener. It is called every time the RCCore has received and decoded a video frame from the KX device. In the method code, it is shown how to grab a video frame from RCCore using the BufferedImage getSnapshot() method. Users of the SDK can then further process the image. In the example, it is written to a file.