设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10178|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
$ ?+ v" y/ P5 y3 Ksel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行3 g$ B* ]  B" V& |" v

% y# M6 z9 {3 ]6 ]6 Q- w- j似乎缺少了一个SwarmUtils的类,不知道怎么回事 ! Q# Q. y( o: w8 z* `. L
2 f% A7 S; R# b
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;) Y' U3 B6 C& J9 u
: l9 X# f! p# U( C. c% d$ u
public class SwarmUtils {
0 X" o! ~( Y2 M4 I- g  public static Selector getSelector(String name, String method) {
- L" C* F; y/ ?: V! Q2 h% Y    Selector sel;( ~. W4 I6 p" s7 {7 \
    try {( P" b& Y, C5 P
      sel = new Selector(Class.forName(name), method, false);
8 y  N9 y$ I/ Q$ ]5 I9 l    } catch (Exception e) {
" m: K3 E# m4 C8 \6 n' C, @( ]% H      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");) p% V' A  e' |- E
      System.err.println(name + "." + method + " returns " + e.getMessage());
4 g1 C0 F9 |/ w5 z: L( b; |0 Q7 b      System.err.println("The process will be terminated.");' l# b9 T7 Z* [0 e( K! R
      System.exit(1);
7 E. O, r& b1 P. [0 k) W+ X! n5 V      return null;. W" }5 E% b. L% a6 m/ E
    }
' w! L. r; o2 J4 {    return sel;
5 n' R9 W6 |# S5 D( k7 G  }
. I% t  y+ M8 t' V* r. [$ P9 I) \2 ~( C2 s/ O3 ?" q
  public static Selector getSelector(Object obj, String method) {2 j4 ?8 a, ]& e# C  ?2 O4 W$ B
    Selector sel;, K1 e9 N# X4 G. C- R9 F$ G
    try {& N7 F( |2 Q# ^; v. W" A6 |
      sel = new Selector(obj.getClass(), method, false);, h/ t1 y2 l& E5 S( ^6 S
    } catch (Exception e) {- J! L6 m, l! b( _; f" Y
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
0 [+ M$ _& b6 U) S$ o6 |+ u          + (obj.getClass()).getName() + ".");
+ U. e- {' C" b" ?. A      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());! Z3 n; `8 M8 @" O8 ?: I& Z
      System.err.println("The process will be terminated.");% ]$ t, d; A. j0 d- J5 v. R
      System.exit(1);
3 W4 I7 w8 R& N! T: r; m. v      return null;
: s. q! j$ \% o; D! `- N    }1 e" b# d3 ?) Z6 `  v
    return sel;
& b2 o# {' \5 `. L  }2 r0 x2 z8 F; B2 d
}

评分

参与人数 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-7-22 06:17 , Processed in 0.013442 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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