设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9065|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
1 b1 U( K8 ]9 n9 J3 ~sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行6 t4 J4 ?. D; @
" L* c$ U8 `/ j% R. y* V! w
似乎缺少了一个SwarmUtils的类,不知道怎么回事 $ i, S8 j3 p& l% h
5 I$ l* j4 v" j
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
9 F  V( t% D& s5 t/ B
( K- ], a; R4 H( I" q- kpublic class SwarmUtils {
; n0 R; _5 b* ~  O5 I3 k5 j  public static Selector getSelector(String name, String method) {) N. x( E2 e' x
    Selector sel;
. l/ P( O8 |& B* b    try {4 q: M2 A% a4 M5 f. o0 b
      sel = new Selector(Class.forName(name), method, false);, I7 p" m2 m3 N3 H. O
    } catch (Exception e) {
5 B1 E9 g1 C) b( }- B      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
* c, \8 L  ]( g- l      System.err.println(name + "." + method + " returns " + e.getMessage());
( D2 r3 S) E) f* |6 v& h$ H# `      System.err.println("The process will be terminated.");
* Q3 v7 A) ^7 V, x; B      System.exit(1);
9 r& r( @  f2 u9 G9 L      return null;7 S9 m/ e- J! `
    }
5 c+ t. Y  J: ^    return sel;
  N# {& H% X/ Q& f2 D) b  }
- G8 r+ s8 b2 V  t! b7 b1 a
- ]7 h5 k5 E# I9 D5 A( I/ q* J6 j  public static Selector getSelector(Object obj, String method) {
2 k! v' }2 k2 {- Y. X    Selector sel;
$ V$ @" n+ E! R1 G    try {
+ V3 U) v2 }6 S! r: `      sel = new Selector(obj.getClass(), method, false);
8 l0 ~! p1 W7 n  G+ j! ^9 B    } catch (Exception e) {
9 B- S" [7 D; x+ F- @  G      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "$ ^6 l$ f' t- n0 q0 J
          + (obj.getClass()).getName() + ".");
4 E" _3 Q8 z9 L3 C      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());" N) w4 U& G  e% ~/ x  m, k5 O
      System.err.println("The process will be terminated.");7 _" j4 y0 N' T' O' O
      System.exit(1);7 B' X4 L- _5 B4 U$ d  z1 d; s
      return null;
% d, R8 \( V0 ]& D    }' ^8 K0 r% w$ U# L
    return sel;9 |. G# @% o0 {7 n& U
  }) G; z4 g7 W9 y$ S
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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