设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9946|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行, J/ i9 m- h! l; I+ r3 C
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行! }7 i$ }0 I8 X( V) ?& g, N! L6 O
3 F. O, O2 N3 \; ^; D
似乎缺少了一个SwarmUtils的类,不知道怎么回事 8 Y* @0 w# Y# C! B
5 `! P5 e4 X/ Z: ]# R4 Q
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;( Q9 c1 J% U1 F6 _: P' o; b  P

1 y9 f- q7 R* F) t' u5 xpublic class SwarmUtils {
0 w% `" X) z0 I/ b' N! l+ G  public static Selector getSelector(String name, String method) {
. i9 n0 w6 m) i* j    Selector sel;4 E4 q' ~7 S' Z) ?, @
    try {
4 q* O9 P7 q, S3 `2 @      sel = new Selector(Class.forName(name), method, false);' B. J0 E2 X( E: U
    } catch (Exception e) {9 n4 c* b" v* q* z
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
5 W: W/ f  x, F      System.err.println(name + "." + method + " returns " + e.getMessage());3 q2 X' k% E1 m" B- ]* [& S
      System.err.println("The process will be terminated.");! h/ b5 Y! G# a' f7 Q( E7 g, q/ M
      System.exit(1);* S& {6 \- {6 N9 o9 o
      return null;! @1 m' D' X; a0 ?6 k) ]% T/ n
    }
$ d. u+ t  N4 U! K1 C; Z    return sel;! v+ F  k6 z& B4 R( Z
  }
: c4 A+ j9 G+ t. n5 f
- t+ E6 Y- Z% K: {# k" ~  public static Selector getSelector(Object obj, String method) {
: Q( \# L3 J7 f0 w- K# [    Selector sel;- C# S& D# X# _
    try {
1 `5 X' L4 d" Q      sel = new Selector(obj.getClass(), method, false);
0 f0 z# W  |- D/ g4 H9 j    } catch (Exception e) {" W; J& E3 G; D8 r; F4 y+ c. u; O
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "3 Y+ q4 M" n) j0 C0 ]0 @- _2 t
          + (obj.getClass()).getName() + ".");
/ H+ a' |. C2 j& a  V& p4 \6 |      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());4 `5 F1 {, F$ ^- Q
      System.err.println("The process will be terminated.");8 q3 R, {' X6 \8 g5 j
      System.exit(1);
% B( c6 L5 ]+ x& r* i' [/ w      return null;; E, b* o7 h- O7 Z8 U
    }
- [% d( J1 l& i2 ]( v6 P3 ^    return sel;
4 Y/ ^5 I- ?# Q$ ?: a1 m2 Y  _  }! _  j! _. C$ F" e: z, c# G
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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