用集成的IDE或者是命令行都可以啊.

解决方案 »

  1.   


    import java.net.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class QQClient {
    String name;
    BufferedReader in;
    PrintWriter out;
    JTextField jtf;
    JTextArea jta;
    JComboBox jcb;
    public static void main(String[] args) {
    if (args.length==0 || args[0].equals("All")
    ||args[0].indexOf(":")!=-1){
    System.out.println("Error!");
    System.exit(0);
    }
    Socket s=null;
    try {
    s = new Socket("127.0.0.1",7755);
    QQClient client=new QQClient(s,args[0]);
    client.prepare();
    client.receive();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    public QQClient(Socket s,String name) throws Exception{
    this.name=name;
    this.in=new BufferedReader(new InputStreamReader(s.getInputStream()));
    this.out=new PrintWriter(s.getOutputStream());
    JFrame frame=new JFrame("Client "+name);
    frame.setSize(400,300);
    JPanel panel=new JPanel();
    this.jcb=new JComboBox();
    jcb.addItem("All");
    this.jtf=new JTextField(25);
    panel.add(jcb);
    panel.add(jtf);
    this.jta=new JTextArea();
    this.jta.setEditable(false);
    frame.getContentPane().add(new JScrollPane(jta));
    frame.getContentPane().add(panel,"South");
    frame.setVisible(true);
    frame.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent arg0) {
    end();
    }
    });

    this.jtf.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent arg0) {
    send();
    }
    });
    }
    void prepare() throws Exception{
    out.println("1:"+name+":");
    out.flush();
    }
    void end(){
    out.println("2:"+name+":");
    out.flush();

    System.exit(0);
    }
    void send(){
    String receiver=(String)(this.jcb.getSelectedItem());
    if (receiver==null) return;
    String text=this.jtf.getText();
    if ((text.indexOf(":"))!=-1){
    this.jtf.setText("");
    return;
    }
    out.println("3:"+receiver+":"+text);
    out.flush();
    this.jtf.setText("");
    }
    void receive(){
    while(true){
    try {
    String str=in.readLine();
    String[] info=parseString(str);
    if (info[0].equals("1")){
    this.jta.append(info[1]+" entered!"+"\n");
    this.jcb.addItem(info[1]);
    }
    else if (info[0].equals("2")){
    this.jta.append(info[1]+" exit!"+"\n");
    this.jcb.removeItem(info[1]);
    }
    else{
    this.jta.append(info[1]+" said:"+info[2]+"\n");
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }
    private String[] parseString(String s){
    String[] ss=new String[3];
    int i=0;
    StringTokenizer st=new StringTokenizer(s,":");
    while(st.hasMoreTokens()){
    ss[i]=st.nextToken();
    i++;
    }
    return ss;
    } }
    import java.net.*;
    import java.io.*;
    import java.util.*;
    public class QQServer {
    public static void main(String[] args) {
    ServerSocket ss=null;
    Map users=new HashMap();
    try {
    ss = new ServerSocket(7755);
    } catch (IOException e) {
    e.printStackTrace();
    }
    while(true){
    try {
    Socket s=ss.accept();
    Thread t=new ServerThread(s,users);
    t.start();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }}class ServerThread extends Thread{
    Socket s;
    String userName;
    Map users;
    BufferedReader in;
    PrintWriter out;

    public ServerThread(Socket s,Map m){
    this.s=s;
    this.users=m;
    try {
    this.in=new BufferedReader(new InputStreamReader(s.getInputStream()));
    this.out=new PrintWriter(s.getOutputStream());
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } }
    public void run(){
    while(true){
    try {
    String str=in.readLine();
    if (str==null) break;
    String[] info=parseString(str);
    if (info[0].equals("1")){
    this.userName=info[1];
    send(str,"All");
    this.users.put(userName,out);
    Iterator it=users.keySet().iterator();
    while(it.hasNext()){
    String user=(String)(it.next());
    send("1:"+user+":",userName);
    }
    }
    else if (info[0].equals("2")){
    send(str,"All");
    this.users.remove(info[1]);
    break;
    }
    else{
    String text="3:"+this.userName+":"+info[2];
    send(text,info[1]);
    }
    }  catch (Exception e) {
    // e.printStackTrace();
    return;
    }
    }

    }
    private String[] parseString(String s){
    String[] ss=new String[3];
    int i=0;
    StringTokenizer st=new StringTokenizer(s,":");

    while(st.hasMoreTokens()){
    ss[i]=st.nextToken();
    i++;
    }
    return ss;
    }
    private void send(String text,String receiver) throws Exception{
    PrintWriter o;
    if (receiver.equals("All")){
    Iterator it=users.keySet().iterator();
    while(it.hasNext()){
    String s=(String)(it.next());
    o=(PrintWriter)(users.get(s));
    o.println(text);
    o.flush();
    }
    }
    else{
    o=(PrintWriter)(users.get(receiver));
    o.println(text);
    o.flush();
    }
    }
    }
      

  2.   

    代码和IDE都有,就是弄不成功,郁闷死...
      

  3.   

     不知你用的是什么IDE,
    如果是用的netbean的话就很简单了,
    直点击打包就可以了,
      

  4.   

    1 、在eclipse里选中你的项目,右键,在弹出菜单里选择export;
    2、在弹出的对话框里选java,再选下面的Runnable JAR file,点下一步
    3、在Launch configuration里选着你要打包的项目,在Export destination里选着你要存放的路径
    4、完事点finish;就OK了
    不过你想要的别人的计算机上也能执行你的JAR包的话,这个细节就比较多了:
    1、 如果没有用到第三方JAR包,在别人电脑上只要装了jre基本上都能运行,如果不能运行的话,查看环境变量,并设置,基本上都可以;
    2、 如果用到第三方JAR的话,就要拷贝JAR到别人电脑上,或者在打包的第三步,里有个选项Library handing,选着后两个
    3、如果用到了第三方DLL文件,你必须拷贝DLL文件到别人电脑上的jre目录的lib目录下
    4、如果移植系统,比如linux的话,注意环境变量和运行权限,还有.so动态库
      

  5.   

    等我下个最新版的eclipse,试试了再说,TD-3G,要下到明天了
      

  6.   

    你都能远程了,还在乎是不是双击啊?java -verbose -jar ***.jar