1 31 package org.objectweb.proactive.examples.cruisecontrol; 32 33 import org.objectweb.proactive.core.config.ProActiveConfiguration; 34 35 44 public class CruiseControlApplet extends org.objectweb.proactive.examples.StandardFrame { 45 46 50 private CruiseControlPanel controlPane; 51 54 private CarPanel carPane; 55 58 private Interface activeObject; 59 60 61 public CruiseControlApplet(String name, int width, int height) { 62 super(name); 63 createActiveObject(); 64 init(width, height); 65 } 66 67 68 public static void main(String arg[]) { 69 ProActiveConfiguration.load(); 70 new CruiseControlApplet("Cruise Control", 840, 420); 71 } 72 73 74 76 82 public void createActiveObject() { 83 try { 84 activeObject = (Interface)org.objectweb.proactive.ProActive.turnActive(new Interface(this)); 85 } catch (Exception e) { 86 e.printStackTrace(); 87 System.exit(0); 88 } 89 activeObject.initialize(); 90 } 91 92 protected void start(){} 93 94 protected javax.swing.JPanel createRootPanel() { 95 javax.swing.JPanel rootPanel = new javax.swing.JPanel (new java.awt.GridLayout (1, 1)); 96 carPane = new CarPanel(this, activeObject); 97 controlPane = new CruiseControlPanel(this, activeObject); 98 javax.swing.JSplitPane horizontalSplitPane = new javax.swing.JSplitPane (javax.swing.JSplitPane.HORIZONTAL_SPLIT); 99 horizontalSplitPane.setDividerLocation(500); 100 horizontalSplitPane.setLeftComponent(carPane); 101 horizontalSplitPane.setRightComponent(controlPane); 102 rootPanel.add(horizontalSplitPane); 103 return rootPanel; 104 } 105 106 107 111 public void setDistance(double distance) { 112 carPane.setDistance(1000 * distance); 113 } 114 115 116 120 public void setSpeed(double speed) { 121 carPane.setSpeed(speed); 122 } 123 124 125 129 public void setDesiredSpeed(double m_speed) { 130 controlPane.setDesiredSpeed(m_speed); 131 repaint(); 132 } 133 134 135 138 public void engineOff() { 139 controlPane.controlOff(); 140 carPane.engineOff(); 141 } 142 143 144 public void engineOn() { 145 carPane.engineOn(); 146 } 147 148 152 public void setAlpha(double m_alpha) { 153 carPane.setAlpha(m_alpha); 154 } 155 156 157 public void setAcceleration(double m_acc) { 158 carPane.setAcceleration(m_acc); 159 } 160 161 162 public void controlPaneOff() { 163 controlPane.controlOff(); 164 } 165 166 167 public void brake() { 168 carPane.brake(); 169 } 170 171 172 public void controlOn() { 173 activeObject.controlOn(); 174 carPane.controlOn(); 175 controlPane.controlOn(); 176 } 177 178 179 public void controlOff() { 180 activeObject.controlOff(); 181 carPane.controlOff(); 182 controlPane.controlOff(); 183 } 184 } | Popular Tags |