设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7639|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行" y+ s5 Z+ z! r& r2 a$ r
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行$ U- R1 i- K% a& H1 U0 q$ Z" s

0 F2 d2 D- Y; F/ g) x似乎缺少了一个SwarmUtils的类,不知道怎么回事
2 v2 W7 x6 s8 Y" P1 s$ {% _+ }6 B: k2 E- ^) @7 O
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;$ c# y5 W. Y7 X. G* q! m
( O1 U3 B0 @0 g
public class SwarmUtils {
" Y& ?* h3 m" C  public static Selector getSelector(String name, String method) {. _$ e7 ]% f! K- ^; c4 F
    Selector sel;& N) J5 [% V; P7 X' M) |
    try {8 e* F8 o+ o+ }# R0 R' z4 ^
      sel = new Selector(Class.forName(name), method, false);
3 X2 a0 c/ p2 u' Z    } catch (Exception e) {
' M3 U* c4 b: y; Q  s, @; w      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");# }+ f# I0 i8 [4 Q' M
      System.err.println(name + "." + method + " returns " + e.getMessage());
) A2 R, G/ b: h& L      System.err.println("The process will be terminated.");
& d5 E/ f7 T0 S$ h  z' n/ I      System.exit(1);
0 K  \2 @$ T# v$ ?* K2 t9 p# Z4 v      return null;+ k& x& ^( @( O( V1 C8 O4 E/ d
    }
5 c3 i, y9 q! f" L    return sel;
0 J: S  B4 `% N& I7 z  }
# g5 v8 c6 y7 y6 `& `- c( ?; C# |7 f4 T" N  p/ m( _( [/ ]
  public static Selector getSelector(Object obj, String method) {  B% G6 W: Q9 I/ w1 V1 Q6 Z
    Selector sel;
. ~6 p. [$ `7 `, Q9 Z- j% Z8 k    try {1 v6 s8 e7 ?* j, i
      sel = new Selector(obj.getClass(), method, false);& P/ m8 s& U; [' |
    } catch (Exception e) {9 w  i( J$ c! w' ?
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
$ W/ x  B9 a& i9 ]: }( F2 v0 A          + (obj.getClass()).getName() + ".");7 p, p/ q6 {8 g  z5 ^+ c
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());* o7 y4 U5 N' w6 _. s
      System.err.println("The process will be terminated.");# I) v, ?- m* H: A
      System.exit(1);6 A& {$ m# l6 w+ O( J' c0 V9 w
      return null;5 ?) h8 i/ S$ t7 I+ n
    }
) y1 V6 Z" d6 P/ e3 k    return sel;" O4 x  f  h- G5 q
  }2 X$ A* v0 s3 |% I1 i7 g0 v  h
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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