Hello, I have problem with jbotton. I have botton decalre it. but how do i access it ? because I have 10X10 or 100 botton. let i want to access 95 botton how can i do that? how do i set the title?
here is code
import java.awt.*;
import javax.swing.*;
public class BattleShip extends JFrame
{
public static void main(String[] args)
{
int rows = 10;
int cols = 10;
BattleShip newbattleship = new BattleShip(rows, cols );
//newbattleship =("This my title");
//newbattleship.setSize (400, 300);
// newbattleship.setLocationRelativeTo (null);
newbattleship.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
newbattleship.pack();
newbattleship.setVisible(true);
}
public BattleShip (int rows, int cols)
{
Container pane = getContentPane();
pane.setLayout(new GridLayout(rows, cols));
for (int i = 0; i < 100; i++)
{
JButton button = new JButton(Integer.toString(i + 1));
pane.add(button);
}
}
}