import javax.swing.JPanel;
import javax.swing.JScrollPane;
@SuppressWarnings({ "unused", "serial" })
public class Window extends JPanel{
ArrayList lineList=new ArrayList ();
public void addLine(Line line) {
lineList.add(line);
}
public void paint(Graphics g) {
super.paint(g);
for(int i=0;i eages=new ArrayList();
}
Line.java:
package com.test;
//得到线的格式
import java.awt.Color;
import java.awt.Graphics;
public class Line {
private Color color;
private int x1, x2, y1, y2 ;
public Line(int x1, int y1, int x2, int y2, Color color) {
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
this.color = color;
}
public void draw(Graphics g) {
g.setColor(color);
g.drawLine(x1, y1, x2, y2);
}
}
Eage.java:
package com.test;
import com.test.Point;
//边,只记录目标节点的位置和权值
public class Eage{
public Eage(Point pointJ,double weight) {
targetPoint=pointJ;
this.weight=weight;
}
Point targetPoint;
double weight;//该边的权重
}
DV.java:
package com.test;
import java.util.ArrayList;
//DV 算法对周围节点进行信息交换和更新
public class DV {
public static Router[]R=new Router[Main.n];
int start;
int end;
public DV() {
}
public ArrayList
dv(ArrayListpoints,double[][]martix,int start,int
Point(R[R[start].next[end]].x,R[R[start].next[end]].y);
points_2.add(p1);
points_2.add(p2);
i++;
}else {
Point p3 = new
Point(R[R[start].next[end]].x,R[R[start].next[end]].y);
points_2.add(p3);
}
start=R[start].next[end];
}
return points_2;
}
}
class Router{
int index;
int x;
int y;
boolean[] neighbour=new boolean[Main.n];
double[] cost=new double[Main.n];
int[] next=new int[Main.n];
public Router(){
for(int i=0;ithis.cost[k]+r.cost[i]){
this.cost[i]=this.cost[k]+r.cost[i];
this.next[i]=k;
if(this.neighbour[i]==false){
flag=true;
}
}
}
return flag;
}
public boolean changeAll(Router[] router){