设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9810|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
# F) S( V$ ^3 T0 R; m  S* vsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行3 F3 r: y, M; M- j$ q7 N
8 T. W$ |4 t* S9 R
似乎缺少了一个SwarmUtils的类,不知道怎么回事
' b. u, {, m: s0 l+ D4 ^! Q& X
7 r6 v" k8 D* q2 p" u朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;5 z* C8 p  G3 t: F- f
+ W$ c" d1 L! r" j
public class SwarmUtils {* w( x8 Z  c' V5 R! q) Y
  public static Selector getSelector(String name, String method) {
, m9 [- {9 j7 t3 v1 o    Selector sel;. u% U; I6 C% H" T+ _# K& E
    try {7 M, i' i! \: @: G2 @( ]* s% C0 S
      sel = new Selector(Class.forName(name), method, false);
6 e1 I0 V/ U$ B) W    } catch (Exception e) {8 \7 V! C& l6 X. F4 A  P# D' k
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");6 Q5 k# O2 E1 @2 g) \, @/ I
      System.err.println(name + "." + method + " returns " + e.getMessage());
' m  Z6 \, P' [3 r) K" K( [( R      System.err.println("The process will be terminated.");4 ?! T; ]( H4 _7 j6 l
      System.exit(1);! W" u. J8 U' L# L  Q8 M" G
      return null;
* j: z5 \  n! ?    }
$ r2 }& s! V2 }" w" w8 x! ]7 G    return sel;( F7 o$ [. P- _/ t* }4 ]( G
  }, G$ R  B/ ]) v/ Z) L6 A
* a# M% }+ F+ [6 o
  public static Selector getSelector(Object obj, String method) {0 H; b5 b3 Y0 V/ h* @$ _* x
    Selector sel;
) i# k, s" N" z9 A    try {
' w2 [, [8 q' k7 }' S      sel = new Selector(obj.getClass(), method, false);1 t: c9 m' B) Z6 K! Z# K6 }+ L
    } catch (Exception e) {
# ], a- r7 N+ c& T7 A" B+ Q      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
0 H& i0 I4 Z: L5 n1 Y# y: ^          + (obj.getClass()).getName() + ".");
! d6 N4 j7 O0 @      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());, ~' p( Q( v* s) s
      System.err.println("The process will be terminated.");$ q$ f: p+ m2 ?! J9 S+ v
      System.exit(1);
" F& l# a! b, E, D. p5 L8 b      return null;: L. k/ L$ S3 y2 W! \/ p+ H
    }
& M, g8 s3 ^0 l' d5 u    return sel;* ?2 s: f. n$ Y8 {+ n1 U5 y2 r
  }
. E2 }/ ~! I6 g# Q, J0 F1 W}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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