📄 remoteclientapplet.java
字号:
package abrobot.abmobilerobot.clinet;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/**
* <p>Title: GOPDR</p>
* <p>Description: General Open Platform for Distributed Robot</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: SJTU</p>
* @author Hou Xueqiao
* @version 1.01
*/
import abrobot.*;
import abrobot.abmobilerobot.*;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import net.jini.discovery.LookupDiscovery;
import net.jini.discovery.DiscoveryListener;
import net.jini.discovery.DiscoveryEvent;
import net.jini.core.lookup.ServiceRegistrar;
import net.jini.core.lookup.ServiceTemplate;
import net.jini.core.discovery.LookupLocator;
import net.jini.core.lookup.ServiceRegistrar;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.XYConstraints;
public class RemoteClientApplet extends Applet {
private boolean isStandalone = false;
private MRWorldShowPanel WorldShowPanel=null;
private RobotControlPanel ControlPanel=null;
private AbRobotInterface Robot=null;
private SimpleControllerInterface Controller=null;
private TextArea textArea=new TextArea();
private XYLayout xYLayout1 = new XYLayout();
public void SetRobot(){
//Get JiniReggie
LookupLocator lookup = null;
ServiceRegistrar registrar = null;
if (System.getSecurityManager()==null){
System.setSecurityManager(new RMISecurityManager());
}
try {
lookup = new LookupLocator("jini://137.132.165.137");
} catch(java.net.MalformedURLException e) {
System.err.println("Lookup failed: " + e.toString());
System.exit(1);
}
try {
registrar = lookup.getRegistrar();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Registrar found");
//Lookup and get Robot
try{
Class [] classes = new Class[] {AbRobotInterface.class};
AbRobotInterface Robot = null;
ServiceTemplate template = new ServiceTemplate(null, classes,
null);
try {
Robot = (AbRobotInterface) registrar.lookup(template);
} catch(java.rmi.RemoteException e) {
e.printStackTrace();
}
if (Robot == null) {
System.out.println("Robot null");
return;
}
else{
//get Controller
try{
Class [] classes1 = new Class[] {SimpleControllerInterface.class};
ServiceTemplate template1 = new ServiceTemplate(null, classes1,
null);
try {
Controller = (SimpleControllerInterface) registrar.lookup(template1);
} catch(java.rmi.RemoteException e) {
e.printStackTrace();
}
if (Controller == null) {
System.out.println("Controller null");
return;
}
else{
ControlPanel= new RobotControlPanel (Controller);
WorldShowPanel=new MRWorldShowPanel(Robot,textArea);
}
}catch(Exception e){e.printStackTrace(); }
}
}catch(Exception e){e.printStackTrace();}
//Setup MRWorldShowPanel and ControlPanel
}
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Construct the applet
public RemoteClientApplet() {
}
//Initialize the applet
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
try{
SetRobot();
this.setBackground(Color.white);
this.setSize(800,600);
this.setLayout(xYLayout1);
if (WorldShowPanel!=null){
WorldShowPanel.setBounds(new Rectangle(0,0,640,480));
}
if (ControlPanel!=null){
ControlPanel.setBounds(new Rectangle(0,481,320,280 ));
}
textArea.setText("Info:");
textArea.setBounds(new Rectangle(321,490 ,320,100));
this.add(WorldShowPanel, new XYConstraints(0, 0, 645, 485));
this.add(textArea, new XYConstraints(321, 490, 320, 100));
this.add(ControlPanel, new XYConstraints(0, 490, 320, 100));
/*this.add(WorldShowPanel);
this.add(textArea);
this.add(ControlPanel);*/
WorldShowPanel.setVisible(true);
ControlPanel.setVisible(true);
textArea.setVisible(true);
}catch(Exception e){e.printStackTrace();}
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -