JPanel[][] sarr = new JPanel[mr][mc];
int[][] num = new int[11][25];
SeatPage() {
ImageIcon a = new ImageIcon("Seat.png");
GridLayout gl = new GridLayout(mr, mc, 10, 10);
JPanel jp=new JPanel();
jp.setBackground(Color.BLACK);
jp.setLayout(gl);
String l="";
int lc=0;int nc=0;
JFrame frame = new JFrame();
for (int i = 0; i < mr; i++) {
l = (char) ('A' + (lc)) + "";
for (int j = 0; j < mc; j++) {
sarr[i][j] = new JPanel();
sarr[i][j].setBackground(Color.BLACK);
if(i==0 || j==0 || i==mr-1 || j==mc-1 || j==6 || j==22 || i==2 || i==11) {
jp.add(sarr[i][j]);
continue;
}
nc++;
JButton b = new JButton(l+nc, a);
b.setBackground(Color.white);
b.setHorizontalTextPosition(JButton.CENTER);
b.setVerticalTextPosition(JButton.CENTER);
b.setFocusable(false);
b.setBorder(BorderFactory.createLineBorder(Color.black, 5));
b.addActionListener(this);
sarr[i][j].add(b);
jp.add(sarr[i][j]);
}
if(!(i==0 || i==mr-1 || i==2 || i==11))
lc++;
nc=0;
}
System.out.println(l+lc);
frame.setIconImage(new ImageIcon("logo.png").getImage());
frame.setExtendedState(SeatPage.MAXIMIZED_BOTH);
frame.add(jp);
frame.setForeground(Color.BLACK);
frame.setVisible(true);
}
So... the button is in a JPanel, which is in a GridLayout of another JPanel... which is in the JFrame. I am not sure if I summarized this correctly
I am not particularly familiar with awt or swing... I am just fixing this code from a friend, and it has been shortened a lot...