#Why No BuTTON SHOW UP

4 messages · Page 1 of 1 (latest)

finite raptor
#

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.*;

public class TicTacToe {
int boardWith = 600;
int boardHeight = 650;

JFrame frame = new JFrame("Tic Tac Toe");
JLabel textLable = new JLabel();
JPanel textPanel = new JPanel();
JPanel boardPanel = new JPanel();

JButton[][] board = new JButton[3][3];
String playerX = "X";
String playerO = "O";
String currentPlayer = playerX;

TicTacToe() {
    frame.setTitle("Tic Tac Toe");
    frame.setSize(boardWith, boardHeight);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(false);
    frame.setVisible(true);
    frame.setLocationRelativeTo(null);
    frame.setLayout(new BorderLayout());

    textLable.setBackground(Color.darkGray);
    textLable.setForeground(Color.white);
    textLable.setFont(new Font("Arial", Font.BOLD, 50));
    textLable.setHorizontalAlignment(JLabel.CENTER);
    textLable.setText("Tic Tac Toe");
    textLable.setOpaque(true);

    textPanel.setLayout(new BorderLayout());
    textPanel.add(textLable);
    frame.add(textPanel, BorderLayout.NORTH);
    
    boardPanel.setLayout(new GridLayout(3, 3));
    boardPanel.setBackground(Color.darkGray);
    frame.add(boardPanel);

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            board[i][j] = new JButton();
            board[i][j].setFont(new Font("Arial", Font.BOLD, 120));
            board[i][j].setFocusable(false);
            board[i][j].setBackground(Color.white);
            board[i][j].setForeground(Color.black);
            board[i][j].setBorderPainted(false);
            boardPanel.add(board[i][j]);
        }
    }
}

}

the button not showing upppp

halcyon spokeBOT
#

This post has been reserved for your question.

Hey @finite raptor! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

crude lotus
#

you prob want to try
frame.revalidate()
and
frame.repaint()
After your for loop