设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9165|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行& B0 N  n$ E1 D6 L4 }# l- T; d
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行3 J4 n% @8 u" E& ^% f/ Z; [
3 m: q8 _4 S% m9 O6 F( D
似乎缺少了一个SwarmUtils的类,不知道怎么回事 9 \' [" j6 V3 y8 n6 q" H: V
# j! H& K9 ^- L
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;9 u% N$ P# k$ Q0 n+ L
9 H9 S* R8 O( m
public class SwarmUtils {
( Q2 w. W8 W! g8 r- S  V  public static Selector getSelector(String name, String method) {
0 v2 c0 {% T6 T3 [- o! _: Y; \, @8 M    Selector sel;
* D  p6 |! {0 T; p! w    try {* P, Q  g2 I: I# J4 d, E9 I# B
      sel = new Selector(Class.forName(name), method, false);7 y" h; c6 S, Y( g: c
    } catch (Exception e) {$ D% X# Z; j: D+ }9 H
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
, G3 N5 J3 u- C7 y5 \3 N3 |) ?( D! q8 V      System.err.println(name + "." + method + " returns " + e.getMessage());
+ ~8 I- V8 W0 @6 C$ u      System.err.println("The process will be terminated.");% G- b3 u; X) l: t# S" N6 C2 M
      System.exit(1);& ?, a2 S& K! j; q/ R' W
      return null;
5 M2 c  C0 g. \- Z' G8 u    }+ {. k" S* J& K9 P+ a' L/ e
    return sel;7 L9 C! ~' p" z8 B
  }! C3 c' c6 p1 W, L0 T+ s

2 @: F* ?" b7 Z  public static Selector getSelector(Object obj, String method) {
" r! R8 C; S9 }7 c, z9 `    Selector sel;
' m3 n2 q6 y6 \; G, E! T# m    try {
$ d2 d; t  x' O4 U! n3 X      sel = new Selector(obj.getClass(), method, false);1 `1 I  u$ ~! O, B' n3 C
    } catch (Exception e) {0 T! ~% k  y) J' g0 z
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
0 e/ l. u+ t, J3 \* f  N          + (obj.getClass()).getName() + ".");( P6 k9 J1 r5 @2 ~4 M: A. w
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());! q) }& J# _$ Q
      System.err.println("The process will be terminated.");1 H* p& x0 A; w" M' q
      System.exit(1);5 L3 I$ n# }) D8 i
      return null;
9 `1 c, G. |& B! H5 \" h* G5 o    }
& a2 X9 H* z' f+ B0 ^4 b5 F    return sel;( N$ T+ I/ \8 W( ~4 ^$ H
  }
( q5 T& ~4 _' Z$ y& b! m}

评分

参与人数 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-3-24 23:55 , Processed in 0.015365 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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