课程设计报告(4)

2019-03-16 19:11

startTime = System.nanoTime(); // 获得新的路线

newList = annealing.newLoop(cityName); endTime = System.nanoTime();

this.showTime(endTime - startTime); // 画线

usOP.setLine(g, cityName, list, newList, startCityName); this.showWayLength(g); line = 0; } }

if (draw == 2) {

cityName = \蚌埠市\

list = usOP.showCity(cityName); usOP.show(g, list, cityName); if (line == 1) {

startTime = System.nanoTime();

newList = annealing.newLoop(cityName); endTime = System.nanoTime();

this.showTime(endTime - startTime);

usOP.setLine(g, cityName, list, newList, startCityName); this.showWayLength(g); line = 0; } }

if (draw == 3) {

cityName = \安庆市\

list = usOP.showCity(cityName); usOP.show(g, list, cityName); if (line == 1) {

startTime = System.nanoTime();

newList = annealing.newLoop(cityName); endTime = System.nanoTime();

this.showTime(endTime - startTime);

usOP.setLine(g, cityName, list, newList, startCityName); this.showWayLength(g); line = 0; } }

if (draw == 4) {

cityName = \芜湖市\

list = usOP.showCity(cityName); usOP.show(g, list, cityName); if (line == 1) {

startTime = System.nanoTime();

newList = annealing.newLoop(cityName); endTime = System.nanoTime();

this.showTime(endTime - startTime);

usOP.setLine(g, cityName, list, newList, startCityName); this.showWayLength(g); line = 0; } }

if (draw == 5) {

cityName = \淮北市\

list = usOP.showCity(cityName); usOP.show(g, list, cityName); if (line == 1) {

startTime = System.nanoTime();

newList = annealing.newLoop(cityName); endTime = System.nanoTime();

this.showTime(endTime - startTime);

usOP.setLine(g, cityName, list, newList, startCityName); this.showWayLength(g); line = 0; } }

if (draw == 6) {

cityName = \阜阳市\

list = usOP.showCity(cityName); usOP.show(g, list, cityName); if (line == 1) {

startTime = System.nanoTime();

newList = annealing.newLoop(cityName); endTime = System.nanoTime();

this.showTime(endTime - startTime);

usOP.setLine(g, cityName, list, newList, startCityName); this.showWayLength(g); line = 0; }} }

// 计算和设置查询所用时间

public void showTime(long a) { float f = a / 1000;

float b = new Float(f / 1000000).floatValue();

time.setText(\查询用时:\秒\}

// 用于显示行使的总路程

}

@SuppressWarnings(\

public void showWayLength(Graphics g) { Info.setText(\查询结束,欢迎使用!\ g.setColor(Color.white);

g.drawString(\总路程: \米\}

3、方法操作

import java.awt.Color; import java.awt.Graphics; import java.util.Iterator; import java.util.List; public class userOP {

private pathInfo paInfo = new pathInfo(); public static int lineOK = 0; // 判断输入的城市是否有效

public boolean testCityName(String cityName, String name) { List list = this.showCity(cityName); Iterator li = list.iterator(); while (li.hasNext()) {

String strName = li.next();

if (name.trim().equals(strName)) { return true;} }

return false; }

// 返回城市列表

public List showCity(String name) {

return (List) factory.getFac().getUserDAO().read(name); }

// 显示城市name的名称

public void show(Graphics g, List list, String name) { int i = 0, x = 0, y = 0, a[][] = null; a = this.getZB(name);

Iterator li = list.iterator(); while (li.hasNext()) {

String city = li.next(); x = a[i][0]; y = a[i][1];

g.setColor(Color.blue);

g.fillArc(x, y, 10, 10, 0, 360); g.setColor(Color.black);

}

}

g.drawString(city, x, y); i++;

if (i == a.length) { break; }

// 获得城市的坐标

public int[][] getZB(String name) { int a[][] = null;

if (name.trim().equals(\合肥市\ a = paInfo.getHeFeiZB(); }

if (name.trim().equals(\蚌埠市\ a = paInfo.getBengBuZB(); }

if (name.trim().equals(\安庆市\ a = paInfo.getAnQingZB(); }

if (name.trim().equals(\芜湖市\ a = paInfo.getWuHuZB(); }

if (name.trim().equals(\淮北市\ a = paInfo.getHuaiBeiZB(); }

if (name.trim().equals(\阜阳市\ a = paInfo.getFuYangZB(); }

return a; }

// 画出序列list的路线

@SuppressWarnings(\

public void setLine(Graphics g, String city, List S, List newList, String startCity) {

int zb[][] = null,i=0, x = 0, y = 0, w = 0, h = 0, stop = 0; int startCityIndex = 0,newListSize=newList.size(); //获得该城市的路径长度

int way[][]=this.getCityWay(city); // 获得原始序列坐标 zb = this.getZB(city);

// 判断起始位置在最佳序列中位置

int indexOfNewList = newList.indexOf(startCity);

// 起始位置在原始序列中的坐标

startCityIndex = S.indexOf(startCity); i = startCityIndex; while (true) { x = zb[i][0]; y = zb[i][1]; startCityIndex=i;

if (indexOfNewList == (newListSize- 1)) { indexOfNewList = 0; } else {

indexOfNewList++; }

String str = newList.get(indexOfNewList); i = S.indexOf(str); w = zb[i][0]; h = zb[i][1];

g.setColor(Color.red); try {

Thread.sleep(1000);

} catch (InterruptedException e) { e.printStackTrace(); }

g.drawLine(x, y, w, h); stop++;

g.setColor(new Color(83, 205, 74));

g.drawString(\ g.setColor(Color.pink);

g.drawString(\相距 \米\(y + h) / 2);

if (stop == newList.size()) { break; } }

lineOK = 1; }

//获得城市间的路径长度

public int[][] getCityWay(String cityName) { int a[][] = null;

if (cityName.trim().equals(\合肥市\ a = paInfo.getHeFeiWay(); }

if (cityName.trim().equals(\蚌埠市\


课程设计报告(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:四川省绵阳市2013届高三第一次诊断性考试理科综合试题 生物部分

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: