[Previous]
| [Table of Contents]
7 Jython
Jython is a
scripting language based on the
Python
specification. The advantages of Jython are:
- No need to compile
code
- More descriptive than
Java
- Java classes are
accessible through Jython
The interface shown in
figure 1 below was created with Jython. Clicking
the "Start" and "Stop" buttons interact with JavaHMI's
MockDigitalOutput.
Figure 1. Jython GUI screen shot.
The source
for the interface shown in figure 1 is listed below in
Code Example 1.
Code Example 7.1.
TestControl.jy |
from java import awt
from javax import swing
from net.sourceforge import javahmi
do = javahmi.mockup.MockDigitalOutput()
do.name = "Motor"
class MyListener(awt.event.ActionListener):
def actionPerformed(self,event):
if event.getActionCommand() == "Start":
print "Starting!"
do.write(1)
elif event.getActionCommand() == "Stop":
print "Stopping!"
do.write(0)
frame = swing.JFrame("Subclassing Example")
container = frame.getContentPane()
container.setLayout(awt.FlowLayout())
button1 = swing.JButton("Start")
button1.addActionListener(MyListener())
container.add(button1)
button2 = swing.JButton("Stop")
button2.addActionListener(MyListener())
container.add(button2)
frame.setSize(150,120)
frame.pack()
frame.setVisible(1)
|
[Previous]
| [Table of Contents]
Please send
content suggestions to
todd.brunia@xilution.com.
|