设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10715|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
* B, Z& I: l* b! `$ g& J+ |) H+ Msel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
/ g% M- ]' ^$ i: k& `3 \0 Q' G7 i! N) c; P* n8 t! P! U: h
似乎缺少了一个SwarmUtils的类,不知道怎么回事
6 |- Z$ z- m; b! S- V, t$ b5 O! T7 M% g# z6 m
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
+ \* x5 Z. @* N+ H
; \( A& h8 P9 @' ^" I; Tpublic class SwarmUtils {
5 E+ _0 X; ~0 g+ B  g  public static Selector getSelector(String name, String method) {" o' K# O$ E& `2 ]$ |: r7 o
    Selector sel;4 O$ @& Y, O' Y: {& t# Q* @& K
    try {
# F6 C7 N3 q$ A. V+ O      sel = new Selector(Class.forName(name), method, false);7 }) u! w, V8 ?8 a
    } catch (Exception e) {
  \/ w0 q3 J6 t( r9 e      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");1 F% O# |& K, h! T7 i6 c
      System.err.println(name + "." + method + " returns " + e.getMessage());
4 E9 M( d7 ~$ Z, R, J2 p% C      System.err.println("The process will be terminated.");
, @5 e- z) _& l      System.exit(1);
: v+ x- @- D" F- _, v      return null;1 @8 h  y- T# {/ X# W3 k- n
    }
" S: f. w: }! f7 g    return sel;
) u- K4 O4 w* T3 I  }
5 h. E; }. m9 M8 d9 P
" H! z6 M1 d" g3 N2 C# m# N9 l3 }" w  public static Selector getSelector(Object obj, String method) {2 m+ s( v. K6 U. }, h% o3 }$ `
    Selector sel;
/ T! E$ t. X1 q5 p0 Z    try {8 i* u7 F/ d  a: F
      sel = new Selector(obj.getClass(), method, false);
. A. A0 P" z# G/ J    } catch (Exception e) {$ }% f+ W' N, B- U, r. ^9 a
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "- Z/ x: M' U& s+ Z7 w
          + (obj.getClass()).getName() + ".");
% D* ^& `  f# ^) x% b3 V      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());* Z; N; H, ?9 s) ^5 q4 W# P( U! C
      System.err.println("The process will be terminated.");
0 [! _3 H0 S  c      System.exit(1);! s+ ~( n, Y; H  l. S
      return null;, b% t! e1 h9 Y- t  L
    }# t' Y, x% d0 A. d, i
    return sel;* [6 Z0 V9 L& g+ e; \2 K
  }
4 p! i7 S7 L! ~' 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-20 07:11 , Processed in 0.017704 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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