设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9782|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行% a5 s0 m. O% W/ p( h7 f* c4 f; T
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行; l6 I! ]0 j2 ]% }/ |( X6 n3 N+ F

) S5 r/ ?! E; c0 C9 n似乎缺少了一个SwarmUtils的类,不知道怎么回事 6 G9 z; ?/ [5 J; h- L- x, L# h
2 }$ e5 A" S: E
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
% X' w# T6 |! {% L+ y  \: G) y( V2 T) E9 H# Y# b6 w
public class SwarmUtils {7 v/ q; l5 X: n* p' F
  public static Selector getSelector(String name, String method) {
9 g  u, N: m8 F/ N    Selector sel;
) M0 {! A( H$ d5 H- O5 s    try {
' c! t3 q# E) v7 a      sel = new Selector(Class.forName(name), method, false);$ J8 C1 D" X3 A. v
    } catch (Exception e) {
  K. \5 \, c- r      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");4 b  n! g( }+ E3 m
      System.err.println(name + "." + method + " returns " + e.getMessage());- l% J: [3 @& N0 {. H$ C: }
      System.err.println("The process will be terminated.");, @; y7 U6 E6 `7 t4 A
      System.exit(1);
" {) t' `/ D5 G      return null;
+ W: I4 d6 W4 B5 f: a7 ~    }
1 s( Z% ^- ^' _: U, T* R+ y! r& k    return sel;2 b# {0 K+ L2 G0 {9 ~
  }5 V/ Y5 N% M7 _, z

: z3 R1 J+ S5 \* |  public static Selector getSelector(Object obj, String method) {
/ q* J0 C# y- S5 k    Selector sel;
( ^) i# Z4 o4 R$ C( D    try {
: O8 _; J3 z# \1 G+ W8 H( U      sel = new Selector(obj.getClass(), method, false);
6 q0 F# ?+ h2 O! J# h, |- x    } catch (Exception e) {8 R  \% l( d3 f$ R1 H
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "4 I. @& _. H% e4 B: `
          + (obj.getClass()).getName() + ".");
7 p' ~- o+ ^5 z2 R: v0 `0 r1 Z      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());3 T6 A" T+ l1 P2 d2 _9 ^0 s
      System.err.println("The process will be terminated.");$ C+ m* h0 u* g% [2 L
      System.exit(1);, h: D, t* A/ c$ d0 _% d. p$ i% @
      return null;
' y4 C  A8 j. N0 K    }
& g& b/ ~5 _, V    return sel;; x% W5 H% m1 X" C- H. |
  }
* }, ]- w2 R& ^8 A* h2 @5 R}

评分

参与人数 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-6-6 12:44 , Processed in 0.021841 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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