Hi all, thanks in advance for the help. I have placed an "X" on the first JButton and what I need it to do is this...
Once the user has clicked the button with the "X" it needs to disappear and reappear on a different button. This process needs to repeat 10 times so some sort of loop is being required I believe. Not quite sure on how to do this. Here is my code so far...I know I did it the long way without using an array or list :/
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class JClickTheX extends JFrame implements ActionListener
{
JButton b1 = new JButton();
JButton b2 = new JButton();
JButton b3 = new JButton();
JButton b4 = new JButton();
JButton b5 = new JButton();
JButton b6 = new JButton();
JButton b7 = new JButton();
JButton b8 = new JButton();
JButton b9 = new JButton();
JButton b10 = new JButton();
JButton b11 = new JButton();
JButton b12 = new JButton();
JButton b13 = new JButton();
JButton b14 = new JButton();
JButton b15 = new JButton();
JButton b16 = new JButton();
JButton b17 = new JButton();
JButton b18 = new JButton();
JButton b19 = new JButton();
JButton b20 = new JButton();
JButton b21 = new JButton();
JButton b22 = new JButton();
JButton b23 = new JButton();
JButton b24 = new JButton();
JButton b25 = new JButton();
JButton b26 = new JButton();
JButton b27 = new JButton();
JButton b28 = new JButton();
JButton b29 = new JButton();
JButton b30 = new JButton();
JButton b31 = new JButton();
JButton b32 = new JButton();
JButton b33 = new JButton();
JButton b34 = new JButton();
JButton b35 = new JButton();
JButton b36 = new JButton();
JButton b37 = new JButton();
JButton b38 = new JButton();
JButton b39 = new JButton();
JButton b40 = new JButton();
JButton b41 = new JButton();
JButton b42 = new JButton();
JButton b43 = new JButton();
JButton b44 = new JButton();
JButton b45 = new JButton();
JButton b46 = new JButton();
JButton b47 = new JButton();
JButton b48 = new JButton();
public JClickTheX()
{
setTitle("Click the X!");
setSize(750, 750);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new GridLayout(8, 6));
add(buttonPane);
buttonPane.add(b1);
buttonPane.add(b2);
buttonPane.add(b3);
buttonPane.add(b4);
buttonPane.add(b5);
buttonPane.add(b6);
buttonPane.add(b7);
buttonPane.add(b8);
buttonPane.add(b9);
buttonPane.add(b10);
buttonPane.add(b11);
buttonPane.add(b12);
buttonPane.add(b13);
buttonPane.add(b14);
buttonPane.add(b15);
buttonPane.add(b16);
buttonPane.add(b17);
buttonPane.add(b18);
buttonPane.add(b19);
buttonPane.add(b20);
buttonPane.add(b21);
buttonPane.add(b22);
buttonPane.add(b23);
buttonPane.add(b24);
buttonPane.add(b25);
buttonPane.add(b26);
buttonPane.add(b27);
buttonPane.add(b28);
buttonPane.add(b29);
buttonPane.add(b30);
buttonPane.add(b31);
buttonPane.add(b32);
buttonPane.add(b33);
buttonPane.add(b34);
buttonPane.add(b35);
buttonPane.add(b36);
buttonPane.add(b37);
buttonPane.add(b38);
buttonPane.add(b39);
buttonPane.add(b40);
buttonPane.add(b41);
buttonPane.add(b42);
buttonPane.add(b43);
buttonPane.add(b44);
buttonPane.add(b45);
buttonPane.add(b46);
buttonPane.add(b47);
buttonPane.add(b48);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b10.addActionListener(this);
b11.addActionListener(this);
b12.addActionListener(this);
b13.addActionListener(this);
b14.addActionListener(this);
b15.addActionListener(this);
b16.addActionListener(this);
b17.addActionListener(this);
b18.addActionListener(this);
b19.addActionListener(this);
b20.addActionListener(this);
b21.addActionListener(this);
b22.addActionListener(this);
b23.addActionListener(this);
b24.addActionListener(this);
b25.addActionListener(this);
b26.addActionListener(this);
b27.addActionListener(this);
b28.addActionListener(this);
b29.addActionListener(this);
b30.addActionListener(this);
b31.addActionListener(this);
b32.addActionListener(this);
b33.addActionListener(this);
b34.addActionListener(this);
b35.addActionListener(this);
b36.addActionListener(this);
b37.addActionListener(this);
b38.addActionListener(this);
b39.addActionListener(this);
b40.addActionListener(this);
b41.addActionListener(this);
b42.addActionListener(this);
b43.addActionListener(this);
b44.addActionListener(this);
b45.addActionListener(this);
b46.addActionListener(this);
b47.addActionListener(this);
b48.addActionListener(this);
b1.setText("X");
}
public void actionPerformed(ActionEvent e)
{
}
public static void main(String[] args)
{
JClickTheX mouse = new JClickTheX();
mouse.setVisible(true);
}
}