设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9573|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行, B( h; L4 V( L
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行: Y: _% W( X% {4 k, _6 S: O
/ x& {- B+ T. x- y: Z, W5 P2 J
似乎缺少了一个SwarmUtils的类,不知道怎么回事 ' v5 F' Z4 ^# B7 w3 Z

% M: ^* ?$ X  W朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;# [' d# y$ `! r$ U) v. q
1 g" e# |3 I, n+ x
public class SwarmUtils {
1 o$ D% [2 c- S  public static Selector getSelector(String name, String method) {6 h9 T/ V, D9 W  ~. U% \8 A+ S3 V
    Selector sel;
2 L5 @& c* h) H9 Y$ ^    try {
. ]8 L7 J2 S4 y# f0 P& [      sel = new Selector(Class.forName(name), method, false);! b3 r4 j1 D2 `- H' W0 i: Q
    } catch (Exception e) {
$ V  @' ?. ]% i; {, y6 z      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");- D; i6 g2 k" x2 s9 W5 a/ V0 b7 w
      System.err.println(name + "." + method + " returns " + e.getMessage());
- d: |" b5 w' ?; I& R9 K5 G  Y' B3 f      System.err.println("The process will be terminated.");- [. M# X2 f! c& N* Z" V
      System.exit(1);
2 _+ k. _+ F4 h9 n      return null;7 ^! q  E( h) `$ [/ h
    }, _# z& Q8 }1 p: A6 H8 }
    return sel;# P: |- g- J: q9 M7 c
  }2 B, X- A" \& N8 l' j9 @  l
5 ~& E3 K; P8 H+ f9 P0 `  b
  public static Selector getSelector(Object obj, String method) {. O: M1 W6 f9 q* {
    Selector sel;
  ^4 o. U% x. Q% x; d5 v- y& }    try {
- B4 B5 R$ F/ q8 D- t, U2 J7 ~6 X      sel = new Selector(obj.getClass(), method, false);
+ E2 J3 a! Z# C9 Y    } catch (Exception e) {5 u' [) F9 \- x; i# n3 g( g; z/ f
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
8 Y! S" J( \! @5 _4 Y          + (obj.getClass()).getName() + ".");
2 L( I4 Q$ a5 t5 O7 Z7 a9 i9 d1 f      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());% N' r  _3 h+ R; r" G
      System.err.println("The process will be terminated.");
2 N8 Z( S7 x& P      System.exit(1);
4 @! K6 R. y: W* i' n  u! U      return null;
, m9 Q1 F% m: F. M    }+ D, n/ `/ ?/ _6 J: @* J0 x( N
    return sel;, w, P5 S. o: t5 K* P8 e! ^
  }* P8 R9 _& Y- s6 s8 ?5 p8 Q
}

评分

参与人数 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-5-8 15:19 , Processed in 0.015946 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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