Java.use(better, Jython=Swing) #Color Chart -- JComboBox
‖記事一覧‖
Java.use(better, Jython=Swing)
Color Chart -- JComboBox 《Jython2.5.0》
《著》小粒ちゃん+∞《監修》小泉ひよ子とタマゴ倶楽部
第1版♪2003/05/23 ● 第2版♪2009/04/03
事例:
次のコードを実行すると、ウィンドウが現われます。
$ jython -i chart_swing.py
- タブ[JComboBox]を選択します。
- 〔右側〕項目(リスト)を選択すると、
- 〔左側〕パネルの色が変化します。
コードの解説
## ---------------------------------------- JComboBox from javax.swing import DefaultComboBoxModel from javax.swing import JComboBox from java.awt.event import ActionListener class Tab_JComboBox(TabbedComponent, ActionListener): species = colors selector = "selectedItem" def __init__(self, command): self.model = self.create_Model() self.container = self.create(command) self.command = command def create_Model(self): model = DefaultComboBoxModel() items = [e for e in dir(colors) if not e.startswith("_")] for e in items: model.addElement(e) return model def create(self, command): container = JPanel() comp = JComboBox( model = self.model, ) comp.addActionListener(self) container.add(comp) return container def actionPerformed(self, event): name = getattr(event.source, self.selector) self.command.client.update(name=name)
- リスナーとして、インスタンスオブジェクト self を指定します。
》こちらに移動中です《
↑TOP