⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testapplet.java

📁 Pioneer2机器人远程控制程序
💻 JAVA
字号:
package abrobot.IRURobot.Client;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import abrobot.*;
import abrobot.IRURobot.*;
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.*;

/**
 * <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
 */

public class TestApplet extends Applet {
  private boolean isStandalone = false;
  private AbRobotInterface Robot=null;
  private IRUControllerInterface Controller=null;
  private ControllerPanel ControlPanel=null;
  private SonarShowPanel SonarshowPanel=null;
  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[] {IRUControllerInterface.class};
        ServiceTemplate template1 = new ServiceTemplate(null, classes1,
            null);
        try {
          Controller = (IRUControllerInterface) registrar.lookup(template1);
        } catch(java.rmi.RemoteException e) {
          e.printStackTrace();
        }
        if (Controller == null) {
          System.out.println("Controller null");
          return;
        }
        else{
          ControlPanel= new  ControllerPanel (Controller);
          SonarshowPanel=new SonarShowPanel(Controller);

        }
        }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 TestApplet() {
  }
  //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 (SonarshowPanel!=null){
      SonarshowPanel.setBounds(new Rectangle(321,0, 320, 240));
    }
    if (ControlPanel!=null){
     ControlPanel.setBounds(new Rectangle(1, 241, 320, 240 ));

    }*/
    xYLayout1.setWidth(800);
      xYLayout1.setHeight(600);
    //  ControlPanel.setBackground(Color.gray);
      this.add(SonarshowPanel,  new XYConstraints(321,0, 320, 240));
      this.add(ControlPanel,  new XYConstraints(1, 241, 320, 240));




    SonarshowPanel.setVisible(true);
  ControlPanel.setVisible(true);



    }catch(Exception e){e.printStackTrace();}
  }
  //Get Applet information
  public String getAppletInfo() {
    return "Applet Information";
  }
  //Get parameter info
  public String[][] getParameterInfo() {
    return null;
  }
  //Main method
  public static void main(String[] args) {
    TestApplet applet = new TestApplet();
    applet.isStandalone = true;
    Frame frame;
    frame = new Frame() {
      protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
          System.exit(0);
        }
      }
      public synchronized void setTitle(String title) {
        super.setTitle(title);
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
      }
    };
    frame.setTitle("Applet Frame");
    frame.add(applet, BorderLayout.CENTER);
    applet.init();
    applet.start();
    frame.setSize(800,620);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
    frame.setVisible(true);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -