程序功能:
显示8条线段(颜色随机,位置随机,线段粗度随机)。
运行结果:
源码:
1. 实体类
/**
* 13.8 (Random Lines Using Class Line2D.Double) Modify your solution to
* Exercise 13.7 to draw random lines in random colors and random thicknesses.
* Use class Line2D.Double and method draw of class Graphics2D to draw the
* lines.
*
* @author Pandenghuang@163.com
* @Date Jan 22, 2019, 1:44:03 PM
*
*/
public class RandomLinesJPanel extends JPanel
{
public void paint(Graphics g)
{
Graphics2D g2d = (Graphics2D) g;
super.paintComponents(g);
double width = getWidth(); // total width
double height = getHeight(); // total height
int rRed=0;
int rGreen=0;
int rBlue=0;
final SecureRandom rn