one way to do this is....

Code:
import javax.swing.*;
import java.awt.GridLayout;
import java.util.Random;
import java.awt.Color;

public class Triliza extends JFrame{
    private JLabel labels[][];//array of JLabels
    private Random random;
    private String validChars[]={"x","o"," "};//valid characters in an array
    public Triliza(){
        random=new Random();
        labels=new JLabel[3][3];
        setLayout(new GridLayout(3,3));
        for (int i=0;i<3;i++)
            for(int j=0;j<3;j++){
                labels[i][j]=new JLabel(validChars[random.nextInt(3)],JLabel.CENTER);//we choose randomly one element from the array of valid characters.
                labels[i][j].setBorder(BorderFactory.createLineBorder(Color.black));//we add a border for better results

                add(labels[i][j]);
            }
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        pack();
        setVisible(true);
    }
    public static void main(String args[]){
        new Triliza();
    }
}