设为首页收藏本站

最大的系统仿真与系统优化公益交流社区

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10533|回复: 7

[交流] 科学网于同奎先生的源程序

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
- k6 g2 ?. r% V$ D- Dsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行5 D, Z- o# _4 Y9 S2 m
/ v, o2 o5 u: Q- \0 H  G8 \8 Y
似乎缺少了一个SwarmUtils的类,不知道怎么回事
! E; G6 H1 _3 R- |" v( h# v0 M+ L
朋友们给个反馈??

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

评分

参与人数 1仿真币 +12 +1 收起 理由
苘苘 + 12 + 1

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;+ o1 \$ y. ~, y  l
7 y9 _, H3 B. h. J" @- {
public class SwarmUtils {0 y/ V$ s7 Q1 P' n) _3 b
  public static Selector getSelector(String name, String method) {+ C' E8 G2 {! |( i, F
    Selector sel;
8 \( n) S4 \! b, O    try {
3 X7 D- ^$ O* u# W- F      sel = new Selector(Class.forName(name), method, false);
1 D- p' I! S. Z  J+ ~; ]( v    } catch (Exception e) {
4 R5 I% p, l, |2 \7 }      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
' c. L! O# O, a0 z      System.err.println(name + "." + method + " returns " + e.getMessage());
1 F* u9 m. b4 D& S7 f+ L      System.err.println("The process will be terminated.");
2 b, T3 i: ?3 b3 y      System.exit(1);2 r$ H  p4 i& n% l  Q
      return null;' {' L( p" @: T% i7 X& `; B3 D2 {
    }% I% n( Y" w1 u9 v
    return sel;- E1 s) ~8 Q/ X( d; D' |. }
  }$ Q2 t" `; A( M9 D' L
2 p0 h; {" k# U7 K4 g) ^& _# C
  public static Selector getSelector(Object obj, String method) {
& b9 Z6 K0 A/ g  N; {& C  `    Selector sel;
! ~2 r8 L& ]; t( u# t- Q2 d8 K    try {" \/ }7 ?1 b  x( W
      sel = new Selector(obj.getClass(), method, false);( x. r! X: V! u1 o% z
    } catch (Exception e) {1 K' O$ F+ g4 B3 k
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
! t7 }1 `4 a% |7 O% O          + (obj.getClass()).getName() + ".");
+ B9 J7 ]- n( [      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
) j7 ?6 d( c9 B4 J      System.err.println("The process will be terminated.");
7 |/ P% d( |! q* u      System.exit(1);0 Y4 {0 }/ d, Q- i/ h2 |
      return null;
) h% G6 n3 J; t1 [$ F4 J    }# M! |: W, r8 A; @  ?
    return sel;# f8 {* g8 U) ?* p$ V, |8 t* ]* S4 E
  }
1 |  F/ d( D- a}

评分

参与人数 1仿真币 +21 +1 收起 理由
苘苘 + 21 + 1 我很赞同

查看全部评分

发表于 2008-11-20 19:49:58 | 显示全部楼层
very good.
发表于 2008-11-28 11:12:43 | 显示全部楼层
这个……在SimpleBug的代码中自带了一个SwarmUtils的类……答案如2楼所示……
发表于 2009-3-12 14:52:51 | 显示全部楼层

谢谢

学习学习
发表于 2009-12-2 20:20:58 | 显示全部楼层
请问一下代码是添加在哪里的啊?
发表于 2012-5-22 10:31:21 | 显示全部楼层
是单独建立一个新的JAVA文件,文件名为SwarmUtils.java,然后把上述代码复制进去就可以了
发表于 2013-1-25 12:27:29 | 显示全部楼层
学习。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|SimulWay 道于仿真   

GMT+8, 2026-8-31 02:38 , Processed in 0.021747 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表