Swing:JButton

【例題1】JButton を選択したときに、その日時を表示したい。


JButton を含むウィンドウが現われます。ボタンを選択すると、そのときの日時が出力されます。これを実現したのが、次のコードです。

def ex_JButton_actionPerformed1():
from java.util import Date
def now(e): print Date()
view = JButton(
text="What time is it now?",
icon=ImageIcon("icons/clock-icon.gif"),
actionPerformed=now,
)
frame = JFrame(
defaultCloseOperation=JFrame.EXIT_ON_CLOSE,
title="JButton",
size=(150, 80),
)
frame.add(view)
frame.show()