KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > examples > philosophers > AppletPhil


1 /*
2 * ################################################################
3 *
4 * ProActive: The Java(TM) library for Parallel, Distributed,
5 * Concurrent computing with Security and Mobility
6 *
7 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8 * Contact: proactive-support@inria.fr
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * Initial developer(s): The ProActive Team
26 * http://www.inria.fr/oasis/ProActive/contacts.html
27 * Contributor(s):
28 *
29 * ################################################################
30 */

31 package org.objectweb.proactive.examples.philosophers;
32
33 import org.objectweb.proactive.core.config.ProActiveConfiguration;
34
35 public class AppletPhil extends org.objectweb.proactive.examples.StandardFrame {
36
37   // private javax.swing.JButton bStart;
38
private String JavaDoc url;
39   private DinnerLayout theLayout;
40   private javax.swing.JPanel JavaDoc theLayoutPanel;
41
42   public AppletPhil(String JavaDoc name, int width, int height) {
43     super(name, width, height);
44   }
45
46   public static void main(String JavaDoc args[]) {
47     ProActiveConfiguration.load();
48     AppletPhil phil = new AppletPhil("Philosophers", 450, 300);
49     phil.receiveMessage("Applet running...");
50     if (args.length == 1) {
51       phil.setURL(args[0]);
52     }
53     phil.go();
54   }
55
56   private void go() {
57     try {
58       /* le Layout est necessairement actif, puisqu'il est referenc? par tous les autres objets.
59        */

60       theLayout = (DinnerLayout) org.objectweb.proactive.ProActive.turnActive(theLayout);
61       if (url != null)
62         theLayout.setNode(url);
63       /*
64        * Builds the active Table and Philosophers:
65        */

66       org.objectweb.proactive.ProActive.waitFor(theLayout.init());
67       theLayout.activateButtons();
68       receiveMessage("Objects activated...");
69     } catch (Exception JavaDoc ex) {
70       ex.printStackTrace();
71     }
72   }
73
74   public void setURL(String JavaDoc url) {
75     this.url = url;
76   }
77
78   /* Called by AppletWrapper before creating the toplevel Frame: */
79   protected void start() {
80   }
81
82   //
83
// -- PROTECTED METHODS -----------------------------------------------
84
//
85
/* createRootPanel:
86    * abstract method of AppletWrapper.
87    * result: the JPanel to be inserted in the upper part of the Main Frame.
88    */

89
90   protected javax.swing.JPanel JavaDoc createRootPanel() {
91     // Get the images
92
javax.swing.Icon JavaDoc imgArray[] = new javax.swing.Icon JavaDoc[5];
93     try {
94       ClassLoader JavaDoc c = this.getClass().getClassLoader();
95       imgArray[0] = new javax.swing.ImageIcon JavaDoc(c.getResource("org/objectweb/proactive/examples/philosophers/think.gif"));
96       imgArray[1] = new javax.swing.ImageIcon JavaDoc(c.getResource("org/objectweb/proactive/examples/philosophers/wait.gif"));
97       imgArray[2] = new javax.swing.ImageIcon JavaDoc(c.getResource("org/objectweb/proactive/examples/philosophers/eat.gif"));
98       imgArray[3] = new javax.swing.ImageIcon JavaDoc(c.getResource("org/objectweb/proactive/examples/philosophers/fork0.gif"));
99       imgArray[4] = new javax.swing.ImageIcon JavaDoc(c.getResource("org/objectweb/proactive/examples/philosophers/fork1.gif"));
100     } catch (Exception JavaDoc e) {
101       e.printStackTrace();
102     }
103     // the DinnerLayout constructor creates the graphical objects:
104
theLayout = new DinnerLayout(imgArray);
105     return theLayout.getDisplay();
106   }
107 }
Popular Tags