画细线,和画粗线的方法,怎么实现的.

xiejiaohui 2002-04-28 05:57:07
画细线,和画粗线的方法,怎么实现的.
在电子白板中.........
...全文
260 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
xiejiaohui 2002-04-30
thanks!!
回复
turbochen 2002-04-29
本人在文档中心发了一个不用graphics 2d画各种直线的文档,大概中午这前就可以看到了.
回复
CanFly 2002-04-29
用scale()方法!

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;

public class TLine extends JFrame
{
private CanvasDisplay cavas;
public TLine()
{
Container content=getContentPane();
cavas=new CanvasDisplay();
content.setLayout(new FlowLayout());
content.add(cavas);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
pack();
show();
}
public static void main(String args[])
{
new TLine();
}
class CanvasDisplay extends Canvas
{
public CanvasDisplay()
{
setBackground(Color.white);
setForeground(Color.blue);
setSize(600,600);
}
public void paint(Graphics g)
{
Graphics2D g2D=(Graphics2D) g;

//move the X and Y
g2D.translate(100,100);

//rotate the line
g2D.rotate(5,200,200);

//fangda the line de bashu
g2D.scale(2,2);

//set the line's width
BasicStroke stroke=new BasicStroke(5);
g2D.setStroke(stroke);
drawhome(g2D);
}
public void drawhome(Graphics2D g2D)
{
Line2D line1=new Line2D.Float(100f,200f,200f,200f),
line2=new Line2D.Float(100f,200f,100f,100f),
line3=new Line2D.Float(100f,100f,150f,50f),
line4=new Line2D.Float(150f,50f,200f,100f),
line5=new Line2D.Float(200f,100f,200f,200f),
line6=new Line2D.Float(140f,200f,140f,150f),
line7=new Line2D.Float(140f,150f,160f,150f),
line8=new Line2D.Float(160f,150f,160f,200f);

g2D.draw(line1);
g2D.draw(line2);
g2D.draw(line3);
g2D.draw(line4);
g2D.draw(line5);
g2D.draw(line6);
g2D.draw(line7);
g2D.draw(line8);
}
}
}
回复
相关推荐
发帖
Java SE
创建于2007-09-28

6.1w+

社区成员

Java 2 Standard Edition
申请成为版主
帖子事件
创建了帖子
2002-04-28 05:57
社区公告
暂无公告