Example Java Call In Using Swing.
Under some circumstances your Java programs may need to call into your Uniface application. The easiest example of this is when a Uniface form component activates a Java Swing program. Swing screens are non-modal, so when the user has finished using it, or has selected a value from it, it will be necessary to activate an operation in Uniface to pass the result back:
The Java Swing program may be executed using either the activate
or sql
proc instructions.
To call Uniface from Java you must:
The source code for the MHU class is supplied with the UD5 driver. Compile it using your JDK:
javac MHU.java
Here is the example Java Swing class: HELLOSWING
Here is our example Java
//v 1.3
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class HELLOSWING {
static JFrame frame;
public static void main(String[] args) {
HELLOSWING.EXEC();
}
public static int QUIT() {
MHU mhu = new MHU();
int res=mhu.UACTIVATE("TEST_JAVA","CLOSING_SWING","Bye");
frame.setVisible(false);
frame.dispose();
return 0;
}
public static void EXEC() {
MHU mhu = new MHU();
mhu.LOADLIBRARY("ud5");
frame = new JFrame("HelloSwing");
final JLabel label = new JLabel("Hello World");
frame.getContentPane().add(label);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
int res=HELLOSWING.QUIT();
}
});
frame.pack();
frame.setVisible(true);
}
}
This example shows how to call Java Swing using the sql
proc statement :
sql "@return-type V","ud5"
sql "@static-method enable","ud5"
sql/print "HELLOSWING.EXEC","ud5"
This example shows how to call Java Swing using the activate
proc statement :
activate "HELLOSWING".EXEC()
The ASN file contains this redirection:
[SERVICES_EXEC]
HELLOSWING $MW1:HelloSwing
The Signature definition of HelloSwing
is:
HELLOSWING
using the Signature editor on the assembly workbenchEXEC
using the pulldown menu Go To
, and the option Operations...
. The Operation name is EXEC, and the literal name is EXEC. The return value is None (void).Go To
, and the option Implementations...
.
Our example Java Swing application is started from a Uniface Form Component called TEST_JAVA
which has an operation named CLOSING_SWING
defined:
operation CLOSING_SWING
PARAMS
STRING TEST:IN
ENDPARAMS
PUTMESS "%%TEST"
swingres.dummy="Closed"
PUTMESS "This Worked"
macro "^next^field"
end
;
The form has a button painted which starts the Swing application, and a field named SWINGRES
which contains the status indicator. NOTE: the macro
in this example is to ensure the screen is correctly updated.
$Revision: 1.8 $ $Date: 2011/02/28 02:56:33 $ | [go to top] |