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

📄 iruapplet1.java

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

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
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.*;
import java.util.*;
/**
 * <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 IRUApplet1 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();


   private UpdateTask Updatetask=null;
   private Timer CoreTimer=null;
   class UpdateTask extends TimerTask{
     private ControllerPanel ControlPanel=null;
   private SonarShowPanel SonarshowPanel=null;
   public void run(){
     if (ControlPanel!=null) ControlPanel.UpdateInfo();
     if (SonarshowPanel!=null) SonarshowPanel.UpdateInfo();
   }
   public UpdateTask(ControllerPanel controlPanel,SonarShowPanel sonarshowPanel){
     ControlPanel=controlPanel;SonarshowPanel=sonarshowPanel;
   }

   }
  //Get a parameter value
  public String getParameter(String key, String def) {
    return isStandalone ? System.getProperty(key, def) :
      (getParameter(key) != null ? getParameter(key) : def);
  }
//Get JiniReggie
       public void SetRobot(){
            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
      }
  //Construct the applet
  public IRUApplet1() {
  }
  //Initialize the applet
  public void init() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  //Component initialization
  private void jbInit() throws Exception {

    //for robot
           try{
               SetRobot();
               this.setBackground(Color.white);
               this.setSize(800,600);
               this.setLayout(xYLayout1);
               if (SonarshowPanel!=null){
                   SonarshowPanel.setBounds(new Rectangle(321,0,641,240));
               }
               if (ControlPanel!=null){
                   ControlPanel.setBounds(new Rectangle(0,241,320,481 ));
               }

               xYLayout1.setWidth(800);
               xYLayout1.setHeight(600);
               this.add(SonarshowPanel,  new XYConstraints(321,0, 320, 240));
               this.add(ControlPanel,  new XYConstraints(1, 241, 320, 240));
              // this.add(Videopanel ,new XYConstraints(0, 0, 320, 240));
               SonarshowPanel.setVisible(true);
               ControlPanel.setVisible(true);
            //   Videopanel.setVisible(true);
               CoreTimer=new Timer();
               Updatetask=new UpdateTask(ControlPanel,SonarshowPanel);
               CoreTimer.schedule(Updatetask,500,500);
           }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 + -