Click here to Skip to main content
15,896,118 members
Articles / Programming Languages / Java

How can I change the button into the image?

Rate me:
Please Sign up or sign in to vote.
1.00/5 (2 votes)
7 Nov 2012CPOL 2.3K  
import java.awt.*;import java.awt.event.*;import javax.swing.*;public class TicTacToe implements ActionListener{//Instance Variablesprivate int[][] winCombinations = new int[][] {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}, //horizontal wins{0, 3, 6}, {1, 4, 7}, {2, 5, 8}, //virticle...

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

Please Sign up or sign in to vote.
7 Nov 2012TorstenH.
Instead of JButtons you need to create JLabels. Then add the corresponding image to the JLabel. A mouse Listener on the JLabel/Image will capture the mouse event of clicking on it.How to use Icons[^]How to Write a Mouse Listener[^]A bit more OOP would help though.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions