先谢谢您!可我的环境是1.1这个不能变
解决方案 »
- 把canvas 改成 Jpanel, 就不会主动刷新了,为什么
- 关于integer类型的变量的问题!!!求解!
- java中使用JNI的registry-3.1.3能否远程访问注册表,一个例子
- 缴费金额必须填写,不能为0,但可以为负数,有没有这个FORM的验证或是java代码
- 请问同样的文件被压缩成.sxw文件和.zip文件后,两者有什么区别?(在线等候)
- java 与数据库的连接问题
- 多个jar文件如何打包成一个jar
- 怎样去掉回运时的Dos窗口
- myeclipse与jre版本问题
- Javase,看视频自学,但是那么多类吗,怎么可能记得住!
- 急!!!谁有RTF文件格式中元素说明?给一份!谢先!!!!70分奉上!
- 关于运用java处理图片问题,高分诚聘。
import java.awt.*;
import java.applet.*;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);
drawThickLine(g, 0, getSize().height, getSize().width, 0, 5, new Color(0).red);
drawThickLine
(g, getSize().width/2, 0, getSize().width/2, getSize().height, 8, new Color(0).green);
drawThickLine
(g, 0, getSize().height/2, getSize().width, getSize().height/2, 12, new Color(0).blue);
} 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);
}
}
Using JDK1.2 public void paint(Graphics g){
Graphics2D g2d = (Graphics2D)g;
int width = 10;
g2d.setStroke(new BasicStroke(width));
g2d.drawLine(x1, y1, x2, y2);
}
On a Component int width = 10;
BasicStroke bs = new BasicStroke(width);
JLabel l = new JLabel();
l.getGraphics().setStroke(bs);
l.drawLine(0,0,100,100);
Using JDK1.3 import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;public class TestLine extends JFrame{
private MyPanel panel;
public TestLine() {
setSize(200, 200);
panel = new MyPanel();
getContentPane().add( panel, "Center" );
} public static void main( String [] args ){
TestLine tl = new TestLine();
tl.setVisible( true );
}
}class MyPanel extends JPanel {
final static BasicStroke stroke = new BasicStroke(2.0f);
final static BasicStroke wideStroke = new BasicStroke(8.0f); public MyPanel(){} public void paintComponent( Graphics g ){
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setStroke( stroke );
g2.draw(new Line2D.Double(10.0, 10.0, 100.0, 10.0));
g2.setStroke( wideStroke );
g2.draw(new Line2D.Double(10.0, 50.0, 100.0, 50.0));
}
}