设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10643|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
; G' T1 M3 L- N5 {  a# Asel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
. \: D1 v& S" A% |1 S' [0 @% N, Q% h8 v$ W& R. T
似乎缺少了一个SwarmUtils的类,不知道怎么回事 8 g2 `; j5 J7 l1 V5 Y
  Y9 r% a" y  E8 b
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;* N$ t' a, [- ]

  V. E2 C) b- h# g& G& S. wpublic class SwarmUtils {6 n" c9 z; I/ V  L3 T7 ^
  public static Selector getSelector(String name, String method) {. M9 D& N3 P- z2 `. g
    Selector sel;( B2 B5 K+ C# f, x/ _2 B& @
    try {
6 k8 K/ h: d# L& s, O      sel = new Selector(Class.forName(name), method, false);
+ f% y- F, @( S- o; Y2 E% L    } catch (Exception e) {
! u1 ?# H/ b, R/ k) G: u5 s: B0 ]" e      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");: Z2 ?! q8 H9 M8 D; F
      System.err.println(name + "." + method + " returns " + e.getMessage());
) o3 F7 a: q4 W  S& y      System.err.println("The process will be terminated.");
1 C7 w& G9 y/ X& K( w8 ]      System.exit(1);+ n5 o' ~! m" U) m. h2 E: r, ^
      return null;+ g( q3 g0 @/ P4 j6 g7 X
    }# m0 O: n+ g: h& V2 W; s# q
    return sel;
7 e) ]3 L2 x. z/ O/ W) d  }
7 |! t, I4 Y. t* c+ X1 c4 y3 B
5 |  C5 J3 B: _% S0 t! r  public static Selector getSelector(Object obj, String method) {
5 D+ H  [1 m$ b  M; R: F: v    Selector sel;
! L& m( \" y) G: ?$ {4 _    try {6 x6 T: I! I" I# b1 M8 I
      sel = new Selector(obj.getClass(), method, false);1 k2 {5 R6 [+ n2 l/ a& e3 v  ]
    } catch (Exception e) {
7 y; g: ]1 z' w4 b: C" d3 g      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "1 l& F+ R1 U6 G$ M! f* v- ]
          + (obj.getClass()).getName() + ".");
6 d0 X+ H" z1 ^/ G* P      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
4 ?( P' _* m+ }( X3 j      System.err.println("The process will be terminated.");! K  \$ c$ o: g5 C& a, C3 `) o
      System.exit(1);
. ~) Z! B# A2 h3 n/ M& ^      return null;/ j' P) Q1 }. |9 l" ?( v
    }
1 i1 ?% t; f6 P$ l    return sel;7 Z. v/ F9 ]# Y, |/ [
  }5 Q0 }5 v# M( F3 {+ h' @
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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