So I have bunch of grids on my window and I have a JTextField
, I want to write a number, say
20, in the text field and the 20 would change my grid size to 20 and so on.
Here you see I have set it to 30, I can set it to any number, but like I said I want to be
able to change/set the number when I type it in the text field after I run the program.
This is my Grids class and not the main class, In my main class I created the text field and
such. Also I have my actionPreformed
in my main so what do I need in my actionPreformed
(if necessary)?
So my question is after running the program how to write in the text field a
number (10,20,30 any number) and be able to change my grid size based on the number I typed?
Also what do I need in my actionPreformed
(if necessary)?
Grids class:
protected int gridSize = 30; // how many grids
public Grids( ghetto ttt )
{
setLayout( new GridLayout( gridSize, gridSize ) );
theSquares = new Marker[gridSize][gridSize];
for ( int i=0; i<gridSize; i++ )
{
for ( int j=0; j<gridSize; j++ )
{
theSquares[i][j] = new Marker(gridSize , this );
add(theSquares[i][j]);
}
}
}