设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10723|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
9 N7 q9 ]7 v" i& q! g: ^) D3 lsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
* R: Q; k8 U+ i# Q# u8 W) W* D5 b# c8 D- ]" h# {" K7 ~
似乎缺少了一个SwarmUtils的类,不知道怎么回事
+ C( V/ g3 h# o9 l& I) d4 c8 w/ ]7 B! m6 V: L) ^5 D
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
0 {* q5 c, L7 r$ d' N7 Y1 z' |5 Z0 a1 Z) h: r" B5 i$ _; t% e' b
public class SwarmUtils {
# M( f5 j1 a& I9 \: Q  public static Selector getSelector(String name, String method) {
: D( [+ {( e% B6 m' X6 p    Selector sel;8 q5 H9 K! H3 J4 W. i& `
    try {( u4 n* l+ G( ~8 C) U, d. P
      sel = new Selector(Class.forName(name), method, false);
0 T7 ]- X; y) k: R    } catch (Exception e) {- \7 L1 r7 ~) o8 \3 B
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
9 Y. F5 _- E; B$ q$ d  E- O3 u$ R      System.err.println(name + "." + method + " returns " + e.getMessage());
& @5 M! j, z2 ?  ]! C$ G$ K      System.err.println("The process will be terminated.");, Q4 b2 B' H6 f" F0 P
      System.exit(1);# h. S) g3 ~; E6 k
      return null;: H+ d$ e0 ]% d( l: l3 S8 [0 }6 f
    }
% U4 D1 g2 d/ {: _; L  w+ s    return sel;
8 G; `; }) `% s; R/ G* @& s  }
! k+ h; _  K$ w0 \" |8 v7 m
" k% f) J( b$ @  public static Selector getSelector(Object obj, String method) {
& i' c6 f" M+ y% K- z    Selector sel;/ H- T0 c) c; u
    try {
1 S6 ~$ S3 r- E6 [4 O  O      sel = new Selector(obj.getClass(), method, false);) b5 l7 r3 r5 c) a: M
    } catch (Exception e) {, A; e5 T$ A& l" |( H& d
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "* A: K" R* F  N2 @5 v9 x: ^
          + (obj.getClass()).getName() + ".");) f/ z9 F+ N# m- g- f6 U1 ]7 j3 T
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
$ e3 T; Q1 i/ I$ j* w; Q, C      System.err.println("The process will be terminated.");4 y$ @5 p& K6 j5 T. A
      System.exit(1);
" R0 f' o( ?! a% E9 G      return null;' q1 L( y8 w1 }" \9 z4 D: U7 v
    }
2 J2 z- k1 P) z, c: e; N    return sel;
5 k3 q" x) n$ V7 A. F: p8 C+ `  }
( J, D% E9 q, D! Q" z- r0 P}

评分

参与人数 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-21 14:58 , Processed in 0.014823 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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