0

私はそれを解決しようとして愚かな時間を探しましたが、何らかの理由でうまくいきません. 私はJavaにかなり慣れていないので、私のjframeは少し混乱していますが、それは問題ではないようです。何をしてもボタン1から応答が得られません。何が間違っていますか? また、クラスには実装されていないものがいくつかありますが、これを乗り越えることができないように見えるので、まだ追加する機会がなかったので無視してください。

public class First{
        private static JButton b1;
        private static JButton b2;
        private static JButton b3;
        private static int GetColor;
        private static Container content;

        public static void main(String[] args){
                JFrame f = new JFrame("test");
                f.setSize(300,100);
                f.setLocationRelativeTo(null);
                Container content = f.getContentPane();
                content.setLayout(new FlowLayout());
                int GetColor = 1;
                if(GetColor==1){
                content.setBackground(Color.blue);
                }else{
                GetColor = 1;
                content.setBackground(Color.blue);
                }
                JButton b1 = new JButton("Blue");
                content.add(b1);
                JButton b2 = new JButton("Red");
                content.add(b2);
                JButton b3 = new JButton("Green");
                content.add(b3);                
                f.setVisible(true);

                Handler h = new Handler();
                b1.addActionListener(h);
                b2.addActionListener(h);
                b3.addActionListener(h);
        }                       
        private static class Handler implements ActionListener{
                public void actionPerformed(ActionEvent a) {
                        Object src = a.getSource();
                        ProcessSrc(src);
                        }
                }
                private static void ProcessSrc(Object src){

                        if(src.equals(b1)){
                                System.out.println("f");

                        }


        }
}

必要なものはすべてそこにあるはずです。

4

2 に答える 2