当前位置: 技术问答>java相关
画细线,和画粗线的方法,怎么实现的.
来源: 互联网 发布时间:2015-05-21
本文导语: 画细线,和画粗线的方法,怎么实现的. 在电子白板中......... | 用scale()方法! import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.geom.*; public class TLine extends JFrame { private Ca...
画细线,和画粗线的方法,怎么实现的.
在电子白板中.........
在电子白板中.........
|
用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);
}
}
}
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);
}
}
}
|
本人在文档中心发了一个不用graphics 2d画各种直线的文档,大概中午这前就可以看到了.