设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9006|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
; z0 `: M1 @2 T# G/ Q: G) e7 Bsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
5 h# s4 }* `! p# K0 p' W+ b1 b, G! ]  N& ]3 l' |, j
似乎缺少了一个SwarmUtils的类,不知道怎么回事
* ?: W2 l* L5 g  R; N9 V* ^6 D: o
; E, H) X( U: w/ \8 m' K# c/ G朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;, Q& A) f, r/ q7 U% n

- s/ C/ _, ~) P7 Upublic class SwarmUtils {7 k, w+ B4 y" T
  public static Selector getSelector(String name, String method) {
7 N+ W- R6 z) U    Selector sel;7 ~; a# \4 y  ]# c& T; q0 Q
    try {
0 n5 t- c) l# c! A* Z/ a6 ^+ T      sel = new Selector(Class.forName(name), method, false);
( X" O- g4 n. N: B* |6 A    } catch (Exception e) {
4 V% @; Y$ T" u/ k; g4 g! c      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
4 M: c/ r9 k; h- ?/ X, [+ O      System.err.println(name + "." + method + " returns " + e.getMessage());
3 i7 H- Z" l* Z$ P( v" R# I( e) v+ d      System.err.println("The process will be terminated.");
) x% }& L5 z3 w) D. q) Q      System.exit(1);
* J/ k, l) ]1 c5 `      return null;5 k- L" ~  t6 a8 \3 B: N
    }+ G- V0 U- A9 H/ N, z
    return sel;/ d! u; p. @4 R2 X: ~; F
  }
" {& |1 X! Y9 Z/ K+ o' m& ^$ K- ~9 [. g
  public static Selector getSelector(Object obj, String method) {7 W/ |* [0 ?7 A
    Selector sel;
/ t( G5 I) x/ [/ }% R    try {5 G3 v2 B3 s3 x
      sel = new Selector(obj.getClass(), method, false);
2 w5 {" x3 y1 D3 Q$ D    } catch (Exception e) {+ P* C( E5 C2 u
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
0 Z, n2 `5 u& K* T  s          + (obj.getClass()).getName() + ".");
4 R4 |( g/ y( V) U& _      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());5 w$ F5 A* Q# u# t" s* }4 J
      System.err.println("The process will be terminated.");- }% `% M3 {6 J# S
      System.exit(1);6 J, M5 C+ o1 ^/ o; m, P7 E" }
      return null;
9 \7 ^- `6 R6 W/ o. f7 s' ]6 {- `& N    }7 h* [* [9 r, j+ F6 g' X) u# g
    return sel;
/ ], j2 G- g8 c6 x6 h* m  }
' f; w8 f0 t5 I* P/ v  A; g8 s; ?. ~}

评分

参与人数 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-25 16:12 , Processed in 0.018544 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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