Basically my problem is that I've been able to create the buttons, but am unable to get any of the text to show up on the buttons, nor for the event listener to work. Any help would be greatly appreciated.
public class Test1
{
private static final int FRAME_WIDTH = 400 ;
private static final int FRAME_HEIGHT = 400 ;
public static void main(String[] args)
{
JFrame frame = new JFrame() ;
LifeButton[][] myButton = new LifeButton[10][10] ;
JPanel panel = new JPanel() ;
panel.setLayout( new GridLayout( 10, 10 ) ) ;
for( int i = 0 ; i < myButton.length ; i++ )
{
for( int k = 0 ; k < myButton.length ; k++ )
{
myButton[i][k] = new LifeButton( "O", false, i, k ) ;
panel.add( myButton[i][k] ) ;
}
}
public class LifeButton extends JButton
{
private String text ;
private boolean value ;
private int x ;
private int y ;
public LifeButton( String text, boolean value, int x, int y )
{
System.out.println( "Initializing button " + x + " " + y ) ;
this.text = text ;
this.value = value ;
this.x = x ;
this.y = y ;
button() ;
}
public void button()
{
System.out.println( "in button " + x + " " + y ) ;
final JButton myButton = new JButton( text ) ;
class ClickListener implements ActionListener
{
public void actionPerformed( ActionEvent event )
{
System.out.println( "in button action " + x + " " + y ) ;
if( value )
{
value = false ;
text = "0" ;
}
else
{
value = true ;
text = "X" ;
}
Bookmarks