`
huihui920823
  • 浏览: 37097 次
  • 性别: Icon_minigender_1
  • 来自: 济南
文章分类
社区版块
存档分类
最新评论

JAVA编写画图板时,遇到的一些小的问题的心得

 
阅读更多
if("line".equals(command)){
			g.drawLine(x1,y1,x2,y2);
		}
		else if("rect".equals(command)){
			g.drawRect(Math.min(x1,x2),Math.min(y1,y2),Math.abs(x2-x1), Math.abs(y2-y1));	
		}
		else if("oval".equals(command)){
			g.drawOval(Math.min(x1,x2),Math.min(y1,y2),Math.abs(x2-x1),Math.abs(y2-y1));
		}



1.当常量与变量进行比较时,为何把常量写在前边?
因为变量的值是随意的,有可能是NULL,如果比较时把变量写在前边就没法调用equals方法,会出现空指针异常,把常量写在前边就会避免这种问题。
2.equals方法是Object超类中的方法
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics