AccessButton.java



/** 会話への参加の処理を行うクラス */
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.rmi.*;
public class AccessButton extends Button
                          implements ActionListener {

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

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

  /** TalkServerListのオブジェクト */
    public TalkServerList list;

  /** コンストラクタ */
    public AccessButton( TalkServerList list )
                                  throws RemoteException {
        super( "Access" );
        this.list = list;
        addActionListener( this );
    }

  /** アクションを処理するメソッド */
    public void actionPerformed( ActionEvent evt ) {
        try {
            String serverName
                = "rmi://" + list.list.getSelectedItem();
            TalkServer server
                = (TalkServer)Naming.lookup( serverName );
            InetAddress host = InetAddress.getLocalHost();
            String hostName = host.getHostName();
            String receiverName = "rmi://" + hostName + "/MessageReceiver";
            String nickName = System.getProperty( "user.name" );

            MessageClient3 client
               = new MessageClient3( serverName, receiverName, nickName );
        }
        catch( Exception e ) {
            System.out.println( "Error:" + e.toString() );
        }
    }
}