From 9ab98e8b79688821f85649fa3a04137f83467b73 Mon Sep 17 00:00:00 2001 From: jestin Date: Tue, 27 Jul 2004 16:21:24 +0000 Subject: clean up the examples to abide to the new API --- examples/Counter.java | 7 +++---- examples/Makefile | 2 +- examples/TestIvy.java | 11 ++++++---- examples/TestIvySwing.java | 26 +++++++++++++++--------- examples/Translate.java | 37 +++++++++++++++++++++++----------- examples/ivyTranslater.java | 49 ++++++++++++++++++++++----------------------- 6 files changed, 77 insertions(+), 55 deletions(-) (limited to 'examples') diff --git a/examples/Counter.java b/examples/Counter.java index 34ae576..3c4c93e 100644 --- a/examples/Counter.java +++ b/examples/Counter.java @@ -41,13 +41,12 @@ public class Counter implements IvyMessageListener, Runnable { public static final String helpmsg = "usage: java Counter -[options]\n\t-b BUS\tspecifies the Ivy bus domain\n\t-q\tquiet, no tty output\n\t-d\tdebug\n\t-h\thelp\n"; - public Counter(String domain,boolean quiet) { + public Counter(String domain,boolean quiet) throws IvyException { this.quiet=quiet; for (int j=0;j0)?args[0]:"")); + try { + bus.sendMsg("Bonjour"+((args.length>0)?args[0]:"")); + } catch (IvyException ie) { + } } - public static void main(String args[]) { new Translate("translation.txt"); } + public static void main(String args[]) throws IvyException { + new Translate("translation.txt"); + } } diff --git a/examples/ivyTranslater.java b/examples/ivyTranslater.java index 497ac87..5299338 100644 --- a/examples/ivyTranslater.java +++ b/examples/ivyTranslater.java @@ -1,46 +1,45 @@ /** * Yet another Ivy java program example * - * This is the example from the documentations, it connects to the bus, and - * translate the messages beginning with "Hello" by the same message, where - * "Hello" is replaced by "Bonjour". + * This is the example from the documentation * * @author Yannick Jestin * * (c) CENA * - * This program is distributed as is, under the LGPL licence, which should be - * present in the package. + * This program is distributed as is * */ import fr.dgac.ivy.* ; class ivyTranslater implements IvyMessageListener { - private Ivy bus; + private Ivy bus; - ivyTranslater() { - bus = new Ivy("IvyTranslater","Hello le monde",null); - bus.bindMsg("^Hello(.*)",this); - bus.bindMsg("^Bye$",new IvyMessageListener() { - // callback for "Bye" message - public void receive(IvyClient client, - String[] args) {System.exit(0);} - }); - try { - // starts the bus on the default domain or IVY_DOMAIN property - bus.start(null); - } catch (IvyException ie) { - System.err.println("can't run the Ivy bus" + ie.getMessage()); + ivyTranslater() throws IvyException { + // initialization, name and ready message + bus = new Ivy("IvyTranslater","IvyTranslater Ready",null); + bus.bindMsg("^Hello(.*)",this); + bus.bindMsg("^Bye$",new IvyMessageListener() { + // callback for "Bye" message + public void receive(IvyClient client, String[] args) { + bus.stop(); } - } + }); + // starts the bus on the default domain + bus.start(null); + } - // callback associated to the "Hello" messages" - public void receive(IvyClient client, String[] args) { + // callback associated to the "Hello" messages" + public void receive(IvyClient client, String[] args) { + try { bus.sendMsg("Bonjour"+((args.length>0)?args[0]:"")); + } catch (IvyException ie) { + System.out.println("can't send my message !"); } + } - public static void main(String args[]) { - new ivyTranslater(); - } + public static void main(String args[]) throws IvyException { + new ivyTranslater(); + } } -- cgit v1.1