设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9247|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
3 S: m, z- |' k3 c" H/ Y  [7 P! psel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行* }. b6 S  O( ]$ p/ O

/ h- d7 y" y# a! k/ f! R似乎缺少了一个SwarmUtils的类,不知道怎么回事 1 T0 w9 n/ G9 Y0 \

/ ~6 M2 G1 r& Y0 v: M7 k朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
" |4 W% T- x5 [- ]$ }9 ^( P- m3 S, K% ^# S( w# O
public class SwarmUtils {) }; w7 T: a9 K, i: @+ F
  public static Selector getSelector(String name, String method) {
, E/ c. Q, T( x5 l7 u    Selector sel;/ ^; I! d6 S! ?, {4 l( n( L
    try {
* z8 v: f- g7 X7 P3 c/ D2 y: p      sel = new Selector(Class.forName(name), method, false);
! v) p0 K( ^5 j( v3 F; S4 @, W1 c    } catch (Exception e) {
# ~4 C$ s+ W1 K( t1 N) T: G$ \      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");; R3 ?! s( M9 ?$ }3 v! F
      System.err.println(name + "." + method + " returns " + e.getMessage());
, s+ y5 n  y6 a& m8 ~      System.err.println("The process will be terminated.");' U+ c9 D) J* L7 M6 C. q. G
      System.exit(1);( o" a# @: x$ \% i& Q
      return null;1 }) j( Q5 r& e7 B: w: k
    }
: h! t6 v9 v9 @  {' t) p2 Q* F! g    return sel;- A- X0 b9 ^/ ]6 d0 N4 p  B
  }
( K; r6 K6 E3 m5 q' z$ S
6 o& L2 g3 k! M. y  public static Selector getSelector(Object obj, String method) {
9 O1 {8 h+ v1 m5 N% f    Selector sel;5 k- A/ [: {( M; y* L
    try {" X7 `. H8 j; V: e7 \7 p% J4 v. ]$ H
      sel = new Selector(obj.getClass(), method, false);9 b0 f8 A0 _$ q1 D% r. Z
    } catch (Exception e) {( ]: N2 n  G; V- z8 r; N& L
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
' p" M% P' T4 r: t          + (obj.getClass()).getName() + ".");
1 q4 U! j4 P. F' l1 H      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());# v" A( D3 B( H4 C
      System.err.println("The process will be terminated.");
. V2 x- z- r/ o      System.exit(1);5 S! A1 h. W* r# a/ w
      return null;1 C( c8 ~# {7 A, |4 X4 C
    }
0 |5 U! ?* }0 _' ^    return sel;
. T" B6 K: N( A) W5 O6 v8 L9 o9 S  }/ h! T6 }' ^! X' U) z
}

评分

参与人数 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-4-2 03:19 , Processed in 0.020555 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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