设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8909|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行9 V7 O& P  I  S  I2 ^, v+ k6 T
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行0 P$ A2 `8 k3 W$ e" P
6 X* H6 [% ^5 D$ ?" ^: M. f
似乎缺少了一个SwarmUtils的类,不知道怎么回事 - K0 g) r) M! F# G8 J- x' N8 J

% S8 s! f, ^7 A+ I朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
. `1 E, c8 N8 \/ N
+ q% t3 c# K  k4 K3 J% J; H: C4 ^public class SwarmUtils {" R+ I+ v; a- _& p
  public static Selector getSelector(String name, String method) {
- s6 c6 K2 y$ p, [    Selector sel;
' A0 u, V0 l* l3 `- O& b    try {& ~: K8 v9 c0 I0 G! C
      sel = new Selector(Class.forName(name), method, false);2 j: ]; o" M" L$ z" a
    } catch (Exception e) {
2 D% v8 _! k$ ?/ h2 Z      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");& x  P- y; K3 a% G0 _
      System.err.println(name + "." + method + " returns " + e.getMessage());
5 K6 R' F1 ]7 H, V- y) c# c      System.err.println("The process will be terminated.");
' q4 ]: Y& D. W  H, z" I      System.exit(1);
% @) j8 Z, M  \2 j# y% A9 t0 p      return null;. _( [- ~9 n2 R- h" @& F/ o+ i
    }
8 ]* \8 h; O; [    return sel;( j. o" p5 o9 Q, i( T0 i- ?8 o
  }
# w7 w( f, o8 Y5 G4 F# U2 N; q" h& l* M1 S
  public static Selector getSelector(Object obj, String method) {
7 ~$ E/ u3 K7 [9 o& I' X+ ?4 j    Selector sel;
- s  L5 V1 d, i    try {
8 w, A0 z7 K+ `7 `8 S. |* y      sel = new Selector(obj.getClass(), method, false);2 F: M6 l$ u  H! b) ~
    } catch (Exception e) {
0 T" d$ a7 ?% Q3 I  D      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
5 Q4 f( R! ^% n# z          + (obj.getClass()).getName() + ".");
5 ^* X( u* _2 ]* r# v: b      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());/ O0 H; ?" i; X! O) A. i  S5 O3 s, r
      System.err.println("The process will be terminated.");
( h9 [' I& H$ R+ }- L      System.exit(1);) ?3 ^  [* s# \4 D4 L. `
      return null;0 @. U+ X1 x5 X( L* u6 r; m
    }; w( F6 [# K' n% J& s% Y( j5 H
    return sel;
* ?' ]; F: j$ V9 y) I) y& J  }
2 r/ O7 ~" P0 W/ Y}

评分

参与人数 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-2-9 13:36 , Processed in 0.023093 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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