设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8741|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行3 J6 B$ N; S& }
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行% ?2 S5 R$ X* K
( U: u1 O7 |- K! |8 B2 [! O
似乎缺少了一个SwarmUtils的类,不知道怎么回事
5 o2 G; D8 J2 X! c/ F
7 f) `- O8 b* d朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;  d3 E9 N: F' B% t2 S/ s

8 v, ^4 O# w* X3 qpublic class SwarmUtils {
$ u& U; C  r, C5 k# ]* \/ s1 o  public static Selector getSelector(String name, String method) {7 y2 t/ A" ?4 b' Y! m5 ?" R
    Selector sel;4 T% ~, q9 f" \7 k% ?0 v* \: {" z
    try {- ^% ?+ D/ f- `1 C6 _. M
      sel = new Selector(Class.forName(name), method, false);/ b7 b$ U" I" V" F) U) l7 e  f
    } catch (Exception e) {' G9 H" I- _% c
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");( u6 U4 s5 k+ m
      System.err.println(name + "." + method + " returns " + e.getMessage());
& L0 a4 q2 Q0 t) R, y% V      System.err.println("The process will be terminated.");, J) O6 P% o8 f3 g
      System.exit(1);; i$ w, k! h+ X, T+ d# I
      return null;  C0 L- I+ s/ V: n) Y
    }
; F; j' W; N/ A, d4 c  n% J* P  U& `1 V    return sel;
* A' S) _. E  A7 y$ T7 h6 P" L  }
' E& ?- ?- A8 F' h" x0 H* N5 t
# W+ }5 H; m7 Z2 y6 K, W' b  public static Selector getSelector(Object obj, String method) {
1 s& t; @6 c1 b( a) T3 a1 O    Selector sel;( g2 a9 V6 ?* d/ j- q8 t7 H
    try {
9 O5 r5 I& W" I, G4 y) T      sel = new Selector(obj.getClass(), method, false);
7 K& \; k" N) i  h' \* p    } catch (Exception e) {
2 G9 M; G8 U- f# r$ ?      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "; k3 _4 _& L6 N) X( [' I
          + (obj.getClass()).getName() + ".");
: Y" ^' {# G6 s      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());# H! c& ~' I% @: D
      System.err.println("The process will be terminated.");
& S  B! o9 T& [      System.exit(1);
% m9 E: J% s; o4 h      return null;0 R6 S) |- L$ K- ~) o* {
    }
( \+ w4 y& U7 ^5 I( L    return sel;7 u. ]: m5 i) u% `9 n) Y  r- ?
  }
8 D; h9 F1 @7 w, F6 _}

评分

参与人数 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-1-21 05:25 , Processed in 0.016691 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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