package l;//客户端
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.security.Key;
public class Q extends Frame{
PrintStream L;
Q F;
// BufferedWriter L;
Frame s=new Frame("客户端");
TextArea s1=new TextArea ();
TextField s2=new TextField();
public Q(){
s.setSize(500,500);
s.setVisible(true);
s.add(s1,BorderLayout.CENTER);
s.add(s2,BorderLayout.SOUTH);
s.pack();
s.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
super.windowClosing(e);
System.exit(0);
}
});
s2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
L.print(s2.getText());
s1.append(s2.getText()+"\n");
s2.setText("");
}
});
}
public void aa(){
try {
s1.append("等待与服务器连接"+"\n");
Socket s=new Socket("192.168.1.105",9080);
OutputStream S=s.getOutputStream();
// OutputStreamWriter SS=new OutputStreamWriter(S);
L=new PrintStream(S);
// L=new BufferedWriter(SS);
s1.append("服务器连接成功"+"\n");
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
s1.append("服务器连接失败"+"\n");
} catch (IOException e) {
// TODO Auto-generated catch block
s1.append("服务器连接失败"+"\n");
}
}
public static void main(String args[]){
Q F=new Q();
F.aa();
// F.pack();
}
}
吃鸡游戏