Using Template Pattern, problem with extends to Applet

  • Follow


public class TicTacToe extends Game (wish can extends to applet, and
probably don't have this problem)
{
	private class Board
	{
	String[] board = new String[9];
	Font font = new Font("Helvetica", Font.BOLD, 60);

	public Board()
	{
	for (int i = 0; i < 9; i++) {
        board[i] = "";
      }
	}

	public void draw(Graphics g)
	{
		  g.setFont(font);
	      g.setColor(Color.black);


	      g.drawLine(120, 0, 120, 360);
	      g.drawLine(121, 0, 121, 360);
	      g.drawLine(122, 0, 122, 360);
	      g.drawLine(123, 0, 123, 360);



	}// end class board


	}
	@Override
	public void initializeGame() {
		Graphics g = this.getGraphics();


		g.drawLine(4,5,6,7);  // this is not in paint



	}
}

this is the part of the code:
and the class is extended to Abstract class called Game, Since i have
to use Template pattern, how would i able to extends to applet also
when everi try to complie, it gives me error with intializiation, and i
also tried graphics g = null; nothings works, help.

0
Reply swq_shan10 (14) 11/12/2006 10:21:15 PM

spidey12345 wrote:
> public class TicTacToe extends Game (wish can extends to applet, and
> probably don't have this problem)
> {
> 	private class Board
> 	{
> 	String[] board = new String[9];
> 	Font font = new Font("Helvetica", Font.BOLD, 60);
>
> 	public Board()
> 	{
> 	for (int i = 0; i < 9; i++) {
>         board[i] = "";
>       }
> 	}
>
> 	public void draw(Graphics g)
> 	{
> 		  g.setFont(font);
> 	      g.setColor(Color.black);
>
>
> 	      g.drawLine(120, 0, 120, 360);
> 	      g.drawLine(121, 0, 121, 360);
> 	      g.drawLine(122, 0, 122, 360);
> 	      g.drawLine(123, 0, 123, 360);
>
>
>
> 	}// end class board
>
>
> 	}
> 	@Override
> 	public void initializeGame() {
> 		Graphics g = this.getGraphics();
>
>
> 		g.drawLine(4,5,6,7);  // this is not in paint
>
>
>
> 	}
> }
>
> this is the part of the code:
> and the class is extended to Abstract class called Game, Since i have
> to use Template pattern, how would i able to extends to applet also
> when everi try to complie, it gives me error with intializiation, and i
> also tried graphics g = null; nothings works, help.

Its dangerous to use getGraphics.  You should instead override the void
paint(Graphics g) {} method.

You would probably have gotten more help sooner if you had posted an
sscce (read about it at http://www.physci.org/codes/sscce/)
Also, telling us exactly what the error is would help us.

Good luck,
Daniel.

0
Reply Daniel 11/13/2006 7:16:36 PM


1 Replies
101 Views

(page loaded in 1.35 seconds)

Similiar Articles:







7/26/2012 3:14:27 AM


Reply: