设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10199|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行) ]2 ]0 y) C0 L* I
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
/ K6 m- B8 V" z+ @% b; o. {1 f: h7 P4 N% ~& m
似乎缺少了一个SwarmUtils的类,不知道怎么回事
+ E. K8 g5 @/ F- j8 {7 N1 a( d* ^2 y
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;2 H0 B" ]1 |' W. Q& f7 r* d
5 u% ^* d5 g$ I& y) Q
public class SwarmUtils {
6 x! U' G+ T0 W. }  b8 z0 f$ P7 i  public static Selector getSelector(String name, String method) {
8 U0 e( s- J) A; S# c5 ^8 k2 x    Selector sel;
4 s6 F7 y0 F* ?+ T    try {6 d2 d3 b: \  P$ X& y; z* e6 z
      sel = new Selector(Class.forName(name), method, false);. n5 A% ^* h5 j7 v! N8 u6 B. l- j6 O! E
    } catch (Exception e) {6 Q: O1 T( _4 T. t! `4 o7 w" W
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");7 e3 p( Y% `9 T/ [. J1 `
      System.err.println(name + "." + method + " returns " + e.getMessage());
3 S% ~& V1 Q' I7 F      System.err.println("The process will be terminated.");2 o) f2 A# i$ b* L+ l0 f" @
      System.exit(1);+ x4 J9 a" ?! [: i: q
      return null;
9 p5 q% w8 }9 Q7 N. C    }
% C* \8 ?* S0 I% N    return sel;
/ b$ x1 W2 N# P9 V# X+ b  }
% w5 L% J1 H. [& p$ W. Z. ?& d; o8 Q3 B
  public static Selector getSelector(Object obj, String method) {
8 n$ Y9 ^, z* p5 t    Selector sel;! u$ ^/ H% C! Q* G6 j5 }. m1 Z
    try {6 {, @' s8 R) w' |; g6 b
      sel = new Selector(obj.getClass(), method, false);
, h& k1 n- `* T% K( `    } catch (Exception e) {; M/ O# D4 |  Q$ j. T+ w
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
1 l  q3 a3 R3 F9 G- Q          + (obj.getClass()).getName() + ".");6 U/ o: h, U! V4 h; k9 A
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
  ^. T" t& \, d9 [! _) \      System.err.println("The process will be terminated.");
6 h% u  {. B" u0 q5 I! C* x; ~      System.exit(1);
% O4 y# I5 G9 @      return null;$ N1 K6 @" l/ x* R- I- V
    }6 a; Q3 w& M( K& b
    return sel;
7 C7 C; j0 H5 Q. V0 O& s  }
2 R: Q! Z) k# P7 b* U! i}

评分

参与人数 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-7-24 05:17 , Processed in 0.018672 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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