I want to display a new button on screen after another button (named done) is clicked.
I have to get a gridSize from text field by user. After user clicks on done button, I have to initialize JButtons array of size [gridSize][gridSize].
For now, I have initialized a new JButton as gridCell in the mouse action listener of done button. But gridCell button does not appear when I click on done button. Where as it does appear when I initialize the gridCell button outside the scope of Mouse listener of done button.
Here's the code that shows initialization of gridCell inside action listener of done button.
JButton btnDone = new JButton("Done");
btnDone.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
int gridSize = Integer.parseInt(textArea.getText());
textArea.setText(""+gridSize);
gridCell = new JButton[gridSize][gridSize];
gridCell[0][0].setBounds(90, 140, 27, 23);
frame.getContentPane().add(gridCell[0][0]);
}
});
btnDone.setBounds(393, 12, 89, 23);
frame.getContentPane().add(btnDone);