设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10772|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
( w9 Z# m: |1 D6 I, m2 Esel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行/ z5 j- n, w, H6 v4 a: U

1 h- G2 v7 N0 Y& X# h似乎缺少了一个SwarmUtils的类,不知道怎么回事
3 s& ~9 [: `: i3 \9 x: P; w
2 b8 {( B' n7 J. u. t3 s朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;7 l. A- x" d# x, i* S5 }: }
: {- W% A) J7 a! p* G: {! `* e
public class SwarmUtils {, S+ e0 j0 [9 O) L& a
  public static Selector getSelector(String name, String method) {0 A0 L5 _$ P3 }
    Selector sel;' Z8 P6 k$ ]3 V: j! P, P
    try {
% {% d7 S7 |2 ^  O: v/ `      sel = new Selector(Class.forName(name), method, false);
( \) p! v" W9 ^+ l, v$ g. S8 ^& H    } catch (Exception e) {2 O5 a+ W# `: I: X; ~# C0 [- R  G
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
8 D: _1 V- T) A* ^, O      System.err.println(name + "." + method + " returns " + e.getMessage());
  f8 _+ z; Y9 Z8 z2 @) ~      System.err.println("The process will be terminated.");
! P% S0 C8 ~/ q* F. C9 [& |      System.exit(1);0 k& `3 d/ J/ p
      return null;
0 Q( S! o4 C0 O9 Z3 [4 w    }$ Q: _  C0 Z& g5 P
    return sel;
& k6 ]2 a5 t: k, B0 K  }7 C8 m- O( L9 X3 D7 s9 E' `' L5 t
/ F8 S! |6 g/ @
  public static Selector getSelector(Object obj, String method) {
- N$ `$ W' B; p7 P8 P" d( m, I    Selector sel;9 o4 F) U. R8 x; a7 L
    try {  F6 t0 O5 L6 r# Y( ?
      sel = new Selector(obj.getClass(), method, false);1 g) d7 m8 J6 |' w, M
    } catch (Exception e) {
. f. M7 T/ n5 i      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
) B2 X9 O# |; q3 X8 K: q          + (obj.getClass()).getName() + ".");
4 o# v8 ^( \3 {1 H      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
$ {2 @" p7 l8 h4 A4 r% U. w0 f+ O      System.err.println("The process will be terminated.");
2 [; f3 L2 Q1 m$ G      System.exit(1);/ O7 z" {3 T4 [8 u) ?$ N& z
      return null;! ~# d( v! v% i/ m7 ?) `! b
    }* e& L% }& [5 i
    return sel;
+ O( f2 e9 G* l7 `$ b  }
/ C; O' q3 h% Q  \  M+ y5 d}

评分

参与人数 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-25 14:55 , Processed in 0.017720 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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