Next: , Previous: , Up: Interfacing with Java   [Contents] Using pragma foreign_decl for Java

pragma foreign_decl’ declarations for Java can be used to provide any top-level Java declarations (e.g. ‘import’ declarations or auxiliary class definitions) which are needed by Java code in ‘pragma foreign_proc’ declarations in that module.

For example:

:- pragma foreign_decl("Java", "
import javax.swing.*;
import java.awt.*;

class MyApplet extends JApplet {
    public void init() {
        JLabel label = new JLabel(""Hello, world"");
:- pred hello(io.state::di, io.state::uo) is det.
:- pragma foreign_proc("Java",
	hello(_IO0::di, _IO::uo),
	MyApplet app = new MyApplet();
	// ...