编程第九十五天

java CheckerApplet 类的 init() 方法和私有的 parseSquareSize() 方法:

public void init ( ) {
String squareSizeParam = getParameter ( " squareSize " ) ;
parseSquareSize ( squareSizeParam ) ;
String colorParam = getParameter ( " color " ) ;
Color fg = parseColor ( colorParam ) ;
setBackground ( Color . black ) ;
setForeground ( fg ) ;
}
private void parseSquareSize ( String param ) {
if ( param == null ) return ;
try {
squareSize = Integer . parseInt ( param ) ;
}
catch ( Exception e ) { // 保留默认值 }
}

猜你喜欢

转载自blog.csdn.net/imezreal/article/details/72858510