Python 弾丸ツアー/Java: JavaBeans 準拠 ... step 3: ラベルを利用する
Python.use(better); Python 弾丸ツアー /Java: JFC/Swing 編
>>> JavaBeans 準拠
step 3: ラベルを利用する
《Python3.1|Jython2.5|IronPython2.6》
《著》小粒ちゃん@湘南組《監修》小泉ひよ子とタマゴ倶楽部
第0版♪2001/03/02 ● 第1版♪2003/05/23 ● 第4版♪2010/03/08
step 3: ラベルを利用する
《課題》日時を確認するウィンドウを表示したい。
《テストケース》 ̄次のコマンドを実行すると、ウィンドウが現われます。ウィンドウを閉じると、アプリケーションが終了します。
$ jython -i swingTimer2.py
■ コードの解説
def tips(): frame = JFrame( title = "Timer", size = (260,100), defaultCloseOperation = JFrame.EXIT_ON_CLOSE, ) TIPS(master = frame) frame.visible = True class TIPS(): def __init__(self, master, *args, **keys): textPane = self._textPane( minimumSize = (150,100), ) controlPane = self._controlPane( minimumSize = (70,100), actionPerformed = self.actionPerformed, ) self.splitPane = self._splitPane( leftComponent = textPane, rightComponent = controlPane, ) master.contentPane = self.splitPane def _textPane(self, **keys): comp = JLabel(**keys) self.label = comp return comp def _controlPane(self, **keys): comp = JButton( text = "Now", **keys ) return comp def _splitPane(self, **keys): pane = JSplitPane( orientation = JSplitPane.HORIZONTAL_SPLIT, dividerLocation = 180, **keys ) return pane ## ---------------------------------------- def actionPerformed(self, e): # ActionListener self.label.text = "%s"%ctime()
↑TOP
》作業中です《