###前提・実現したいこと
お世話になっております、Javaを勉強しているものです
以下の要件でプログラムを組んでいるのですが、手詰まりとなってしまいました
皆様のお力をお借りしたいです
要件
ボタンを一つ配置
そのボタンを1度押すたびに状態が遷移する
まる→ばつ→まる といった風に
よろしくお願いいたします
###発生している問題
まるからばつへ一度遷移するのですがそれ以降遷移することができません
###該当のソースコード
import
1import java.awt.event.ActionEvent; 2import java.awt.event.ActionListener; 3 4import javax.swing.ImageIcon; 5import javax.swing.JButton; 6import javax.swing.JFrame; 7import javax.swing.JPanel; 8import javax.swing.SwingUtilities; 9 10 11 12 13 14public class Kadai { 15 private JFrame jf = null; 16 private JButton jb = null; 17 int flag=1, i=0; 18 19 private JFrame getJFrame() 20 { 21 jf = new JFrame(); 22 jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 23 jf.setSize(240,120); 24 jf.setLocationRelativeTo(null); 25 JPanel cp = (JPanel)jf.getContentPane(); 26 27 cp.setLayout(new GridLayout()); 28 cp = (JPanel)jf.getContentPane(); 29 jf.setTitle("課題7"); 30 31 cp.add(getJButton()); 32 33 return jf; 34 } 35 36 private JButton getJButton() 37 { 38 jb = new JButton(); 39 ImageIcon icon = new ImageIcon("./maru32.png"); 40 jb.setIcon(icon); 41 jb.setText("まる"); 42 jb.addActionListener(new ActionListener1()); 43 44 45 46 47 return jb; 48 } 49 50 public class ActionListener1 implements ActionListener 51 { 52 public void actionPerformed(ActionEvent e) 53 { 54 55 if(i==1) 56 { 57 if(flag==1) 58 { 59 ImageIcon icon = new ImageIcon("./maru32.png"); 60 jb.setIcon(icon); 61 jb.setText("まる"); 62 flag=2; 63 64 } 65 i=0; 66 } 67 68 69 if(flag==2) 70 { 71 ImageIcon icon = new ImageIcon("./peke32.png"); 72 jb.setIcon(icon); 73 jb.setText("ぺけ"); 74 flag=1; 75 i++; 76 } 77 78 } 79 } 80 81 82 83 84 public static void main(String[] args) { 85 SwingUtilities.invokeLater(new Runnable() { 86 public void run() { 87 Kadai application = new Kadai(); 88 application.getJFrame().setVisible(true); 89 } 90 }); 91} 92}