这是书上的一道练习题,据提示用DrawLine就行了,可是我想不出做法来
解决方案 »
- 怎样巩固javaSE基础,求过来人指点迷津
- java中编写一个判断一个字符数组中是否存在某个字符
- 求证明
- netsbeans做桌面应用时,如何给JFrame加背景
- 大家用JAVA开发出来的都是些什么软件?运行在什么环境下?
- JBuilder8安装完成后不能运行,没反应...
- 大家好,请问java中怎样调用windows的API函数
- 有谁用过 poi 生成 Excel 文件吗?里面的中文内容都成乱码!有谁帮我给你500分~!(分五次给)
- applet中可以使用swing来进行图形设计吗?
- 用JAVA写了程序(application)之后,要在网上用,总不能让人家都装JDK吧,有什么好的办法
- 问大家个智力题
- 哪位仁兄有在分布式开发方有经验者,请授之一二!
public void paintComponent(Graphics g) {
//ensure the panel is properly rendered
super.paintComponent(g);
//get window hight and width
int intWidth = getWidth();
int intHight = getHeight();
//get the increment unit of both width and hight
int intUnitWidth = getWidth() /15;
int intUnitHight = getHeight()/15;
//variable to store current hight and width
int intCurrWidth = 0;
int intCurrHight = 0;
//while loop: run until either width or hight reach the edge
while((intCurrWidth < intWidth) && (intCurrHight < intHight)){
//draw the line.
g.drawLine(0,intCurrHight,intCurrWidth,intHight);
intCurrWidth += intUnitWidth; //increment the width by one unit
intCurrHight += intUnitHight; //increment the hight by one unit
}
}
}