JAVA小程序为初始化
客服端:importjava.net.*;importjava.io.*;importjava.awt.*;importjavax.swing.*;importjava....
客服端:
import java.net.*;
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.applet.*;
class Spanel extends Panel{
TextField msg_txt;
JButton button;
Spanel(){
setLayout(new FlowLayout());
msg_txt=new TextField(20);
button=new JButton("送出");
add(new JLabel("你说的话"));
add(msg_txt);
add(button);
}
}
public class chatClient extends Applet implements Runnable,ActionListener{
public static final int PORT=1008;
String name;
Socket socket;
DataOutputStream out;
DataInputStream in;
Thread thread;
TextArea chat_txt;
Spanel sp;
public void init(){
setBackground(new Color(230,230,200));
setLayout(new BorderLayout());
name=getParameter("Chatname");
chat_txt=new TextArea(10,45);
chat_txt.setEditable(false);
sp=new Spanel();
add("Center",chat_txt);add("SOUTH",sp);
sp.button.addActionListener(this);
chat_txt.setBackground(new Color(200,185,220));
}
public void start(){
try{
socket=new Socket(this.getCodeBase().getHost(),PORT);
in=new DataInputStream(socket.getInputStream());
out=new DataOutputStream(socket.getOutputStream());
}
catch(IOException e){}
chat_txt.append("★★★"+" "+name+",欢迎你来到聊天室 "+"★★★\n");
if(thread==null){
thread=new Thread(this);
thread.start();
}
}
public void run(){
try{
while(true){
chat_txt.append(in.readUTF()+'\n');
}
}
catch(IOException e){}
}
public void actionPerformed(ActionEvent e){
if((name!=null)){
try{
out.writeUTF(name+"说→"+":"+sp.msg_txt.getText());
sp.msg_txt.setText(null);
}
catch(IOException e1){}
}
}
}
服务器的不能一起传上来!哪个大虾加我啊! 展开
import java.net.*;
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.applet.*;
class Spanel extends Panel{
TextField msg_txt;
JButton button;
Spanel(){
setLayout(new FlowLayout());
msg_txt=new TextField(20);
button=new JButton("送出");
add(new JLabel("你说的话"));
add(msg_txt);
add(button);
}
}
public class chatClient extends Applet implements Runnable,ActionListener{
public static final int PORT=1008;
String name;
Socket socket;
DataOutputStream out;
DataInputStream in;
Thread thread;
TextArea chat_txt;
Spanel sp;
public void init(){
setBackground(new Color(230,230,200));
setLayout(new BorderLayout());
name=getParameter("Chatname");
chat_txt=new TextArea(10,45);
chat_txt.setEditable(false);
sp=new Spanel();
add("Center",chat_txt);add("SOUTH",sp);
sp.button.addActionListener(this);
chat_txt.setBackground(new Color(200,185,220));
}
public void start(){
try{
socket=new Socket(this.getCodeBase().getHost(),PORT);
in=new DataInputStream(socket.getInputStream());
out=new DataOutputStream(socket.getOutputStream());
}
catch(IOException e){}
chat_txt.append("★★★"+" "+name+",欢迎你来到聊天室 "+"★★★\n");
if(thread==null){
thread=new Thread(this);
thread.start();
}
}
public void run(){
try{
while(true){
chat_txt.append(in.readUTF()+'\n');
}
}
catch(IOException e){}
}
public void actionPerformed(ActionEvent e){
if((name!=null)){
try{
out.writeUTF(name+"说→"+":"+sp.msg_txt.getText());
sp.msg_txt.setText(null);
}
catch(IOException e1){}
}
}
}
服务器的不能一起传上来!哪个大虾加我啊! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询