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

📄 iruapplet.java

📁 Pioneer2机器人远程控制程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package abrobot.IRURobot.Client;
import abrobot.IRURobot.*;
import java.applet.Applet;
 import javax.media.rtp.*;
 import javax.media.rtp.rtcp.*;
 import javax.media.rtp.event.*;
 import com.sun.media.rtp.RTPSessionMgr;
 import java.io.*;
 import java.awt.*;
 import java.util.Vector;
 import java.net.*;
 import java.awt.event.*;
 import java.lang.String;
 import javax.media.*;
 import javax.media.protocol.*;
 import com.sun.media.*;
 import com.sun.media.ui.*;
 import java.io.IOException;
 import java.lang.SecurityException;
 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.XYLayout;
 import com.borland.jbcl.layout.XYConstraints;
 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 IRUApplet extends Applet implements
     ControllerListener, ReceiveStreamListener{

     /* For Robot Control */

     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;
      }
    }

     /* For video Control */
      InetAddress destaddr;
      String address;
      String portstr;
      String media;
      Player videoplayer = null;
      RTPSessionMgr videomgr = null;
      Component visualComponent = null;
      Component controlComponent = null;
      Panel Videopanel = null;
      GridBagLayout gridbag = null;
      GridBagConstraints c = null;
      int width = 320;
      int height =240;
      Vector playerlist = new Vector();
      SocketClientUDPAdapter UDPadapter;
      RTPManager rtpMgrs;


      //Initialize the applet
      public void init() {
         try {
            jbInit();
         }
         catch(Exception e) {
            e.printStackTrace();
         }
       }
     //Component initialization
     private void jbInit() throws Exception {
          // for video
           address="137.132.165.137";
           portstr="1200";
          StartSessionManager(address,StrToInt(portstr));
           if (videomgr == null){
               System.err.println("null video manager ");
               return;
           }

           //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(1,261,320,481 ));
               }
               //Videopanel=new Panel();
              // if(Videopanel!=null){
              //      repositionPanel(width, height);
             //  }
               xYLayout1.setWidth(800);
               xYLayout1.setHeight(600);
               this.add(SonarshowPanel,  new XYConstraints(321,0, 320, 240));
               this.add(ControlPanel,  new XYConstraints(1, 261, 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();
           }
     }

     public void start(){
          if (videoplayer != null){
              videoplayer.start();
          }
          if (playerlist == null)
              return;
          for (int i =0; i < playerlist.size(); i++){
              Player player = (Player)playerlist.elementAt(i);
              if (player != null)
                  new PlayerWindow(player);
          }
      }
      // applet has been stopped, stop and deallocate all the RTP players.
      public void stop(){
          if (videoplayer != null){
              videoplayer.close();
          }
          if (playerlist == null)
              return;
          for (int i =0; i < playerlist.size(); i++){
              Player player = (Player)playerlist.elementAt(i);
              if (player != null){
                  player.close();
              }
          }
      }

      public void destroy(){
          if (videomgr != null){
              videoplayer = null;
              videomgr = null;
          }
          super.destroy();
      }

      //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");

⌨️ 快捷键说明

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