资源简介
计算机图形学 区域填充 扫面线功能绝对的强大 可以画任意图形 进行区域填充
代码片段和文件信息
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
class myfillcolor extends Jframe implements MouseListener ActionListener {
JPanel p;
JMenuBar b;
JMenu m1 m2 m3 m4;
JMenuItem m11 m12 m13 m21 m22 m31 m41;
static Point d0;
Point d1 d2 seed;
Point[] d;
Graphics g;
String menuname;
static Color fillcolor linecolor;
int n = 0;
void go() {
settitle(“图形填充“);
b = new JMenuBar();
setJMenuBar(b);
m1 = new JMenu(“画图“);
m2 = new JMenu(“选择颜色“);
m3 = new JMenu(“填充“);
m4 = new JMenu(“设置“);
b.add(m1);
b.add(m2);
b.add(m3);
b.add(m4);
menuname = ““;
m11 = new JMenuItem(“直线“);
m1.add(m11);
m11.addActionListener(this);
m12 = new JMenuItem(“多边形“);
m1.add(m12);
m12.addActionListener(this);
m13 = new JMenuItem(“圆形“);
m1.add(m13);
m13.addActionListener(this);
m21 = new JMenuItem(“线条颜色“);
m2.add(m21);
m21.addActionListener(this);
m22 = new JMenuItem(“填充颜色“);
m2.add(m22);
m22.addActionListener(this);
m31 = new JMenuItem(“确定种子位置“);
m3.add(m31);
m31.addActionListener(this);
m41 = new JMenuItem(“清屏“);
m4.add(m41);
m41.addActionListener(this);
d1 = new Point();
d2 = new Point();
seed = new Point();
d = new Point[100];
p = new JPanel();
add(p “Center“);
p.setBackground(Color.WHITE);
p.addMouseListener(this);
fillcolor = Color.red;
linecolor = Color.blue;
setSize(600 400);
setLocation(150 100);
setVisible(true);
}
public void actionPerformed(ActionEvent ev) {
if (ev.getActionCommand().equals(“直线“))
menuname = “直线“;
if (ev.getActionCommand().equals(“多边形“)) {
menuname = “多边形“;
n = 0;
}
if (ev.getActionCommand().equals(“圆形“))
menuname = “圆形“;
if (ev.getActionCommand().equals(“线条颜色“))
linecolor = JColorChooser.showDialog(null “请选择线条颜色“ linecolor);
if (ev.getActionCommand().equals(“填充颜色“))
fillcolor = JColorChooser.showDialog(null “请选择填充颜色“ fillcolor);
if (ev.getActionCommand().equals(“确定种子位置“)) {
menuname = “确定种子位置“;
}
if (ev.getActionCommand().equals(“清屏“)) {
g = p.getGraphics();
g.setColor(Color.WHITE);
g.clearRect((int) p.getX() (int) p.getY() p.getWidth()
p.getHeight());
menuname = ““;
repaint();
}
}
public void mouseClicked(MouseEvent ev) {
if (menuname.equals(“多边形“)) {
if (ev.getClickCount() == 1) {
d[n] = new Point();
d[n].x = ev.getX();
d[n].y = ev.getY();
g.setColor(linecolor);
g.fillOval(d[n].x d[n].y 10 10);
n++;
} else if (ev.getClickCount() == 2) {
d[n] = new Point();
d[n].x = ev.getX();
d[n].y = ev.getY();
g.setColor(linecolor);
for (int i = 0; i < n; i++)
g.drawLine(d[i].x d[i].y d[i + 1].x d[i + 1].y);
g.drawLine(d[n].x d[n].y d[0].x d[0].y);
n = 0;
}
}
if (menuname.equals(“确定种子位置“)) {
seed.x = ev.getX();
seed.y =
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 427 2012-12-16 20:20 shiyaner\.classpath
文件 384 2012-12-16 20:18 shiyaner\.project
文件 629 2012-12-16 20:18 shiyaner\.settings\org.eclipse.jdt.core.prefs
文件 3832 2012-12-27 15:57 shiyaner\bin\fil1.class
文件 5532 2012-12-27 15:57 shiyaner\bin\myfillcolor.class
文件 2850 2012-12-16 20:20 shiyaner\lib\AbsoluteLayout.jar
文件 118103 2012-12-16 20:20 shiyaner\lib\swing-layout-1.0.3.jar
文件 6731 2012-12-20 22:44 shiyaner\src\myfillcolor.java
目录 0 2012-12-16 22:20 shiyaner\.settings
目录 0 2012-12-27 15:57 shiyaner\bin
目录 0 2012-12-16 22:20 shiyaner\lib
目录 0 2012-12-17 17:02 shiyaner\src
目录 0 2012-12-16 22:20 shiyaner
----------- --------- ---------- ----- ----
138488 13
评论
共有 条评论