设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9951|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行1 T& `0 F$ N- z6 f7 J0 V3 _
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
5 ?/ h6 F: P4 u8 N2 o8 B9 V( ~1 Z
似乎缺少了一个SwarmUtils的类,不知道怎么回事 ! r/ r) \: H& k9 m$ p' K% \
5 V1 d8 y5 n7 W8 H# `$ N3 C
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
. [  P! L! i  t6 \- y/ W
  l) R. x* M3 M+ v+ e" C2 q, x6 Vpublic class SwarmUtils {3 |5 V9 }7 d- w" k& d3 J0 k1 J8 w
  public static Selector getSelector(String name, String method) {5 A6 p& [; `/ O- X4 `
    Selector sel;
0 e0 a9 |; P2 b$ e6 p  q: `    try {- y7 ^1 u) d# f) }% c) j( o
      sel = new Selector(Class.forName(name), method, false);
7 x% r6 u, `) ?: @    } catch (Exception e) {: n7 I5 I  _* b" ^0 q/ x
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");9 U! J, m/ L  `- v5 z
      System.err.println(name + "." + method + " returns " + e.getMessage());
7 [+ W! G, s* B2 V3 j      System.err.println("The process will be terminated.");' n1 e7 v) E: `
      System.exit(1);
& l  j, [% j  l0 w) T; r; k" [      return null;' k- P/ `2 n  j' c  y
    }
( |6 T; f; A; D# |' e    return sel;
, h3 k7 X) S$ i& d2 o* w8 p# Y  }
- x, a# Y  I/ z; D7 F/ F8 K- S9 q2 C1 @/ r
  public static Selector getSelector(Object obj, String method) {/ L* k& R+ z- |8 C- q) U+ _
    Selector sel;
4 Q5 I6 C  E6 W' A    try {
/ _" P+ M% \- _; D( E6 X' W      sel = new Selector(obj.getClass(), method, false);5 ]# t0 E* J$ e# ]
    } catch (Exception e) {
1 y: u, w& F/ D# d9 W5 e      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "/ b/ s! Q0 p& U6 }5 c1 `
          + (obj.getClass()).getName() + ".");  m8 E# z; x. B8 u! L
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());8 F0 s! y/ R  K! W9 }4 |2 k8 Q
      System.err.println("The process will be terminated.");
0 K0 p' J3 V. @      System.exit(1);8 p+ S, N% w4 r* t
      return null;! k" e3 ]6 A& t+ E9 X
    }
+ v% e" Y  n4 h& t- n3 W) c    return sel;) v- C) J) O# Z5 P$ r+ i
  }
& L9 Z$ @( e" m& [. M}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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