Monday, 26 January 2009

Jython and Matlab do jobs for java

Java codes:
======================
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MyExample
implements ActionListener {

public void actionPerformed(ActionEvent e) {
System.out.println("Ouch!");
}

public static void main(String[] args) {
JFrame frame = new JFrame("My Frame");
frame.setSize(300,300);
JButton button = new JButton("Push Me!");
ActionListener listener = new MyExample();
button.addActionListener(listener);
frame.getContentPane().add(button);
frame.setVisible(true);
}
}


Jython:
======================
import javax.swing as swing

def printMessage(event):
print "Ouch!"

frame=swing.JFrame("my frame")
frame.setSize(300,300)
button=swing.JButton("Push Me!")
button.actionPerformed=printMessage
frame.getContentPane().add(button)
frame.setVisible(True) #frame.visible=1


Matlab:
=======================
import javax.*;

frame = swing.JFrame('my frame');
frame.setSize(300,300);
button = swing.JButton('Push Me!');

set(button,'ActionPerformedCallback',@printMessage);

frame.getContentPane.add(button);
frame.setVisible(true);

%code for sub function:
function printMessage(handle,event)
disp('ouch');
end

No comments:

My photo
London, United Kingdom
twitter.com/zhengxin

Facebook & Twitter