konow;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.ServerSocket;
import java.Socket;
import java.UnknownHostException;
import android.app.Activity;
t.Intent;
aphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class chat extends Activity {
Intent intent0=new Intent();
private DataInputStream in=null;
//private DataOutputStream out=null;
private BufferedWriter out=null;
private Handler messageHandler;
String minput=null;
String moutput="";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
Create(savedInstanceState);
setContentView(R.layout.chat);
Bundle bundle=new Bundle();
bundle=getIntent().getExtras();
String String("name");
TextView text1=(TextView) findViewById(R.id.tittle);
final EditText input=(EditText) findViewById(R.id.chat_input);
Button send=(Button) findViewById(R.id.send);
text1.setText("与"+name+"聊天中");
Looper looper = Looper();
messageHandler = new MessageHandler(looper);
Socket socket;
try {
socket = new Socket("10.0.2.2",8192);
out = new BufferedWriter(new OutputStream(),"GBK"));
in=new InputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
send.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Text().toString();
try {
out.write(minput);
out.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
new Thread(mRunnable).start();
java模拟器怎么用 }
private Runnable mRunnable = new Runnable()
{
public void run() {
while(true){
try {
String msg="";
if((adUTF())!=null){
Message message = Message.obtain();
message.obj = msg;
messageHandler.sendMessage(message);
System.out.println("msg1"+msg);
}
System.out.println("msg2"+msg);
} catch (Exception e) {
e.printStackTrace();
}
}
}
};
class MessageHandler extends Handler {
public MessageHandler(Looper looper) {
super(looper);
}
@Override
public void handleMessage(Message msg) {
//处理收到的消息,把天气信息显示在title上
TextView text=(TextView) findViewById(R.id.chat_output);
moutput+=(String) msg.obj+"\n";
text.setText(moutput);
text.setTextColor(Color.BLACK);
//setTitle((String) msg.obj);
}
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ( keyCode == KeyEvent.KEYCODE_BACK)
{
try
{
if(out!=null)out.close();
if(in!=null)in.close();
//if(mSocket!=null)mSocket.close();
}
catch(Exception e)
{
e.printStackTrace();
}
this.finish();
return true;
}
KeyDown(keyCode, event);
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论