77范文网 - 专业文章范例文档资料分享平台

基于远程方法调用的聊天室软件设计与实现—毕业论文(5)

来源:网络收集 时间:2019-02-15 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

System.out.println(\ e.printStackTrace(); } }

图5.1服务器端启动

5.2.2客户端设计 (1)界面设计

public class SwingChatv2Client extends UnicastRemoteObject implements Chatv2Client,ActionListener{

Chatv2Server server=null;//界面的设计 boolean connected=false; String title=\ JFrame f;

String username=\ JTextArea area; JTextField inName; JButton connect; JButton disconnect; JButton send; JButton info;

JTextField contentIn; private ActionListener change;

public SwingChatv2Client() throws RemoteException{ super();

//System.setSecurityManager(new RMISecurityManager());

}

public void init(){

//setLayout(new BorderLayout());//界面的设计参数 f=new JFrame(title);

f.setBounds(250,250,500,500); f.setVisible(true);

JPanel pNorth,pSouth,pText; pNorth=new JPanel(); pSouth=new JPanel(); pText=new JPanel();

inName=new JTextField(6); contentIn=new JTextField(22); area=new JTextArea(15,35);

connect=new JButton(\

disconnect=new JButton(\ send=new JButton(\ info=new JButton(\

pNorth.add(new JLabel(\ pNorth.add(inName); pNorth.add(connect); pNorth.add(disconnect);

pSouth.add(new JLabel(\ pSouth.add(contentIn); pSouth.add(send); pSouth.add(info);

pText.add(new JScrollPane(area)); connect.addActionListener(this); disconnect.addActionListener(this); send.addActionListener(this); info.addActionListener(this);

contentIn.addActionListener(this); f.add(pNorth,BorderLayout.NORTH); f.add(pSouth,BorderLayout.SOUTH); f.add(pText,BorderLayout.CENTER);

f.validate();

f.addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e){ System.exit(0); } }); /*try{

UnicastRemoteObject.export(this); }

catch(Exception e){

}*/ }

public static void main(String args[])throws RemoteException{

SwingChatv2Client client=new SwingChatv2Client(); client.init();

}

public void connect(){ try{

server=(Chatv2Server)Naming.lookup(\r\客户端连接

//此处localhost可改为服务端所在主机IP

//server=(IChatServer)Naming.lookup(\r\

System.out.println(\ connected=true; setStatus();

username=inName.getText().trim(); server.addClient(this,username+\Entered!\

} catch(Exception e){

area.append(\ //area.append(\ connected=false; setStatus();

server=null;

System.out.println(e); } }

public void disconnect(){ try{

if(server==null) return;

server.removeClient(this,username+\ server=null; }

catch(Exception e){

area.append(\ int length = area.getText().length(); area.setCaretPosition(length); }

finally{

connected=false; setStatus(); } }

/*Add some other information by this button!*/ public void info(){ try{

if(server==null) return;

server.checkinfosavve(this); }

catch(Exception e){ } }

public void actionPerformed(ActionEvent e){//按钮事件函数 if(e.getSource()==connect){ //连接函数 connect(); }

else if(e.getSource()==info){ info(); }

else if(e.getSource()==disconnect){ //断开连接 disconnect(); } else if(e.getSource()==send){ //send function //else if(e.getSource()==contentIn){ if(server==null)

return; try{

String news=contentIn.getText(); server.sendMessage(this,news);

server.savve(this, inName.getText().trim(), news); contentIn.setText(\ } catch(Exception ee){

area.append(\ int length = area.getText().length(); area.setCaretPosition(length); } } else{

if (server==null) return;

try{ server.sendMessage(this,contentIn.getText()); contentIn.setText(\ }

catch(Exception ex){

area.append(\ int length = area.getText().length(); area.setCaretPosition(length);

}

public void setStatus(){ if(connected)

f.setTitle(title+\ else

f.setTitle(title+\ }

public String getName() throws RemoteException{ return username; }

public void sendMessage(String msg) throws RemoteException{ area.append(msg+\

int length = area.getText().length(); area.setCaretPosition(length); (3)客户端界面

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库基于远程方法调用的聊天室软件设计与实现—毕业论文(5)在线全文阅读。

基于远程方法调用的聊天室软件设计与实现—毕业论文(5).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/467176.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: