毎度、お世話になります。 Radioボタンの割込み処理について、お教えください。 コード中の『se[0].addChangeListener(this)』にて、Radioボタンをクリックしますと 割込みが発生し、正常に動作します。 Q1)このthisを他のワードに変更できないでしょうか? 理由:他のプログラムで、thisと記述した瞬間に、エラーcheckに引っかかります。 nullの場合は、OKですが、割込みが発生しません。 以上、宜しくお願いします。 ============== import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.FlowLayout; import java.awt.GridLayout; import javax.swing.ButtonGroup; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; class JRadioButtonTestB extends JFrame implements ChangeListener { JRadioButton se[]=new JRadioButton[2]; JLabel lb1, lb2; JRadioButtonTestB() { lb1 = new JLabel(); lb2 = new JLabel(); Container cont = getContentPane(); cont.setLayout(new BorderLayout()); //性別================================ se[0] = new JRadioButton("男性"); se[1] = new JRadioButton("女性"); se[0].addChangeListener(null); //<----問題点 se[1].addChangeListener(null); // JPanel pSex = new JPanel(); pSex.setBackground(Color.cyan); pSex.setLayout(new FlowLayout()); pSex.add(new JLabel("性別")); pSex.add(se[0]); pSex.add(se[1]); ButtonGroup bgsex = new ButtonGroup(); bgsex.add(se[0]); bgsex.add(se[1]); JPanel kaku = new JPanel(); kaku.setBackground(Color.green); kaku.setLayout(new GridLayout(3,2)); kaku.add(new JLabel("確認")); kaku.add(new JLabel(" ")); kaku.add(new JLabel("性別")); kaku.add(lb1); cont.add("North",pSex); cont.add("South",kaku); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("JRadioButtonTestB"); setSize(320, 200); setVisible(true); } public void stateChanged(ChangeEvent e) { if(se[0].isSelected()) lb1.setText("男性"); if(se[1].isSelected()) lb1.setText("女性"); } public static void main(String[] args) { new JRadioButtonTestB(); } } //===
↧