The way it is already works, you just have to fix the actionPerformed method, which has a wrong signature and which does not declare the self parameter.
Up vote 1 down vote favorite share g+ share fb share tw.
I have a Java program which I'd like to call from a Jython program. I'd like to be able to have the two interface with one another and had hoped to call the Java program from Jython with an action listener as a parameter, but so far I have had no luck. Jython code: import sys sys.path.
Append("sgJython. Jar") from java.awt. Event import ActionListener from java.awt.
Event import ActionEvent from sg. Gui import MainGui class MyListener(ActionListener): def ActionPerformed(e): print("gotit") ml = MyListener() MainGui(ml) Java code: package sg; import java.awt.event. ActionListener; import java.awt.event.
ActionEvent; class MainGui { public MainGui(ActionListener listener) { top = new JFrame(); top. SetBounds(300, 300, 600, 300); JButton doneButton = new JButton("Done"); doneButton. AddActionListener(listener); top.
Add(doneButton) } } Is there some other way of doing this? If not, is there a better way to go about integrating Java and Python into a single application, or is that not a good thing to do? Java jython actionlistener link|improve this question asked 2 hours agoI.
Ped82.
The way it is already works, you just have to fix the actionPerformed method, which has a wrong signature and which does not declare the self parameter. Class MyListener(ActionListener): def actionPerformed(self, e): print("gotit") In your Java code, you missed a couple of semicolons and since you are not displaying the frame it will not be visible unless you explicitly ask it from your Jython code. So I changed it a bit for testing purposes: public class MainGui { private JFrame top; public MainGui(ActionListener listener) { top = new JFrame(); top.
SetBounds(300, 300, 600, 300); JButton doneButton = new JButton("Done"); doneButton. AddActionListener(listener); top. Add(doneButton); top.pack(); top.
SetVisible(true); } } I did the Java code in a Java Project in Eclipse and the Python code in PyDev project in Eclipse, then I ran the Python script and it worked like a charm.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.