大侠,您好:
我写了一个Java的聊天工具的界面,代码如下:
package Client;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
//创建ChatClient类作为聊天窗口;
public class Complete_ChatForeUIDoctorClient extends JFrame implements WindowListener,KeyListener,ItemListener, ActionListener
{
private static final long serialVersionUID = 1L;
static Integer ChatPartnerSerialMark = 200;
Integer ChatFriNum = 200;
static DataOutputStream dops3 = null;
JPanel jp = new JPanel();
static DataInputStream dips3 = null;
boolean started = false;
InetAddress addr = null;
String title = "获取好友资料";
String chatword = null;
Dialog ordernum = new Dialog(this,title,started);
String str;
int T =0;
public static String UIDLocal = null;
static String roleLocal = null;
static String iPAddressLocal = null;
String Local_Doctor_facia = null;
Integer MyLocalSysNum = -1;
static String MyChatObjrolE = null;
JPanel jp1 = new JPanel();
JTextArea Jta2 = new JTextArea();
String DoctorFuct = null;
JTextArea Jta1 = new JTextArea();
OutputStream outputstream = null;
//CaptureScreen capScreen = new CaptureScreen();
public Complete_ChatForeUIDoctorClient(String UID,Integer MySysPriNum,String Doctor_facia,Integer ChatObjectNum,String ChatObjrolE,String MyIP){
System.out.println("C端Complete_ChatForeUIDoctorClient");
UIDLocal = UID;
MyLocalSysNum = MySysPriNum;
roleLocal = "Doctor";
str = Doctor_facia;
this.setTitle(str);
ChatPartnerSerialMark = ChatObjectNum;
MyChatObjrolE = ChatObjrolE;
iPAddressLocal = MyIP;
//TODO:
Jta2.addKeyListener(this);
Jta1.setLineWrap(true); //如果加上这一句,那么水平方向的滚动条永远不会出现。
Jta1.setEditable(false);
JScrollPane jspanel=new JScrollPane(Jta1);
jspanel.add(Jta1);
this.add(jspanel);
setSize(300, 300);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void start() {
JScrollPane panel = new JScrollPane(Jta1);
panel.setPreferredSize (new Dimension (600,400));
this.setBounds(new Rectangle(419,92,590,550));
jp1.setLayout(null);
Jta1.setBounds(new Rectangle(28,10,500,220));
Jta1.setLineWrap(true);//激活自动换行功能
Jta2.setLineWrap(true);
Jta1.setWrapStyleWord(true);//激活断行不断字功能
Jta2.setBounds(new Rectangle(28,280,500,220));
panel.setVisible(true);
jp1.add(Jta2);
jp1.add(Jta1);
jp1.add(panel);
this.add(jp1);
this.setVisible(true);
}
@Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
public static void main(String[] args){
new Complete_ChatForeUIDoctorClient("测试账户0",0,"加油!!加油!!",2,"Doctor","222.196.1.8").start();
}
@Override
public void windowOpened(WindowEvent e)
{
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
if(e.isControlDown()&&e.getKeyCode()==KeyEvent.VK_ENTER){