设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9879|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行& `+ P' N8 K4 ?' F9 Q+ x& e+ R8 [
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
7 J& o( X5 f. A0 p. [, T
6 k4 n9 I5 w+ t' p4 |似乎缺少了一个SwarmUtils的类,不知道怎么回事 ' }3 W$ |2 B! L6 Z! j

" {* S9 Q, d8 i, Y* e6 [  z朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
; ]: w' Q9 J# c- g( R: B# `- w8 b5 i0 }$ O8 Q4 W! I  K( a% n; A
public class SwarmUtils {5 L( [- N0 K/ J0 @* H( E" v
  public static Selector getSelector(String name, String method) {
& {0 q, p, l1 v' ]  F$ B) p# Y6 v* [    Selector sel;2 V/ R) B( F: Y" i! p
    try {; D6 u+ {% R( P( i: p, G: `: `
      sel = new Selector(Class.forName(name), method, false);  @" `" l& J7 T0 P8 d; T
    } catch (Exception e) {/ s7 `, N& P3 p( e$ o/ B& `0 _) t+ q
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");7 s3 Q8 ?4 s4 q- P& R
      System.err.println(name + "." + method + " returns " + e.getMessage());
7 S1 D8 f: J8 H+ z& A1 \' q2 }      System.err.println("The process will be terminated.");" |0 c+ m0 h( L( v' B9 [0 L+ B9 `
      System.exit(1);2 W0 g, I* F: B8 _7 A4 [
      return null;% D/ h- b1 F0 m' n  L- v% W0 B+ S
    }
1 N* c+ g) v3 f1 l    return sel;
9 l" O# F9 |( ?# c2 N  }, B) ^% C7 D4 ?
- p6 z' s0 Q8 K7 b* x. U
  public static Selector getSelector(Object obj, String method) {
/ q  Z" d7 O4 j& c) P. x2 H) P7 z    Selector sel;
) @- b  s. B% _# x, I% K    try {1 {* Z# t3 p0 ]- I% S1 q
      sel = new Selector(obj.getClass(), method, false);
. m9 E) s3 ?: g- ?) k3 U! q    } catch (Exception e) {
7 d) R+ `( [+ R% `" R" |      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "$ C7 @. |  }/ |1 ]& E
          + (obj.getClass()).getName() + ".");" K  ?" H2 q$ M" }2 @3 }' P0 Q
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
9 j! _. q0 R6 y) Q0 U8 T      System.err.println("The process will be terminated.");
" c5 K( z7 Y% G, Z      System.exit(1);8 A% ^2 ~5 h: ^/ U& k
      return null;7 G3 u) `+ B5 l2 [# g' L* d0 d1 {
    }
$ x0 S) q% q: m. Z$ b9 Q/ ]2 V    return sel;
$ L7 b9 B6 T' Q$ `2 g6 y  }
- a/ c1 I, o; I2 M& Y8 d  u}

评分

参与人数 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-6-19 18:04 , Processed in 0.015980 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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