1 31 package org.objectweb.proactive.examples.hello; 32 33 import org.objectweb.proactive.core.config.ProActiveConfiguration; 34 35 public class HelloApplet extends org.objectweb.proactive.examples.StandardFrame { 36 37 38 private Hello activeHello; 39 40 41 private org.objectweb.proactive.core.node.Node node; 42 43 44 private javax.swing.JTextArea lMessage; 45 46 private boolean shouldRun = true; 47 48 49 public HelloApplet(String name, int width, int height, String nodeURL) { 50 super(name, width, height); 51 if (nodeURL == null) 52 node = null; else { 54 try { 55 node = org.objectweb.proactive.core.node.NodeFactory.getNode(nodeURL); } catch (org.objectweb.proactive.core.node.NodeException e) { 57 node = null; 58 } 59 } 60 } 61 62 63 public static void main(String args[]) { 64 String nodeURL = null; 66 if (args.length > 0) { 67 nodeURL = args[0]; 69 } 70 ProActiveConfiguration.load(); 71 new HelloApplet("Hello applet", 300, 200, nodeURL); 72 } 73 74 75 public void start() { 76 receiveMessage("Applet creating active objects"); 77 receiveMessage("on node "+(node == null ? "local" : node.getNodeInformation().getURL())); 78 try { 79 activeHello = (Hello)org.objectweb.proactive.ProActive.newActive(Hello.class.getName(), null, node); 80 } catch (Exception e) { 81 receiveMessage("Error while initializing"); 83 lMessage.setText("Error... Did you set the security attributes?"); 84 e.printStackTrace(); return; 86 } 87 receiveMessage("Ok"); 88 Thread t = new Thread (new HelloTimer(), "Hello clock"); 89 t.start(); 90 } 91 92 93 public void stop() { 94 shouldRun = false; 95 activeHello = null; 96 lMessage.setText("Applet stopped"); 97 } 98 99 100 protected javax.swing.JPanel createRootPanel() { 101 javax.swing.JPanel rootPanel = new javax.swing.JPanel (); 102 rootPanel.setBackground(java.awt.Color.white); 104 rootPanel.setForeground(java.awt.Color.blue); 105 lMessage = new javax.swing.JTextArea ("Please wait..........."); 106 rootPanel.add(lMessage); 107 return rootPanel; 108 } 109 110 111 private class HelloTimer implements Runnable { 112 113 public void run() { 114 while (shouldRun) { 115 lMessage.setText(activeHello.sayHello()); 116 try { 117 Thread.sleep(1000); 118 } catch (InterruptedException e) {} 119 } 120 } 121 } 122 } 123 | Popular Tags |