publicstaticvoid main(String[] args) throws IOException{
System_UI Frame=new System_UI("绘制前驱图");
}
}
画结点类
import java.awt.Color;
import java.awt.Graphics2D;
publicclass Node {//画结点
void draw_node(intx,inty, intn,Graphics2D g) {
String str="s"+Integer.toString(n);
g.setColor(Color.red);
g.drawOval(x, y, 20, 20);
g.drawString(str, x+3, y+15);
}
}
画有向边类
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.GeneralPath;
publicclass Side {//画有向边
void draw_side(intsx, intsy, intex, intey,Graphics2D g) {
doubleh=10; //箭头高度
doublel=4; //底边的一半
intx1=0,y1=0,x2=0,y2=0;
doubleawrad =Math.atan(l/h); //箭头角度
doublearraow_len = Math.sqrt( l* l + h * h); // 箭头的长度
double[] arrXY_1 = rotateVec(ex - sx, ey - sy, awrad,
true, arraow_len);
double[] arrXY_2 = rotateVec(ex - sx, ey - sy, -awrad,
true, arraow_len);
doublex_1 = ex - arrXY_1[0]; // (x3,y3)是第一端点
doubley_1 = ey - arrXY_1[1];
doublex_2 = ex - arrXY_2[0]; // (x4,y4)是第二端点
doubley_2 = ey - arrXY_2[1];
Double X3 = new Double(x_1);
x1 = X3.intValue();
Double Y3 = new Double(y_1);
y1 = Y3.intValue();
Double X4 = new Double(x_2);