import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;public class thickLine extends Applet { public void init() {
} public void paint(Graphics g) {
drawThickLine(g, 0, 0, getSize().width, getSize().height, 5, new Color(0).black);
} public void drawThickLine(Graphics g, int x1, int y1, int x2, int y2, int thickness, Color c) {
// The thick line is in fact a filled polygon
g.setColor(c);
int dX = x2 - x1;
int dY = y2 - y1;
// line length
double lineLength = Math.sqrt(dX * dX + dY * dY); double scale = (double) (thickness) / (2 * lineLength); // The x and y increments from an endpoint needed to create a rectangle...
double ddx = -scale * (double) dY;
double ddy = scale * (double) dX;
ddx += (ddx > 0) ? 0.5 : -0.5;
ddy += (ddy > 0) ? 0.5 : -0.5;
int dx = (int) ddx;
int dy = (int) ddy; // Now we can compute the corner points...
int xPoints[] = new int[4];
int yPoints[] = new int[4]; xPoints[0] = x1 + dx;
yPoints[0] = y1 + dy;
xPoints[1] = x1 - dx;
yPoints[1] = y1 - dy;
xPoints[2] = x2 - dx;
yPoints[2] = y2 - dy;
xPoints[3] = x2 + dx;
yPoints[3] = y2 + dy; g.fillPolygon(xPoints, yPoints, 4);
}
}
import java.awt.Color;
import java.awt.Graphics;public class thickLine extends Applet { public void init() {
} public void paint(Graphics g) {
drawThickLine(g, 0, 0, getSize().width, getSize().height, 5, new Color(0).black);
} public void drawThickLine(Graphics g, int x1, int y1, int x2, int y2, int thickness, Color c) {
// The thick line is in fact a filled polygon
g.setColor(c);
int dX = x2 - x1;
int dY = y2 - y1;
// line length
double lineLength = Math.sqrt(dX * dX + dY * dY); double scale = (double) (thickness) / (2 * lineLength); // The x and y increments from an endpoint needed to create a rectangle...
double ddx = -scale * (double) dY;
double ddy = scale * (double) dX;
ddx += (ddx > 0) ? 0.5 : -0.5;
ddy += (ddy > 0) ? 0.5 : -0.5;
int dx = (int) ddx;
int dy = (int) ddy; // Now we can compute the corner points...
int xPoints[] = new int[4];
int yPoints[] = new int[4]; xPoints[0] = x1 + dx;
yPoints[0] = y1 + dy;
xPoints[1] = x1 - dx;
yPoints[1] = y1 - dy;
xPoints[2] = x2 - dx;
yPoints[2] = y2 - dy;
xPoints[3] = x2 + dx;
yPoints[3] = y2 + dy; g.fillPolygon(xPoints, yPoints, 4);
}
}
解决方案 »
- WindowBuilder Pro for Eclipse 4.2下载
- Ext作excel导出,始终不弹出下载对话框(程序不报错)
- struts2 jfreeChart 问题
- 配置了OpenSessionInViewFilter,为什么还出现懒加载问题啊
- AAAAAAAAA 我就剩90分了 但是我很急 需要提问 大家说怎么才能 弄到10 分啊!!!
- 急!!!Spring+hibernate连接ORACLE,有查询SQL,但是没有结果?
- 一个很有挑战性的问题哦!!! 高分相赠!!!!
- EJB开发关于JBOSS服务器的问题
- eclipse 环境问题,初级问题
- 你好,我用j2ee1.3配合tomcat4.04使用的问题
- struts中的session怎么取到为空
- 请问如何配置weblogic7.0 和jbuilder7.0?
如果你的线是(x1,y1)(x2,y2),你就可以再画几条,如
(x1,y1+1)(x2,y2+1)
(x1,y1+2)(x2,y2+2)
(x1,y1+3)(x2,y2+3)
.....
不过,要在x坐标还是Y坐标上加增量,也或者更完美再两者上面都加增量(这样直线更圆滑),你还是稍微看一下计算机图形学。