设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9291|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
6 \; H; O. @- l( dsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
/ B( d' ~! H1 d$ d( F
% o( t1 }/ _" D: {& q: _  n. L似乎缺少了一个SwarmUtils的类,不知道怎么回事
7 q2 e! U. M) ^& M, s  P" ?7 I3 h4 H
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;; R0 s" N! R) i! C, p& g

3 T1 f2 Z! l+ H0 _9 G/ [! Dpublic class SwarmUtils {
5 L' {: z& Y: C% S& q* R/ \' ~  public static Selector getSelector(String name, String method) {& b, J5 |7 B6 P% c
    Selector sel;
8 L  g" E# I* O3 A. b    try {7 y' M+ z1 G" M$ x
      sel = new Selector(Class.forName(name), method, false);4 n3 k0 x( i6 s0 k1 R4 d9 _
    } catch (Exception e) {
2 M+ S7 H& J8 t* H2 g6 a5 r      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
' G: L% X. o  ?" N7 I7 a. w6 Z      System.err.println(name + "." + method + " returns " + e.getMessage());
7 w3 l, y: a% m7 M  Z      System.err.println("The process will be terminated.");( H- r" M# {: l0 {) G
      System.exit(1);
( g0 ~" e. p+ `. ?+ n& _& H      return null;
6 `# w3 M5 U" h, ^    }
, M8 C" e" a' m" y' `6 p5 a    return sel;
! l! P8 A; r* ?' N- D9 }/ d0 L2 g  }
7 S+ x$ B# y$ O. R3 u" W- j$ {* n" e4 M9 U5 _
  public static Selector getSelector(Object obj, String method) {
% j7 U& l: n- q* X8 |    Selector sel;% V( K8 a$ z  i" E' h: `
    try {# E, g6 s" J3 v) ?' Y
      sel = new Selector(obj.getClass(), method, false);
" X2 ~4 M% I: x    } catch (Exception e) {( w+ K. ?  k& q% ^; E) y3 |8 H0 d
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "5 s6 v  t3 Y) V+ M! C) E0 u0 f4 B
          + (obj.getClass()).getName() + ".");
! ~- i' x6 T# S" x. J      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
+ E! N- G  c4 L8 u, ^) d      System.err.println("The process will be terminated.");
) \; V6 j9 _3 Z0 d2 X' X& q" p      System.exit(1);1 D( K8 l- y( B+ i- J* U* }
      return null;3 M1 C$ C- h9 U$ D
    }
6 X) V% c# r; d/ c. |* P' t    return sel;) U7 V" e, l7 c
  }
' Q4 A7 f. |4 D. L, q}

评分

参与人数 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-6 10:33 , Processed in 0.020918 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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