设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9377|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行4 }& \# }. p/ ~3 O* j0 V
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行% |6 X$ F- w0 b9 a

1 A, Y( M# F$ l1 X9 e2 ^/ S" k似乎缺少了一个SwarmUtils的类,不知道怎么回事 + L  v. E6 c) U$ J( ~  u* d4 N3 G
% @- N+ n8 B3 E% d: V5 p
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
6 @) A: t2 i1 Q8 Q( V+ o
! l# f' m1 n$ M: p& Dpublic class SwarmUtils {
# s# }  o: z* i3 u6 F  public static Selector getSelector(String name, String method) {6 v5 z' c9 c3 `6 Z: c
    Selector sel;! i) |  ?! M* ?1 Z9 n: c
    try {
; ]! S  b" h9 c: M0 u; T0 {! q5 T      sel = new Selector(Class.forName(name), method, false);
9 p& [5 Y! I- K8 k    } catch (Exception e) {
* A' i# @, N: Z( r) J+ y' \! @      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
; q) S. N4 J+ n( m      System.err.println(name + "." + method + " returns " + e.getMessage());* t, j) X; e  w# |: i
      System.err.println("The process will be terminated.");
1 B+ C" x  Q2 U/ i1 z: |; ?      System.exit(1);
+ b7 J' k- M; J  ]8 {$ W      return null;
! m: ]* y* I7 V. S* n" P1 E    }
/ h' G, h1 a3 G9 p/ d; u$ F    return sel;; r8 `  s9 ^" }! d
  }0 X. U3 w, z: P4 f0 p

% m7 O' ~2 ]- F; l2 P: |  public static Selector getSelector(Object obj, String method) {/ X0 N6 h5 X  k) H9 @7 `' C
    Selector sel;
1 `/ s) u* i+ e& a5 Y; ?    try {
) H$ A, P: y, v7 L, S7 T" P      sel = new Selector(obj.getClass(), method, false);$ ]2 u- b; _3 m! n
    } catch (Exception e) {5 \7 P- f+ A$ `8 [: y3 F
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
# k# O) X, Q7 f0 X* ]4 ^          + (obj.getClass()).getName() + ".");. {) f1 d& w' E* P# c8 p! G
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
, q9 B% k" d' X# l$ v      System.err.println("The process will be terminated.");
6 X% D; U2 i" c" B      System.exit(1);
1 n4 H- A- d5 Q' A9 b2 g% s" Z3 M      return null;
4 R1 D  `! U) w% f6 N    }8 x- q  C$ Y0 @" x. z
    return sel;
7 T5 g5 V: i5 k0 f5 c- V  }
' G6 I2 X" j8 l}

评分

参与人数 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-4-16 16:14 , Processed in 0.018619 second(s), 17 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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