I need to create a custom panel that displays X,0, or nothing, randomly.
It is supposed to be something like a tic tac toe board. The only thing is, when you open it it must randomly place the x's, 0's, or blank spaces, and when the screen is resized by pulling on the corner, or elsewhere, it must randomly change the figures in its grid.

I can not figure out how to display the images randomly. I have no idea what I'm missing, it just escapes me.

I will post what I have thus far and kindly request assistance. What I need help with is randomly generating the figures positions, and making it repaint when resized or reopened.

Thanks, here is what I have thus far:

import java.awt.Color;
import java.awt.Graphics;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Exercise15_07 extends JFrame {

    public Exercise15_07() {
        add(new ticTacToeBoard());


    }

    public static void main(String[] args) {
        Exercise15_07 ticTac = new Exercise15_07();
        ticTac.setVisible(true);
        ticTac.setSize(200, 200);
        ticTac.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        ticTac.setLocationRelativeTo(null);
        ticTac.setTitle("Tic Tac Toe");
    }
}

class ticTacToeBoard extends JPanel {

    JPanel frame = new JPanel(new GridLayout(3, 3));

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawLine(2, 2, 30, 30);
        g.drawLine(30, 2, 2, 30);



    }
}

I could figure out the coordinates and put some x's, 0's, and blank spots in a grid but that is not random,lol.

Please Help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.