设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8956|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
0 P( z9 J- L' K* w2 h! A+ nsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
) }) W) e$ ]3 {* [% P% p7 v( n1 N3 V; I' `6 ~
似乎缺少了一个SwarmUtils的类,不知道怎么回事 " Z7 _' a7 e. j* k
) a* k! t" R( B
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;( _. p4 P- e$ j
, ^4 X( I4 v, @; G6 @* `) i
public class SwarmUtils {% D# w: ^6 z% m5 s& `3 }& z' m* t* I
  public static Selector getSelector(String name, String method) {
* i2 i* D& P, B/ M% ]6 m5 R    Selector sel;4 M# m; d; A' n* I
    try {8 t- z/ E+ L) v# U/ T4 ?" Y$ U
      sel = new Selector(Class.forName(name), method, false);
/ F# w$ v' K' z. Q1 G6 R! s8 q- l    } catch (Exception e) {# b+ C3 v: ?+ ~' X" L! U8 V6 U) i
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");. v7 E  \3 o& N5 Q
      System.err.println(name + "." + method + " returns " + e.getMessage());
+ y4 V$ t7 V6 T: s      System.err.println("The process will be terminated.");
4 C  q8 s8 u% F  U# f      System.exit(1);
9 ?9 a5 G5 P" I      return null;
* y: O3 o: P1 `, D( C    }
8 h+ Q3 z9 H9 n! J* \2 W# Z9 Z    return sel;
* m7 x$ l: o. H0 c# r+ d9 E% |  }# X. V' X4 I. A' K

" h9 ]) y. ^5 I" F. `0 @( `  public static Selector getSelector(Object obj, String method) {: c* U8 ^4 S( }" {( V: t
    Selector sel;. p, h" k, x' P: I) p# `) o
    try {5 X/ {* Z% F  R! w# v$ w5 n( d, G, G- n
      sel = new Selector(obj.getClass(), method, false);' ?7 [, ~/ F7 B$ ]
    } catch (Exception e) {
3 C% t- L. E8 K5 S. x. t      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "/ `/ Y! [& H0 _/ A, P8 t; D  K$ D+ m
          + (obj.getClass()).getName() + ".");
# `0 E  A, @1 x( a' \7 B$ P9 p      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());" A3 U- c) n5 Y/ z: r
      System.err.println("The process will be terminated.");
6 n+ m5 r- z$ y: `, a      System.exit(1);
0 j* Z: p0 q7 w      return null;6 I- P/ R" [, J& |: W' O3 c7 y
    }, j, q) W2 a' y( E9 _
    return sel;
  N5 B" }) Q, m; Z1 p; r  }4 x  M+ i5 q7 F
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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