设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9168|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行$ P1 q: Y+ w- N% }6 z( ^( }
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行, B  j: c7 M9 _5 v# @! H

' k9 `* x" \4 D, m! ]7 }似乎缺少了一个SwarmUtils的类,不知道怎么回事 3 h+ n& d9 [9 f" n

* j2 y" H7 v. z/ ?( d% ~$ _' g朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
- B' Q( x2 Q( P+ z& l& U( D, r: j& _
public class SwarmUtils {% z. Q5 Z; S4 P9 w) j  y
  public static Selector getSelector(String name, String method) {
5 y4 o# Z5 D  t& H# n5 t9 B* Z    Selector sel;$ E  H3 c5 y$ @) |0 W
    try {
6 V4 V  G6 ]- ~# s      sel = new Selector(Class.forName(name), method, false);( R; z4 S3 I1 y/ P2 ?  |  r
    } catch (Exception e) {$ Z# z) ^* i" t" h( |
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
" O6 c. |2 C3 F6 h! |3 U+ u2 @+ ~      System.err.println(name + "." + method + " returns " + e.getMessage());
( ?: E) t# ]: S# a/ u. ?  p      System.err.println("The process will be terminated.");
! o+ P+ @& }1 D* {% S+ j$ ^      System.exit(1);
3 ]7 O1 x; }' K3 a  ^3 o      return null;( N3 B" q- B' L# Y, c( i: R
    }
1 t; a2 y" I/ q2 i( q7 ^    return sel;0 x  }8 N( j' v2 o7 F0 R
  }
5 O8 G4 }( o# ]* p1 n4 M! w
) F# d% e7 O  T/ L  public static Selector getSelector(Object obj, String method) {
6 B% Q0 U# o# u7 D: D) E1 b( a8 M$ ]    Selector sel;
' K( M! ?4 l- p8 v3 S7 Y2 E" i) z6 a    try {
) v& E  }9 S+ F# W: y      sel = new Selector(obj.getClass(), method, false);
* X: W/ ~1 f. ?  [. W% s    } catch (Exception e) {+ M2 n1 j( Z1 f8 i$ y  p6 c, j6 h9 c
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "! t1 m- Z3 e3 e
          + (obj.getClass()).getName() + ".");
# @- \# Z1 O) W* i# j+ E: w& \, U      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());* {7 I8 X" `$ H7 F$ e
      System.err.println("The process will be terminated.");
9 j' v! Y  i! v8 [' x$ ^# I. R' N      System.exit(1);. A5 f5 D4 T5 F8 d$ h% I
      return null;8 E/ J& t" U6 h3 e
    }$ h* ]/ T0 ~; Z( H
    return sel;" R6 s' P0 d7 |9 Y
  }4 m* j8 E; W; R, U+ w5 `9 b
}

评分

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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