设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10484|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
8 y$ t' B7 D4 t  Zsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
; Z2 G- e1 s$ L# O- N% P, c0 A! ]$ }" c* G
似乎缺少了一个SwarmUtils的类,不知道怎么回事 4 }! {7 I+ c7 z  P3 ~, i9 I

  o) J) x- M; B5 ]# A/ c! F朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;6 i; z' L& m" Q: v
0 [( T# r: A% m, S
public class SwarmUtils {
! r8 k5 x$ f) q$ T7 h  public static Selector getSelector(String name, String method) {
) A  a3 n2 E0 ~2 \3 S- m* e/ n    Selector sel;
* `+ Q3 v) u: l! e/ ^: V    try {. Y. [. }& t$ Y: J- ]
      sel = new Selector(Class.forName(name), method, false);/ q5 U, m% j0 b( B% e
    } catch (Exception e) {
* b9 v- B% Q: t. @7 ~      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
0 p$ ~, U: U5 e; B  f# R) b      System.err.println(name + "." + method + " returns " + e.getMessage());& m2 S7 N- [; L
      System.err.println("The process will be terminated.");1 Q( M* ~; S5 m) l
      System.exit(1);
8 {7 _2 k: a6 P      return null;' h( [# ?2 Z. i+ ~! P5 h" T) S
    }  Y9 G# D+ o! n! R. ]  e% x2 G
    return sel;
6 h$ B% e& L5 y- Z  }# g% g& l4 T; t% c5 Y' ^% q

6 M) l$ J2 o6 f1 h8 s  T  public static Selector getSelector(Object obj, String method) {
# ^; S, Y4 `/ O- Q2 A    Selector sel;
/ g: D* v/ z: c( v$ r; o    try {
& f# ]( _, Q" ]  c: k! r      sel = new Selector(obj.getClass(), method, false);
# K# n$ q1 M8 b$ d; b, K    } catch (Exception e) {0 ?4 w% c+ L  k1 Z
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "; n) y5 O9 Q/ b2 Q2 x, \
          + (obj.getClass()).getName() + ".");# Z8 W( z  r% P/ l
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());5 k7 l$ k: a- h; Y3 C2 R
      System.err.println("The process will be terminated.");
' F9 I* S0 e! x5 j$ p$ h      System.exit(1);
8 o/ ~; q5 u7 B5 v      return null;
0 t4 w! G8 x% Z# L+ R" c- b0 N  z1 q    }; ~2 A& o0 E; h! [8 D% y
    return sel;% n5 k, p; F, l+ l4 |
  }
2 J3 a8 F: p3 r9 M& M% a6 \6 F5 ^7 v}

评分

参与人数 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-8-23 18:11 , Processed in 0.017032 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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