|
|
OVERVIEW |
|
|
|
|
EXAMPLES |
|
|
|
|
COMPONENTS |
|
|
|
|
RELATED |
|
|
|
|
Jeval - Java Evaluation for SICStus
Jeval is a package that enable SICStus developers to make full use of
the strengths of Java (GUI, networking, etc). Using jeval it is possible and
easy to develop the core functionality of the application in prolog
and the user interface in Java.
Different Modes - Single/Multi user
The jeval package allow the user to decide if the prolog or the Java code should
be the server. When prolog acts as server jeval can handle multiple users
(connections) to the application. When Java is the server only one user/GUI
can be handled.
Scripted Java Code
Jeval uses the BeanShell scripting package to implement the execution of Java
code from prolog. The syntax of BeanShell scripted Java is close to Java and
the most obvious difference is that you do not need to declare variables.
In Java you would write String str = textField.getText() to make the
variable str contain the text of textField. In scripted Java you would write
str = textField.getText()
For more information about the syntax,
etc of BeanShell please look at http://www.beanshell.org.
Using Single User Jeval
Jeval in single user (single gui) mode is good when you have one or several
prolog processes running and you only need one GUI.
Initialization
- jeval:jeval_init. - initializes Jeval to use jasper (an automatically started Java in the SICStus)
- jeval:jeval_init(+Mode, +Import) - initializes Jeval in one of the following modes:
- jasper - use jasper for Java communication
- jasper(ClassPath) - use jasper for Java communication and with
the specified class path
- client - connect to Jeval server at default port
- client(+Port) - connect to Jeval server at specified port
- client(+Host,+Port) - connect to Jeval server at specified location
Import is a list of Java packages to import.
Executing code
- jeval:jeval(+JavaCode) - Executes the Java code in the argument
JavaCode
- jeval:jeval_result(+JavaCode, -ResultAtom) - Executes the Java code
in the argument JavaCode and binds Result to the
result of the execution. This predicate blocks until the Java
execution is complete.
single user example
Using Multi User Jeval
Multi user Jeval is an excellent choice when you have an application that is
used by multiple users and need a more interactive user interface than a
html-based web interface. In this case prolog acts as a server and users
typically connect through applets via a web-browser.
Initialization
- jeval_server:register_applet(+Context, +Module) - ...
Executing code
- jeval:jeval(+User, +JavaCode) - Executes the Java code - JavaCode - in the client associated with User
- jeval:jeval_result(+User, +ResultName, +JavaCode) - Executes the Java code - JavaCode - in the client associated with User. The result will be delivered via a callback to client_result(+ResultName, +ResultAtom, +User)
Callbacks
- client_connected(+Host, +User) - ...
- client_disconnected(+User) - ...
- client_event(+Event, +User) - ...
- client_result(+ResultName, +ResultAtom, +User) - ...
multi user example
|
|