www.pudn.com > rmi_whiteboard.rar > WhiteboardFrame.java


package whiteboard; 
 
import java.awt.*; 
import java.awt.event.*; 
import java.util.Vector; 
import java.rmi.*; 
 
/** 
 * Sample application using Frame. 
 * 
 * @author  
 * @version 1.00 04/12/14 
 */ 
public class WhiteboardFrame extends Frame { 
     
    /** 
     * The constructor. 
     */   
     Panel p1; 
     CheckboxGroup cg; 
     Checkbox c1; 
     Checkbox c2; 
     Checkbox c3; 
     Checkbox c4; 
     Button   b1; 
      
     eboard board1; 
     CallBack callback1; 
     int callbackid; 
      
     mainframe_mouseAdapter ada1=new mainframe_mouseAdapter(this); 
     mainframe_mouseMotionAdapter ada2=new mainframe_mouseMotionAdapter(this); 
      
     public WhiteboardFrame(String hostname) { 
                 
        //this.setLayout(new FlowLayout()); 
                 
        MenuBar menuBar = new MenuBar(); 
        Menu menuFile = new Menu(); 
        MenuItem menuFileExit = new MenuItem(); 
         
        menuFile.setLabel("File"); 
        menuFileExit.setLabel("Exit"); 
         
        // Add action listener.for the menu button 
        menuFileExit.addActionListener 
        ( 
            new ActionListener() { 
                public void actionPerformed(ActionEvent e) { 
                    WhiteboardFrame.this.windowClosed(); 
                } 
            } 
        );  
        menuFile.add(menuFileExit); 
        menuBar.add(menuFile); 
         
        setTitle("Whiteboard"); 
        setMenuBar(menuBar); 
        setSize(new Dimension(600, 400)); 
         
        // Add window listener. 
        this.addWindowListener 
        ( 
            new WindowAdapter() { 
                public void windowClosing(WindowEvent e) { 
                    WhiteboardFrame.this.windowClosed(); 
                } 
            } 
        );  
         
        cg=new CheckboxGroup(); 
        c1=new Checkbox("pen",cg,true); 
        c2=new Checkbox("line",cg,false); 
        c3=new Checkbox("rect",cg,false); 
        c4=new Checkbox("circle",cg,false); 
         
        b1=new Button("clear"); 
        b1.addMouseListener(new button1_mouseAdapter(this)); 
        p1=new Panel();         
         
        p1.add(c1); 
        p1.add(c2); 
        p1.add(c3); 
        p1.add(c4); 
        p1.add(b1); 
        this.add(p1,BorderLayout.NORTH); 
         
 
        this.addMouseListener(ada1); 
        this.addMouseMotionListener(ada2);  
 
 
 
        if(System.getSecurityManager() == null) 
        { 
            System.setSecurityManager(new RMISecurityManager()); 
        }  
        else  
            System.out.println("Already has a security manager, so cant set RMI SM"); 
         
        try{ 
            //board1=new eboardServant(); 
            board1=(eboard)Naming.lookup("rmi://"+hostname+"/WhiteBoard"); 
            System.out.println("find remote object"); 
            callback1=new CallBackServant(this); 
            callbackid=board1.regist(callback1); 
            System.out.println("initiate call back success"); 
        }catch(Exception e) { 
            System.out.println(e.getMessage()); 
        }         
        //callback1=new CallBackServant(); 
    } 
     
    protected void whiteboardupdate() 
    { 
        try{ 
    	    Vector shapelist=board1.getall(); 
    	 
    	  
    	    for(int i=0;i