设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8915|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
5 i) n% q! O8 M: Bsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行* u( Q- A% H3 w/ s9 r
$ Y  P& Z" g8 H' ]0 u: T! c
似乎缺少了一个SwarmUtils的类,不知道怎么回事 9 U7 s& v- U" v. z2 p" [
* G4 a  f5 ]3 R. r2 Y% {
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
8 ~2 _4 o) E. t/ W# `8 d/ x: O1 w. k
public class SwarmUtils {/ H; u" i4 S- _% P, J4 r. s! p
  public static Selector getSelector(String name, String method) {
( z" b3 i; X' t/ J    Selector sel;
' ?# h2 C6 r# A* P& }6 ~3 q& ^" S5 s    try {+ h- {4 W! u) s+ R  O! ]1 m
      sel = new Selector(Class.forName(name), method, false);3 i, O* \0 F8 {1 a5 f4 K7 c' F
    } catch (Exception e) {, @7 G) x7 T+ `2 n5 v6 v* N* u
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
& Z# U9 a/ w$ P& O      System.err.println(name + "." + method + " returns " + e.getMessage());
& K! D8 [' s. ^7 ^9 C% S7 E4 o9 U      System.err.println("The process will be terminated.");
/ R5 t* K* A1 [% S, e% [8 g      System.exit(1);
) |4 j2 g) Z- ~/ g4 w- U: u: Z      return null;
/ }. [1 o* I3 v( {; Z3 D    }3 p2 `. L3 D) R
    return sel;
3 G; r: b8 s% W; T. C9 `  }4 {3 M! L0 J+ {) Q
' k* R- `) C& e4 P& E, A
  public static Selector getSelector(Object obj, String method) {
4 V1 a. S) W9 H* ?- G    Selector sel;
- N6 J4 M* o1 G5 O    try {/ y. Q: u4 ?6 M- P
      sel = new Selector(obj.getClass(), method, false);. k- M5 Z9 `1 x4 \6 l9 k: L
    } catch (Exception e) {; @* _7 x5 ]4 r0 T* K+ v
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ": U* c+ \2 ]/ j/ w
          + (obj.getClass()).getName() + ".");% i" ^1 k- P0 F" d" x
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
: ~! ]% l- P/ i6 K) H      System.err.println("The process will be terminated.");# t) V2 e9 H" N4 W7 t1 p
      System.exit(1);
7 ]1 h  S. W) c) W. P7 `# R! ~      return null;
. v% w$ c* a) i, `3 K5 `    }  b  I) ^/ Z9 L" ^
    return sel;% X, [9 N" r) ~
  }7 l1 s; ^. q" s6 k, J4 Z
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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