Thursday, 27 March 2008

Two examples of matlab implement java

Example 1: print a line
===================
import java.lang.System;
System.out.println('zhengxin');

% in Java environment, java.lang.* is automatically imported, so no need to import it when programming with java. But in Matlab, this package/classes must be imported manually.


Example 2: show a dialog
===================
import java.awt.*;
import javax.swing.*;

title = 'Frame Title';
frame = JFrame(title);
comp = JTextArea();
frame.getContentPane.add(comp, BorderLayout.CENTER);
width = 300;
height = 300;
frame.setSize(width, height);
frame.show();

No comments:

My photo
London, United Kingdom
twitter.com/zhengxin

Facebook & Twitter