Ejemplo n.º 1
0
def test(panel, size=None, name='AWT Tester'):
        f = awt.Frame(name, windowClosing=lambda event: sys.exit(0))
        if hasattr(panel, 'init'):
                panel.init()

        f.add('Center', panel)
        f.pack()
        if size is not None:
                f.setSize(apply(awt.Dimension, size))   
        f.setVisible(1)
        return f
Ejemplo n.º 2
0
    def _encode(self, img, g, size, **options):
        p = Panel(img, size)

        def onWindowClose(e):
            e.getWindow().dispose()
            self.dispose()

        self.window = awt.Frame(windowClosing=onWindowClose)
        if options.has_key('title'):
            self.window.setTitle(options['title'])
        self.window.add(p)
        self.window.pack()
        self.window.setVisible(True)
Ejemplo n.º 3
0
# -*- coding: cp950 -*-

# 載入awt
from java import awt

# 建立子類別(SubClass)
class SpamListener(awt.event.ActionListener):
   # 事件函數
   def actionPerformed(self,event):
      # 如果按下按鈕就執行print
      if event.getActionCommand() == "button":
         print '你按下按鈕'

# 建立instance
f = awt.Frame("ch1603", size=(250,150))

# 建立一個awt按鈕
b = awt.Button("button")

# 監聽事件
b.addActionListener(SpamListener())

# 將按鈕加入
f.add(b, "Center")

# 顯示Frame
f.setVisible(1)
Ejemplo n.º 4
0
    if t == '':
        return 0
    else:
        return java.lang.Integer.parseInt(t)


def doMath(e):
    n1 = getField(f1)
    n2 = getField(f2)
    sum.setText(repr(n1 + n2))
    diff.setText(repr(n1 - n2))
    prod.setText(repr(n1 * n2))
    quo.setText(repr(n1 / n2))


f = awt.Frame('BSH Calculator (jpython)', windowClosing=exit)

f1 = awt.TextField(20, actionPerformed=doMath)
f2 = awt.TextField(20, textValueChanged=doMath)

p = awt.Panel()
p.setLayout(awt.GridLayout(2, 2))
p.add(awt.Label('Enter Operand'))
p.add(f1)
p.add(awt.Label('Enter Operand'))
p.add(f2)

f.add('North', p)

f.add("Center", awt.Label('Results:'))
Ejemplo n.º 5
0
"""\
This is a very simple example of using Java's AWT from JPython.

Many more examples can be found in Demo/applet.  While all of those
demos are designed as applets, they can also be run as applications
and they all show how to use different parts of the AWT.
"""

import java
from java import awt

def exit(e): java.lang.System.exit(0)

frame = awt.Frame('AWT Example', visible=1)
button = awt.Button('Close Me!', actionPerformed=exit)
frame.add(button, 'Center')
frame.pack()