设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8979|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
1 c0 L6 U/ f# X! qsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
. `, r" W, {7 ^: p: k# q3 y" u6 B% R4 p, W. m3 A! Y# u
似乎缺少了一个SwarmUtils的类,不知道怎么回事
3 E" N( v6 I. g2 ~% d" ?" q- ^7 U; \+ r- \9 m
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;6 S6 ?2 }  M9 O9 Y

# D, j) b5 e- K& H/ N- Tpublic class SwarmUtils {
( u  x: O6 }6 l# B6 M/ H  public static Selector getSelector(String name, String method) {& Y7 I7 U* E. i8 d. Y
    Selector sel;2 T3 g/ h+ z; g
    try {4 n0 ]/ s+ z& E& `6 m* K4 {
      sel = new Selector(Class.forName(name), method, false);; \- O* t! I- Y0 u
    } catch (Exception e) {9 D5 r/ o6 q. q& u, T
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");, k9 W% y( X; {# ?& h# q# v0 G; j; x
      System.err.println(name + "." + method + " returns " + e.getMessage());; K* M6 |2 u0 ]" s- Y5 ?$ D4 L7 w& }
      System.err.println("The process will be terminated.");, B3 v- A- v( I3 \. j7 O
      System.exit(1);/ @! Q* V6 B8 e/ v! P, I/ e
      return null;  x+ y+ ?1 ?' j) l! C- @
    }) o- R# G% R  R3 {2 F
    return sel;
, v4 h- |( J: x7 j4 o  }
& O$ j5 V; x/ f& b( w. Q, M( ^6 C) e# M4 `1 I: k2 C& l* \3 z. i
  public static Selector getSelector(Object obj, String method) {7 g6 h' B) E; L7 e2 F
    Selector sel;; B2 R% S4 z+ I7 e8 x8 H# U  N& x
    try {" {( g/ @8 E; K3 O: v
      sel = new Selector(obj.getClass(), method, false);
( O% B" m$ @* c4 C/ ?" G5 ?    } catch (Exception e) {% C6 [- B* s: q/ v: n; `
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
9 Y7 ^* W4 z9 J. b1 e          + (obj.getClass()).getName() + ".");8 G3 R4 l/ Q/ n
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());( I5 F4 O* P; y0 m
      System.err.println("The process will be terminated.");
+ ?* `: }7 h+ o1 {" Q      System.exit(1);- ~" u5 m% d5 _1 k& L
      return null;- i  f2 U( C5 r) Z" S! Z: L* T/ |
    }# r& M: D- ]7 \" J2 H: }! U& ]$ W# Y+ ?, l
    return sel;/ O% U7 G3 Y. P: I8 {) |
  }
$ ?; x1 w+ @9 G0 J0 A, o}

评分

参与人数 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-2-20 13:17 , Processed in 0.016705 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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