设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9648|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
, w+ ]7 t6 k6 X# U* M5 L  M( Ksel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行8 z$ q  x4 Q- i! X, c! o

# c) D: T8 n8 E, W- ~似乎缺少了一个SwarmUtils的类,不知道怎么回事 ) \5 m- Z" z5 a# v5 l% H
$ P" k6 a% L! j) c) j
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
8 z8 |: G- q2 B- j  t/ _& r
* x0 A1 {+ N; ^* F2 ]) e5 h4 h/ ppublic class SwarmUtils {9 l/ Y* v* s5 n  `5 y. Z( ~  }# a8 E
  public static Selector getSelector(String name, String method) {
* [" R) J/ p9 W& A7 \( V  o    Selector sel;" T: D9 h! T- k" v; ^
    try {
( s7 e; b- ^0 v2 S$ U      sel = new Selector(Class.forName(name), method, false);: q7 w( r# g& x3 a1 N# x9 d8 F4 a) y
    } catch (Exception e) {
5 h( X' u; Y& f8 e% P. x4 w5 v      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
* L; @9 [7 z( L' j" g      System.err.println(name + "." + method + " returns " + e.getMessage());
. Z: f% H6 p$ ^9 e; K; F      System.err.println("The process will be terminated.");+ R! i0 o2 Y# }- a  p/ o2 v2 m
      System.exit(1);
/ [. R8 {4 S& ]! ]7 L6 \. J- @      return null;
9 |& a( p" V1 l6 [, c5 s" f    }; B8 C3 a) p8 h2 ^" x
    return sel;$ {9 S# }$ S- C0 ?  h
  }
4 P6 C6 u) r8 d4 I8 y( O8 k
& V- J4 F1 D3 F: X! i  public static Selector getSelector(Object obj, String method) {2 z$ V% `& `5 Y; S+ E% c
    Selector sel;' L6 B& Y$ n0 p' n
    try {
+ S; m# Y, y. @; A6 H/ `! `      sel = new Selector(obj.getClass(), method, false);
& ^2 K5 m; j$ c9 `0 [2 D% a/ o    } catch (Exception e) {
6 C1 g% H/ M. Z# y" V. D3 @      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
& b5 p6 Q3 E1 T& t: [# n          + (obj.getClass()).getName() + ".");2 _. O4 |* V* X) o% @/ y
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
$ w3 m$ i$ V8 J      System.err.println("The process will be terminated.");/ M( A0 k- h: z
      System.exit(1);; c& K4 i& [% W
      return null;
" r: z+ d1 I/ g    }
0 l8 Y8 L, o+ l1 E: N( l3 V    return sel;
" ]+ h( u& V( w6 L9 @  }4 B+ q+ X4 W( s2 \" y: g
}

评分

参与人数 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-5-18 05:35 , Processed in 0.018761 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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