设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8768|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行% R9 V& |0 p/ T& r+ x3 G7 H2 l* j
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行& j3 {$ v* V; Q/ ?0 p0 ^1 @

0 B! R4 ]3 v& Q. W: I似乎缺少了一个SwarmUtils的类,不知道怎么回事 ' A/ A" Q  }" c  b
2 b( j" K* L# x1 }
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;4 q. `5 I# s3 l  j

5 A9 K- V- w; l$ dpublic class SwarmUtils {$ X& J. w$ d" c3 w& D3 o
  public static Selector getSelector(String name, String method) {7 X: m0 t8 k. p  Q
    Selector sel;% O! ~7 w& X; U2 E2 C4 Q( g- F
    try {. A' V  R, S; D: {) r( O, W
      sel = new Selector(Class.forName(name), method, false);- j! v. n7 p# W& o2 z& p, ?
    } catch (Exception e) {" N& \8 H5 f. K1 Q) K( v
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; w# A7 ^4 Z" r! U2 k$ a" w
      System.err.println(name + "." + method + " returns " + e.getMessage());: l, d# F/ q; Z; m
      System.err.println("The process will be terminated.");
8 w1 v; O; d/ U; t3 k' j8 y      System.exit(1);
" a" K4 C& B+ a- T1 Q$ R4 b( Y$ D5 V      return null;+ a9 g0 M, t% v( N8 `/ P. o
    }  a5 u& @; t, y& h
    return sel;
/ q* N) S8 d% z% }  }, l, i4 h( U9 r
2 ]- ]' [( W; u$ Z# S" t- A
  public static Selector getSelector(Object obj, String method) {
2 r: N7 ?: _) o! _: B; d  I: q    Selector sel;* y/ `. H  i* U- q& b; x8 t0 J
    try {
& L( m3 H$ S* j3 w+ U. i1 T7 E5 h      sel = new Selector(obj.getClass(), method, false);$ A0 n' [7 ^5 n  w( f  o% l
    } catch (Exception e) {( ?: g! V! c. k4 n/ R+ y6 j$ R
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "9 k. l/ `; ]+ u7 s- W
          + (obj.getClass()).getName() + ".");) e( ^; y1 N  G6 i& T- R
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
) \1 ]; g+ L+ e2 c+ I/ C      System.err.println("The process will be terminated.");
4 E. w6 K: t& M) [      System.exit(1);
# R2 C; f  [& s) u7 Q* k      return null;
0 i- x6 w' p7 [9 q9 j. F) M/ |. J    }4 {' ]' J/ B# j; r! @
    return sel;
' B. A, ^" }. X3 Q! p9 R$ ]  }9 M- A/ V. Y2 V; `, C/ n
}

评分

参与人数 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-1-24 07:57 , Processed in 0.024067 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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