设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7589|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
3 m$ ~* ], a1 x5 c$ ?* x8 I7 A  Ssel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行" @5 _0 @( }- X8 B+ \0 H
3 w1 N# A& q: p) E3 M  T2 Z% Y
似乎缺少了一个SwarmUtils的类,不知道怎么回事
1 W* W5 s: n, H9 V: K" L$ A7 _  |: E$ `
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
, ^1 M1 I% m& \5 o7 g/ h$ q
( r# v, ^, l+ ~* bpublic class SwarmUtils {
, K5 |. R, ~: t) h  Q9 p6 w% |  public static Selector getSelector(String name, String method) {
" m% O& A& {( v# d3 ~, b3 M5 E3 c    Selector sel;
6 s; ~7 A' x* S7 R    try {$ x# z+ L. ?  T2 M* Z% J
      sel = new Selector(Class.forName(name), method, false);/ O9 n1 p& z$ ^* Y
    } catch (Exception e) {
, V' G1 ~8 w8 A# @% |- ~      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
) i: T3 t  w2 w4 o5 H$ c0 h2 s      System.err.println(name + "." + method + " returns " + e.getMessage());  r9 M+ m8 S3 _( F
      System.err.println("The process will be terminated.");
  `  V# p4 k! F( r4 N- y* k3 s      System.exit(1);$ l/ l: C  V, v$ @. g7 N
      return null;
+ O2 Q: a: ]8 j* Z  `    }) r$ c' G$ K1 v  @# u
    return sel;
) R6 m5 t6 n9 t) P6 C! B7 C  }
, S* K2 M! R9 l/ c
) j& |% r+ m5 N+ p: J( g  public static Selector getSelector(Object obj, String method) {
0 U7 p8 f* U: f3 D    Selector sel;
8 i  @) m/ {7 E1 O' a4 q! Z$ c7 w! y    try {
/ H- R8 @8 ~! X2 t! _% V- h      sel = new Selector(obj.getClass(), method, false);1 V1 q. p5 z7 L7 |
    } catch (Exception e) {
% U+ ]& s7 T& `2 J      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "; Y6 q- [( M$ w
          + (obj.getClass()).getName() + ".");4 Y7 G: t3 N! |, S
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());) {9 Z5 X! n9 K' P  \, R6 U. E$ _
      System.err.println("The process will be terminated.");
9 F! I+ f, t1 ^; @6 U3 _, U( R      System.exit(1);
6 B! c. }& e# x, ^0 I      return null;
$ x) r1 q( |5 Y$ A2 e9 P    }( M( _* c, ?& o+ d$ q" @
    return sel;0 g& `! x* O% r$ G+ q! y
  }
& v: v) I: P6 R- H4 f1 s3 I1 W; b8 \) w}

评分

参与人数 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, 2025-6-27 16:10 , Processed in 0.015479 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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