Step 8


No kidding! Just a tiny bit of Java 2D graphics. All you need to do is add the following two statements in the TTTCell paintComponent() method, just before the if statements that draw the X or O.
    Graphics2D g2d = (Graphics2D)g;
    g2d.setStroke(new BasicStroke(4.0f, BasicStroke.CAP_ROUND,
	    BasicStroke.JOIN_ROUND));

The Graphics2D class extends the Graphics class with additional methods for doing fancier custom graphics. The graphics object of a Swing component is actually an instance of the Graphics2D class, though the paintComponent() parameter is declared as a Graphics object. To make use of the added Graphics2D methods, you need to have a variable that is declared with type Graphics2D. The first statement declares this variable and initializes it by coercing the paintComponent() parameter.

The second statement invokes the setStroke() method, which is one of the added methods in the Graphics2D class. This method changes the way lines are drawn. With the BasicStroke object that is supplied as a parameter, lines are drawn with a width of 4.0 pixels, with rounded ends, and with rounded corners where two lines meet.

After you have added the two statements, recompile your TTTCell class and run the applet with appletviewer. Your applet should look like the following demonstration applet.

Demonstration Applet