设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10741|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
& W! C5 x4 J: psel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行0 t$ @& v# a( p2 @

- ^1 F0 w3 F; h$ n! T似乎缺少了一个SwarmUtils的类,不知道怎么回事 . [9 X3 f+ f) _4 a, Y
9 Q, r0 ?: f/ s) o6 F4 G2 N0 {
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;3 u+ a2 J, j! K$ n, b, r

7 A. R) P! k5 l$ s( {" opublic class SwarmUtils {( {& l2 m& L/ [7 z/ |( i0 L# y4 ?
  public static Selector getSelector(String name, String method) {0 P6 i! M  M) j0 ]& `2 W, {
    Selector sel;7 n2 N- d9 a' _% [8 ]* L, l
    try {
3 ^- l9 H" J$ Y& }4 i9 g# r      sel = new Selector(Class.forName(name), method, false);
- |# s7 t  u) O1 D* M    } catch (Exception e) {6 Z/ o; R8 K0 z9 T2 z* G
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");6 w8 D5 U+ I5 @( {0 n7 X
      System.err.println(name + "." + method + " returns " + e.getMessage());+ {4 H% C$ u! G
      System.err.println("The process will be terminated.");  x" C8 n! u4 F
      System.exit(1);
* F; l3 y7 n6 F1 _9 n& D; q      return null;
/ e! T: K  y& {) ~& B, b    }
6 i+ D) C: W1 }6 O    return sel;  v/ U+ m. G) f. |2 v4 E; |
  }3 h" P) A% w/ O( v! \
6 `; j) v3 k8 A1 D5 F: y& H
  public static Selector getSelector(Object obj, String method) {: b* ]; g; ?. F# b$ d
    Selector sel;: {% a9 w- A+ L  r+ w
    try {
& F0 ?& T' N( c/ L      sel = new Selector(obj.getClass(), method, false);( ~3 a& k9 c- H- H
    } catch (Exception e) {
) S; ~+ b; X% I$ [* Y2 o) e9 X1 Y      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
& f  v6 F; q8 A+ N          + (obj.getClass()).getName() + ".");: _! f) K0 U+ }- }7 l- L
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
! P/ M$ d% y: u4 e& b6 V: {2 U$ ~; L      System.err.println("The process will be terminated.");% A* B3 p. q% y4 M4 m  d0 Y. d
      System.exit(1);
: M& N/ J& b( F" O+ ]- l      return null;1 }2 S8 G/ E( x) S; `/ y
    }+ G; d+ ^9 a, O2 k
    return sel;2 h/ k  T; s  \4 C5 x) E
  }7 [- m3 H* p5 c
}

评分

参与人数 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-9-22 18:54 , Processed in 0.017390 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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