• 大小: 122KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-07
  • 语言: Java
  • 标签: java  

资源简介

java 具有图形界面的最短路径问题的求解

资源截图

代码片段和文件信息



import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.io.Serializable;

/*类通过实现 java.io.Serializable 接口以启用其序列化功能。
 未实现此接口的类将无法使其任何状态序列化或反序列化。
 可序列化类的所有子类型本身都是可序列化的。序列化接口没有方法或字段,
 仅用于标识可序列化的语义。*/


public class Drawing implements Serializable {
private static final long serialVersionUID = 4945502450819201865L;

int x1 x2 y1 y2; // 定义坐标属性
Color color = null;// 设置颜色属性
float stroke; // 定义线条粗细的属性
int type; // 定义字体属性
String s1; // 输入的字符串
String s2; // 定义字体的风格
int xLocation = -1;// 左上角x的坐标
int yLocation = -1;// 左上角y的坐标
int width = 0;// 圆的宽度
int heigh = 0;// 圆的高度
String name = ““;// 用于存放结点的名称

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public void setColor(Color color) {
this.color = color;
}
void draw(Graphics2D g2d) {
}// 定义绘图函数
}

class Line extends Drawing// 直线类
{
private static final long serialVersionUID = 4945502450819201865L;
String lineSpace = ““;// 用于存放结点与结点间的距离
void draw(Graphics2D g2d) {
g2d.setPaint(color);// 为 Graphics2D 上下文设置 Paint 属性。
// 使用为 null 的 Paint 对象调用此方法对此 Graphics2D 的当前 Paint 属性没有任何影响。

g2d.setStroke(new BasicStroke(stroke BasicStroke.CAP_ROUND
BasicStroke.JOIN_BEVEL));
// setStroke(Stroke s)为 Graphics2D 上下文设置 Stroke
// BasicStroke 类定义针对图形图元轮廓呈现属性的一个基本集合
// BasicStroke.CAP_ROUND使用半径等于画笔宽度一半的圆形装饰结束未封闭的子路径和虚线线段
// BasicStroke.JOIN_BEVEL通过直线连接宽体轮廓的外角,将路径线段连接在一起。
g2d.drawLine(x1 y1 x2 y2);// 画直线

}
}

class Circle extends Drawing {// 圆类
private static final long serialVersionUID = 4945502450819201865L;
void draw(Graphics2D g2d) {
xLocation = Math.min(x1 x2);
yLocation = Math.min(y1 y2);
width = Math.max(Math.abs(x1 - x2) Math.abs(y1 - y2));
heigh = Math.max(Math.abs(x1 - x2) Math.abs(y1 - y2));
g2d.setPaint(color);
g2d.setStroke(new BasicStroke(stroke));
g2d.drawOval(xLocation yLocation width heigh);
}
}
class fillCircle extends Drawing {// 实心圆类
private static final long serialVersionUID = 4945502450819201865L;
void draw(Graphics2D g2d) {
g2d.setPaint(color);
g2d.setStroke(new BasicStroke(stroke));
g2d.fillOval(Math.min(x1 x2) Math.min(y1 y2) Math.max(Math.abs(x1
- x2) Math.abs(y1 - y2)) Math.max(Math.abs(x1 - x2) Math
.abs(y1 - y2)));
}
}

class fillRect extends Drawing {// 实心矩形类 刷新绘图区
private static final long serialVersionUID = 4945502450819201865L;
void draw(Graphics2D g2d) {
g2d.setPaint(Color.white);
g2d.fillRect(x1 y1 x2 y2);
}
}

class Word extends Drawing {// 输入文字类
private static final long serialVersionUID = 4945502450819201865L;
void draw(Graphics2D g2d) {
g2d.setPaint(color);
g2d.setFont(new Font(s2 x2 + y2 ((int) stroke) * 10));// 设置字体
if (s1 != null)
g2d.drawString(s1 x1 y1);
}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2010-06-17 16:27  最短路径\
     文件         301  2010-05-28 22:50  最短路径\.classpath
     文件         388  2010-05-28 22:50  最短路径\.project
     目录           0  2010-05-28 22:50  最短路径\.settings\
     文件         629  2010-05-28 22:50  最短路径\.settings\org.eclipse.jdt.core.prefs
     目录           0  2010-06-17 16:27  最短路径\bin\
     文件        1067  2010-06-17 16:23  最短路径\bin\Circle.class
     文件        1168  2010-06-17 16:23  最短路径\bin\Drawing.class
     文件        6267  2010-06-17 11:10  最短路径\bin\DrawJPanel$MouseA.class
     文件        1397  2010-06-17 11:10  最短路径\bin\DrawJPanel$MouseB.class
     文件        5023  2010-06-17 11:10  最短路径\bin\DrawJPanel.class
     文件         979  2010-06-17 16:23  最短路径\bin\fillCircle.class
     文件         678  2010-06-17 16:23  最短路径\bin\fillRect.class
     目录           0  2010-06-02 01:22  最短路径\bin\images\
     文件        1186  2010-06-02 01:18  最短路径\bin\images\clear.jpg
     文件        1221  2010-06-02 01:18  最短路径\bin\images\newNode.jpg
     文件        1025  2010-06-02 01:19  最短路径\bin\images\nodeLine.jpg
     文件        1428  2010-06-02 01:19  最短路径\bin\images\nodeName.jpg
     文件        1305  2010-06-02 01:18  最短路径\bin\images\nodeSpace.jpg
     文件         875  2010-06-17 16:23  最短路径\bin\Line.class
     文件         628  2010-06-07 00:03  最短路径\bin\ShortPath.class
     文件       27386  2010-06-17 16:27  最短路径\bin\ShortPath.jar
     文件         992  2010-05-30 16:45  最短路径\bin\shortPath.properties
     文件        5966  2010-06-17 13:25  最短路径\bin\ShortPathALG.class
     文件        9795  2010-06-17 11:24  最短路径\bin\ShortPathframe.class
     文件         892  2010-06-17 16:23  最短路径\bin\Word.class
     文件       27386  2010-06-17 16:27  最短路径\ShortPath.jar
     文件         992  2010-05-30 16:45  最短路径\shortPath.properties
     目录           0  2010-06-17 16:27  最短路径\src\
     文件        3229  2010-06-17 16:23  最短路径\src\Drawing.java
     文件       11470  2010-06-17 11:10  最短路径\src\DrawJPanel.java
............此处省略11个文件信息

评论

共有 条评论