Draw a square window consisting of square cells with the equal number of rows and columns. Each cell displays a letter or is empty. The first column should include the letters and spaces contained in an initial string with its value specified in the beginning of your program, Each letter is displayed in the centre of a cell. With this initial string, the number of rows can be determined and it is the length of the initial string (e.g. 11 and 20 respectively in the above two examples). So is the number of columns.
i need to enter a newsletter whenyouright-clickacell,awindowispoppedupforyou to enter a letter, which will be displayed in the clicked cell if you finally press the button “OK”. By this way, a newly entered letter can replace an existing letter in the clicked cell.
i have writen the lerre grid
final int CELL_SIZE = 50;
final int NUM_ROW = 10;
final int NUM_COL = 10;
char[][] letters = new char[NUM_ROW][NUM_COL];
int code;
PFont letterFont;
void setup()
{
initLetters(letters);
displayLetters(letters);
size(NUM_ROW * CELL_SIZE, NUM_COL * CELL_SIZE);
letterFont = createFont("Palatino", CELL_SIZE * 0.6);
textFont(letterFont);
textAlign(CENTER, CENTER);
}
void draw()
{
background(255);
drawGrid();
}
void initLetters(char[][] a)
{
for (int i = 0; i < a.length; i++)
{
for (int j = 0; j < a[0].length; j++)
{
code = (int)random(0, 26);
a[i][j] = (char)('A' + code);
}
}
}
void displayLetters(char[][] a)
{
for (int i = 0; i < a.length; i++)
{
for (int j = 0; j < a[0].length; j++)
{
print(a[i][j]);
}
println();
}
}
void drawCell(int row, int col, char letter)
{
stroke(0);
noFill();
rect(col * CELL_SIZE, row * CELL_SIZE, CELL_SIZE, CELL_SIZE);
fill(0);
text(letter, col * CELL_SIZE + CELL_SIZE/2, row * CELL_SIZE + CELL_SIZE/2);
}
void drawGrid()
{
for (int i = 0; i < letters.length; i++)
{
for (int j = 0; j < letters[0].length; j++)
{
drawCell(i, j, letters[i][j]);
}
}
}
how to enter a new letter whenyouright-click a cell,awindow is popped up for you to enter a letter, which will be displayed in the clicked cell. if you finally press the button “OK”. By this way, a newly entered letter can replace an existing letter in the clicked cell.