2011-03-08 85 views
2

嘿,我一直在玩弄Jython的一点,我写了下面的测试程序:的Jython构建无输出

from javax.swing import * 
from java.awt import * 
from java.awt.event import ActionListener 

class JythonTest(JFrame): 
    _windowTitle = "" 

    def __init__(self): 
     self.initVars() 
     self.initLookAndFeel() 
     self.initComponents() 
     self.initGui() 

    def initVars(self): 
     self._windowTitle = "Jython Test" 
     JFrame.__init__(self, self._windowTitle) 

    def initLookAndFeel(self): 
     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()) 

    def initComponents(self): 
     label = JLabel("Hello World!", JLabel.CENTER) 
     label.setFont(Font("Arial", Font.BOLD, 30)) 

     tabs = JTabbedPane() 
     tabs.addTab("Test", label) 
     tabs.addTab("Calculator", self.CalculatorPane()) 
     self.add(tabs) 

    def initGui(self): 
     self.setSize(400,200) 
     self.setDefaultCloseOperation(self.EXIT_ON_CLOSE) 
     self.setVisible(1) 

    class CalculatorPane(JPanel, ActionListener): 
     _txt1 = 0 
     _txt2 = 0 
     _box = 0 

     def __init__(self): 
      self.initVars() 
      self.initComponents() 

     def initVars(self): 
      pass 

     def initComponents(self): 
      self._txt1 = JTextField(5) 
      self._box = JComboBox(["+", "-", "*", "/"]) 
      self._txt2 = JTextField(5) 
      btn = JButton("Go") 

      btn.addActionListener(self) 

      self.add(self._txt1) 
      self.add(self._box) 
      self.add(self._txt2) 
      self.add(btn) 

     def actionPerformed(self, ev): 
      val1 = self._txt1.getText() 
      val2 = self._txt2.getText() 
      operation = self._box.getSelectedItem() 

      val1 = int(val1) 
      val2 = int(val2) 

      if operation == "+": 
       answer = val1+val2 
      elif operation == "-": 
       answer = val1-val2 
      elif operation == "*": 
       answer = val1*val2 
      elif operation == "/": 
       answer = val1/val2 

      JOptionPane.showMessageDialog(self, "The answer is: " + str(answer)) 

if __name__ == "__main__": 
    win = JythonTest() 

这里是我的系统信息:

Operating System: Ubuntun 10.10 
Netbeans Version: 6.9 

我的问题是我无法编译上述代码。它运行得很好,当我点击运行按钮,但是,当我打造或清洁&构建,然后我没有得到任何结果。构建过程在右下角运行约半秒钟,然后结束。输出框打开,但它完全是空的,即使在处理结束后。当我看着我的项目文件夹时,没有任何变化。只有两个文件夹,nbproject和src。可能应该有一个dist文件夹里面有一个jar。下面是在文件结构:

[email protected]: ~/NetBeansProjects/pythontest$ ls 
nbproject src 
[email protected]: ~/NetBeansProjects/pythontest$ ls nbproject 
private project.properties project.xml 
[email protected]: ~/NetBeansProjects/pythontest$ ls nbproject/private 
private.xml 
[email protected]: ~/NetBeansProjects/pythontest$ ls src 
pythontest.py setup.py 

我所做的设置是安装在Debian软件包的NetBeans(前一段),并设置巨蟒/ Jython的通过了NetBeans插件蟒蛇。任何想法有什么不对?

回答

2

简而言之,它并不是那样的工作;我不知道任何IDE或工具支持打包jython程序。

通常我做什么,只是做一个shell脚本,说:

java -cp "the/classpath/;" org.python.util.jython myscript.py 

我发现是运行Jython程序最万无一失的方法,并救了我从没有-工作令人头痛.jar文件在开发过程中。


这就是说,有很多独立的.jar文件包装Jython的程序方法,如果这就是你想要的。

我找到的最佳资源是Jython FAQ中的Distributing Jython Scripts页面,其中介绍了几种用于分发jython脚本的不同技术。

我通常只在使用“发布”程序时使用那里描述的方法。