以下是Java How to Program中的一段代码,
public void sendClickedSquare( int location )
{
if ( myTurn ) { // send location to server
try {
output.writeInt( location );
myTurn = false;
} // process problems communicating with server
catch ( IOException ioException ) {
ioException.printStackTrace();
}
}
}// set current Square
public void setCurrentSquare( Square square )
{
currentSquare = square;
}// private class for the sqaures on the board
private class Square extends JPanel {
private char ;
private int location; public Square( char squareMark, int squareLocation )
{
= squareMark;
location = squareLocation; addMouseListener( new MouseAdapter() { public void mouseReleased( MouseEvent e )
{
setCurrentSquare( Square.this );
sendClickedSquare( getSquareLocation() );
} } // end anonymous inner class ); // end call to addMouseListener } // end Square constructor // return preferred size of Square
public Dimension getPreferredSize()
{
return new Dimension( 30, 30 );
} // return minimum size of Square
public Dimension getMinimumSize()
{
return getPreferredSize();
} // set for Square
public void setMark( char newMark )
{
= newMark;
repaint();
} // return Square location
public int getSquareLocation()
{
return location;
} // draw Square
public void paintComponent( Graphics g )
{
super.paintComponent( g ); g.drawRect( 0, 0, 29, 29 );
g.drawString( String.valueOf( ), 11, 20 );
}} // end class Square} // end class TicTacToeClient我不解的是当鼠标发生事件setCurrentSquare( Square.this ); 中的Square.this 是什么意思,并且是Square的构造函数是如何运行的,怎么就画出了正方形。
public void sendClickedSquare( int location )
{
if ( myTurn ) { // send location to server
try {
output.writeInt( location );
myTurn = false;
} // process problems communicating with server
catch ( IOException ioException ) {
ioException.printStackTrace();
}
}
}// set current Square
public void setCurrentSquare( Square square )
{
currentSquare = square;
}// private class for the sqaures on the board
private class Square extends JPanel {
private char ;
private int location; public Square( char squareMark, int squareLocation )
{
= squareMark;
location = squareLocation; addMouseListener( new MouseAdapter() { public void mouseReleased( MouseEvent e )
{
setCurrentSquare( Square.this );
sendClickedSquare( getSquareLocation() );
} } // end anonymous inner class ); // end call to addMouseListener } // end Square constructor // return preferred size of Square
public Dimension getPreferredSize()
{
return new Dimension( 30, 30 );
} // return minimum size of Square
public Dimension getMinimumSize()
{
return getPreferredSize();
} // set for Square
public void setMark( char newMark )
{
= newMark;
repaint();
} // return Square location
public int getSquareLocation()
{
return location;
} // draw Square
public void paintComponent( Graphics g )
{
super.paintComponent( g ); g.drawRect( 0, 0, 29, 29 );
g.drawString( String.valueOf( ), 11, 20 );
}} // end class Square} // end class TicTacToeClient我不解的是当鼠标发生事件setCurrentSquare( Square.this ); 中的Square.this 是什么意思,并且是Square的构造函数是如何运行的,怎么就画出了正方形。
g.drawRect( 0, 0, 29, 29 );就是画矩形的意思
请指教!