QuitButton.java



/** 終了の処理を行うクラス */
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.rmi.*;
public class QuitButton extends Button
                                implements ActionListener {

  /** Server の名前 */
    public String serverName;

  /** Receiver の名前 */
    public String receiverName;

  /** コンストラクタ */
    public QuitButton( String serverName, String receiverName )
                                  throws RemoteException {
        super( "Quit" );
        this.serverName = serverName;
        this.receiverName = receiverName;
        addActionListener( this );
    }

  /** アクションを処理するメソッド */
    public void actionPerformed( ActionEvent evt ) {
        try {
            TalkServer server
                = (TalkServer)Naming.lookup( serverName );
            server.removeMessageReceiver( receiverName );

            System.exit(0);
        }
        catch( Exception e ) {
            System.out.println( "Error:" + e.toString() );
        }
    }
}