设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8887|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
( d! X2 |1 {2 ^! zsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行6 m: T* F! l  ]
- J0 i' d7 T2 T- ?+ b$ K9 r- m3 X4 ~7 V
似乎缺少了一个SwarmUtils的类,不知道怎么回事
7 f7 e0 K& `" `; _$ v& z5 ]$ u. U- M" j" Q# [  }6 F8 ]/ L
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;( ^+ L2 y. n5 Z9 _% r8 s( P

  F2 }: O- ^) N! kpublic class SwarmUtils {
( v# d' P' A, U* h! W2 K  public static Selector getSelector(String name, String method) {
: c5 N# a$ U' l7 F+ H- }' Q# f) J$ b    Selector sel;: G8 t. ?% k7 w
    try {
2 V" [) I% t& r      sel = new Selector(Class.forName(name), method, false);
: a7 D- n, W% ~8 m! E    } catch (Exception e) {, }/ V! T0 ]5 B9 T
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
. O6 P* h- S- h  A8 ~      System.err.println(name + "." + method + " returns " + e.getMessage());- i1 R# m" V1 e0 j# ]) T; U; O% E
      System.err.println("The process will be terminated.");
; n5 g7 e7 H* a      System.exit(1);6 S" u" Y& I! H0 d+ i% x1 w
      return null;
' U2 D! M" S) \" }3 W; r0 x    }
1 H  u2 C) p& s* g! M    return sel;
. Y3 Z0 [: y) b# Z+ P; N+ h  }
2 J  W/ x8 l* y8 l8 b  o4 S
0 Z  U! S: n6 z6 H  public static Selector getSelector(Object obj, String method) {
3 L5 |. D, s  ^* T3 L  M, s+ {    Selector sel;9 e7 v$ m2 L; d" m" i6 ]; D
    try {  r9 m% z. C0 g5 Q& e+ A
      sel = new Selector(obj.getClass(), method, false);$ H6 ~+ R) b6 L, n
    } catch (Exception e) {
0 f# N' i, Q- X, n5 r% d# \1 y      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "; d7 k; }- G1 d3 X
          + (obj.getClass()).getName() + ".");$ H( n1 V0 G% c% w
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
, b1 t! {8 P/ i8 z0 X      System.err.println("The process will be terminated.");
' E5 z5 o7 ^0 m: ?0 P      System.exit(1);# J1 s' T8 d, ?3 j+ }, F5 z$ o4 h
      return null;; b& }: p9 B& f' ]
    }2 X7 H# r0 {& q7 n5 N, }
    return sel;
# e6 a2 q1 A, k  }
8 C& ]: T3 h- }}

评分

参与人数 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-2-7 17:58 , Processed in 0.016376 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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