Next: Using pragma foreign_code for Java, Previous: Using pragma foreign_export for Java, Up: Interfacing with Java [Contents]
‘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""); label.setHorizontalAlignment(JLabel.CENTER); getContentPane().add(label); } } "). :- pred hello(io.state::di, io.state::uo) is det. :- pragma foreign_proc("Java", hello(_IO0::di, _IO::uo), [will_not_call_mercury], " MyApplet app = new MyApplet(); // … ").