资源简介
实现多边形扫描线填充算法,java实现,在eclipse环境下实现
代码片段和文件信息
package jsjtxx2;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.swing.JButton;
import javax.swing.Jframe;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class MySaom {
private List points = new ArrayList();
private Jframe frame;
public static void main(String[] args)
{
MySaom ms = new MySaom();
ms.frame.setVisible(true);
}
public MySaom() {
initialize();
}
private void initialize() {
frame = new Jframe();
frame.setBounds(100 100 800 600);
frame.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JButton jbtn = new JButton(“扫描“);
jbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(points.size() != 0)
new newframe(points);
}
});
jbtn.setBounds(600 400 100 50);
frame.getContentPane().add(jbtn);
final JTextArea jtright = new JTextArea();
jtright.setBounds(580 30 150 300);
frame.getContentPane().add(jtright);
final JPanel jpleft = new JPanel();
jpleft.addMouseListener(new MouseAdapter()
{
@Override
public void mouseClicked(MouseEvent e)
{
points.add(new Point(e.getX() e.getY()));
jpleft.addMouseListener(new MouseAdapter()
{
@Override
public void mousePressed(MouseEvent e)
{
String s = ““;
for(int i = 0 ;i {
Point point = (Point)points.get(i);
s += “x:“+point.getX() + “ “ +“y:“+ point.getY() + “\n“;
}
jtright.setText(s);
}
});
draw(jpleft.getGraphics());
}
private void draw(Graphics g) {
Color c = g.getColor();
g.setColor(Color.red);
if(points.size() > 0) {
for(int i = 1 ;i Point point = (Point)points.get(i);
Point point1 = (Point)points.get(i-1);
g.fillOval(point1.getX()point1.getY()1010);
g.drawLine(point.getX()point.getY()point1.getX()point1.getY());
}
}
}
});
jpleft.setBackground(Color.WHITE);
jpleft.setBounds(10 10 553 471);
frame.getContentPane().add(jpleft);
}
}
class Point//
{
private int x;
private int y;
public Point(int x int y) {
super();
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
class newframe extends Jframe{//行的Jframe界面,里面有
- 上一篇:简单的jsp源码
- 下一篇:javaee图书管理
评论
共有 条评论