设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10675|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
7 \: F. I! e  ?3 Z# z1 zsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
* L; @. I; x& A6 g- z' K
, ]" ]% Y0 O5 O1 b2 M8 L2 N: R似乎缺少了一个SwarmUtils的类,不知道怎么回事
/ o1 B7 J8 Y$ e) }/ N4 r9 C7 h! D
3 ^5 o, a0 N0 c+ h" P  X朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;1 D1 H3 n7 v% A" a, j" P0 J
1 u  M" [0 M: \1 c1 @
public class SwarmUtils {
5 }, R' O+ M( y  public static Selector getSelector(String name, String method) {
5 X$ A; T6 A2 a5 P1 A+ T7 {7 ^    Selector sel;
6 H& c* O8 s' Z) |) v+ @    try {
  B9 l. W' U, ]      sel = new Selector(Class.forName(name), method, false);
8 D& y& C0 O$ s' O    } catch (Exception e) {
; G6 n! \9 E7 }; V0 F$ _9 l) A: t* a      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");! o/ l3 f" x, h9 u3 [" T
      System.err.println(name + "." + method + " returns " + e.getMessage());4 d# M& ?  ]$ T0 M/ z' y* R
      System.err.println("The process will be terminated.");8 [- O5 E* ^8 |/ T8 B1 k: L
      System.exit(1);- Y0 q7 v# _5 t' c2 t4 r
      return null;1 H/ l/ O7 ]1 ], G4 B! f& ^8 y: }
    }
) W2 z7 }; H0 H2 P    return sel;  f/ w9 u- m7 i7 t( i$ R9 E
  }1 o4 Q1 }( X0 N  H  o3 [! v
: L5 K# Z( \/ i2 P* H! c# `
  public static Selector getSelector(Object obj, String method) {
, P1 v) @" l, G    Selector sel;
0 q) I' a% G3 B    try {
; x1 g  x6 ~& i8 j      sel = new Selector(obj.getClass(), method, false);
1 p2 E+ ^' W! g! g' ?; w    } catch (Exception e) {
3 f" J7 S, \* s6 ^/ H      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class ") W2 x* q  P9 z' \3 U& g
          + (obj.getClass()).getName() + ".");( }" ?( q+ i! _$ p
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());4 ~7 r7 T7 [, E. O
      System.err.println("The process will be terminated.");. A# |/ U6 ^9 F6 h# W
      System.exit(1);
6 g5 x, z) N9 _4 @. I      return null;
3 g% t( [. k' l5 L5 Z5 ]  _6 P  B    }
4 y! n( Z$ _% A8 H7 B: U    return sel;
  c1 w/ D, s  [& O  }
! B  H* q4 L/ x}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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