Display A Random Tic-Tac-Toe Board Using Java Swing This is the problem:

(Game: display a tic-tac-toe board) Display a frame that contains nine labels. A label may display an image icon for X or and image icon for O. What to display is randomly decided. Use the Math.random() method to generate an integer 0 or 1, which corresponds to displaying an X or O image icon. These images are in the files x.gif and o.gif)

My code seems to do what the problem asks, and the output is practically the same as the example (minus the borders). However, without the solutions for odd-numbered exercises, I can't imagine what an "ideal" implementation of this problem would look like. For example, is it good practice to use arrays in the way that I did? 

Here is my solution:

import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;

public class DisplayTicTacToe extends JFrame {
public DisplayTicTacToe() {
    setLayout(new GridLayout(0, 3));

    ImageIcon[] display = new ImageIcon[3];
    display[0] = new ImageIcon("image/o.gif");
    display[1] = new ImageIcon("image/x.gif");
    display[2] = new ImageIcon("Empty Icon");
    for (int i = 0; i &lt; 9; i++) {
        JLabel jlb = new JLabel(display[(int)(Math.random() * 3)]);
        jlb.setBorder(new LineBorder(Color.BLACK, 1));
        add(jlb);
    }
}

public static void main(String[] args) {
    DisplayTicTacToe frame = new DisplayTicTacToe();
    frame.pack();
    frame.setTitle("Display TicTacToe");
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}
}
Math.random is not very intuitive to use. Random makes it much easier. Create an instance of Random somewhere before the main loop, and generate the random indexes with random.nextInt(3) for values 0 1 2.

It's fine to use an array like you did to pick from the values randomly. When there are only few choices, like in this example, another option is to use a switch.

"display" is not a great name for an array of icons. icons would seem more natural.

A simple way to initialize an array:

ImageIcon[] icons = {
    new ImageIcon("images/x.gif"),
    new ImageIcon("images/o.gif"),
};