例題で学ぶ Jython/Swing フレームワーク #2: リファクタリング
《前の記事|記事一覧|次の記事》
Java.use(better, Jython=Swing);
例題で学ぶ Jython/Swing フレームワーク Episode#02
事例:モジュールを起動する
$ jython2.5.0 -i swing_tips.py
0: step00 -- from javax.swing import JFrame
1: step01 -- from javax.swing import JButton
2: step02 -- class TIPS()
3: step03 -- from javax.swing import JPanel
4: step04 -- def command(self, *args)
5: step05 -- from random import randint
6: step06 -- from javax.swing import JList
7: step07 -- from javax.swing import DefaultListModel
8: step08 -- from javax.swing import JScrollPane
9: step09 -- class Command(object)
10: step10 -- def addElement(self, obj)
11: step11 -- from java.awt import GridLayout
12: step12 -- from javax.swing import JLabel
>>> do(2)
次のようなウィンドウが現れます。
- ウィンドウ内を埋め尽くすように、ボタンが配置されます。
事例:コードの解説
def step02():
"""class TIPS()"""
class TIPS():
def __init__(self, master): #1:
comp = JButton()
master.add(comp)
## ----------------------------------------
frame = JFrame(
title = "swing: step02",
size = (180,100),
)
TIPS(master=frame) #2:
frame.visible = True
》こちらに移動中です《