Java標準低速GUI 6 AWT/Swing
at TECH
544:デフォルトの名無しさん
07/12/12 08:34:31
>>542
それだと SubPanel が汎用性の低いクズパーツになるだろ。
SubPanel がボタンを持つパネルならそのボタンのアクションリスナーを
>>534のように SubPanel に委譲してやったほうがいい。
public class SubPanel extends JPanel {
private JButton button;
public SubPanel(String buttonText) {
button = new JButton(buttonText);
this.add(button);
}
public void addButtonActionListener(ActionListener listener) {
button.addActionListener(listener);
}
}
public class MainPanel extends JPanel implements ActionListener {
public MainPanel() {
SubPanel panel = new SubPanel("メインパネルの色を変更");
panel.addButtonActionListener(this);
this.add(panel);
}
public void actionPerformed(ActionEvent e) {
this.setBackground(Color.BLACK);
}
}
次ページ続きを表示1を表示最新レス表示スレッドの検索類似スレ一覧話題のニュースおまかせリスト▼オプションを表示暇つぶし2ch
4901日前に更新/252 KB
担当:undef