Hey, i'm making a tic tac toe game and having some problems when the user clicks on a button. Theres no compile error just nothing happens and debugge mode is not really helpful.
I also tried making the buttons into an array but got some error, so just ditched that idea.
Right now, all I wanted it to do is when I click on a button, it changes to the image on an X but nothing happens.
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class tic extends JFrame { private JButton a = new JButton(); private JButton b = new JButton(); private JButton c = new JButton(); private JButton d = new JButton(); private JButton e = new JButton(); private JButton f = new JButton(); private JButton g = new JButton(); private JButton h = new JButton(); private JButton i = new JButton(); private click slick = new click(); public tic(){ JPanel p1 = new JPanel(); p1.setLayout(new GridLayout(3,3)); p1.add(a); p1.add(b); p1.add(c); p1.add(d); p1.add(e); p1.add(f); p1.add(g); p1.add(h); p1.add(i); JPanel p2 = new JPanel(new BorderLayout()); p2.add(new JTextField("test"),BorderLayout.SOUTH); p2.add(p1,BorderLayout.CENTER); add(p2); a.addActionListener(new clicks()); b.addActionListener(new clicks()); c.addActionListener(new clicks()); d.addActionListener(new clicks()); e.addActionListener(new clicks()); f.addActionListener(new clicks()); g.addActionListener(new clicks()); h.addActionListener(new clicks()); i.addActionListener(new clicks()); } public static void main(String[] args) { tic frame = new tic(); frame.setTitle("test"); frame.setSize(400, 250); frame.setLocationRelativeTo(null); // Center the frame frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } class clicks implements ActionListener { public void actionPerformed(ActionEvent arg0) { slick.x(); } } class click extends JPanel{ private ImageIcon imagei = new ImageIcon("C:/Users/chris/Desktop/x.JPG"); private ImageIcon imageii = new ImageIcon("C:/Users/chris/Desktop/circle.JPG"); Image image; public Image x(){ Image image = imagei.getImage(); return image; } public Image o(){ Image image = imageii.getImage(); return image; } protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(image, 0, 0,this); //g.drawImage(image, 0, 0, getWidth(), getHeight(), this); } } }