Java.use(better, Jython=Swing) #Color Chart -- JCheckBox

記事一覧入門編基礎編応用編中級編

Python.use(better) #Jython2.5.0
Color Chart -- JCheckBox

《著》小粒ちゃん+∞《監修》小泉ひよ子とタマゴ倶楽部
第0版♪2001/03/02 ● 第1版♪2003/05/25 ● 第2版♪2004/06/01 ● 第3版♪2009/02/28

概要

部品 JCheckBox の基本的な機能を紹介します。

Swing によるオブジェクト指向プログラミングへの扉を開きます。
Java/Swing で作成した例題を、Jython で再構成しました。

事例:

次のコードを実行すると、ウィンドウが現われます。

$ jython -i chart_swing.py 

  • タブ[JCheckBox]を選択します。

  • 〔右側〕項目(ボタン)を選択すると、
  • 〔左側〕パネルの色が変化します。

コードの解説

## ---------------------------------------- JCheckBox
from javax.swing import JCheckBox

class Tab_JCheckBox(TabbedComponent):
    species = Color
    selector = None
    items = "red", "green", "blue",
    seq = "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white",

    def __init__(self, command):
        self.container = self.create(command)
        self.command = command
        
    def create(self, command):
        container = JPanel()
        for i,e in enumerate(self.items):
            comp = JCheckBox(
                text = e,
                actionCommand = str(2**i),
                actionPerformed = self,
                )
            container.add(comp)
        return container

    def __call__(self, event):
        index = sum(int(e.actionCommand)
            for e in self.container.components if e.selected)
        self.command.client.update(name=self.seq[index])

》こちらに移動中です《
TOP


関連記事

  • INDEX《Swing》JCheckBox
  • INDEX《Swing》actionPerformed

Last updated♪2009/10/17