如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
编写一个简易的聊天器程序,至少提供一个聊天内容显示文本域和一个发送消息的文本框界面,要求实现在发送信息框内填写内容并按下回车后,把该内容添加到上面的文本域内。packagecom;importjava.awt.FlowLayout;importjava.awt.LayoutManager;importjava.awt.event.FocusEvent;importjava.awt.event.FocusListener;importjava.awt.event.KeyAdapter;importjava.awt.event.KeyEvent;importjavax.swing.*;publicclassLtsdemoextendsJFrameimplementsFocusListener{staticfinalintf=300;staticfinalints=300;JLabell1,l2;JTextAreat1;JTextFieldt2;JPaneljp1,jp2,jp3;Ltsdemo(){super("聊天室程序");jp1=newJPanel();jp2=newJPanel();l1=newJLabel("接收消息");t1=newJTextArea(4,20);JScrollPanes2=newJScrollPane(t1,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);s2.addFocusListener(this);jp1.add(l1);jp1.add(s2);l2=newJLabel("输入消息");t2=newJTextField("发送内容",20);t2.addFocusListener(this);t2.addKeyListener(newKeyAdapter(){publicvoidkeyPressed(KeyEvente){if(e.getKeyChar()=='\n'){t1.setText(t1.getText()+"\n"+t2.getText());t2.setText("");//文本框清空}}});jp2.add(l2);jp2.add(t2);FlowLayoutf1=newFlowLayout();this.setLayout(f1);this.add(jp1);this.add(jp2);setSize(f,s);setDefaultCloseOperation(EXIT_ON_CLOSE);setVisible(true);}publicstaticvoidmain(Stringargs[]){Ltsdemos1=newLtsdemo();}publicvoidfocusGained(FocusEvente){if(e.getComponent()==t2){t2.setText("");//清空文本域;}}publicvoidfocusLost(FocusEvente){if(e.getComponent()==t2){t2.setText("发送消息");//清空文本域;}}}packageCOM;importjava.awt.FlowLayout;importjava.awt.event.FocusEvent;importjava.awt.event.FocusListener;importjava.awt.event.KeyAdapter;importjava.awt.event.KeyEvent;importjavax.swing.*;publicclassLtsextendsJFrameimplementsFocusListener{JLabels1,s2,s3;JTextFieldt1,t2,t3;JTextAreaa1;JButtonw1,w2;JPaneljp,jp1,jp2,jp3;Lts(StringTitle){setTitle("聊天室-客户端程序");jp=newJPanel();s1=newJLabel("服务器:");