问题描述
有个程序代码是这样的:importjava.awt.*;importjava.awt.event.*;importjava.net.*;importjava.io.*;publicclassClientextendsWindowAdapterimplementsActionListener,KeyListener{Framef;TextFieldstr_send;Labellabel;TextAreamsg;Buttonsend,exit;Panelp1;Stringhostname;DatagramSocketreceiveSocket,sendSocket;DatagramPacketreceivePacket,sendPacket;publicvoiddisplay(){Framef=newFrame("山顶风");Imageico=Toolkit.getDefaultToolkit().getImage("红心.png");f.setIconImage(ico);f.setSize(400,350);f.setLocation(100,100);f.setBackground(Color.red);p1=newPanel();f.add(p1,"South");msg=newTextArea();msg.setSize(100,250);msg.setBackground(Color.WHITE);msg.setEditable(false);f.add(msg);label=newLabel("发送消息");p1.add(label);str_send=newTextField(20);p1.add(str_send);str_send.addKeyListener(this);send=newButton("发送");p1.add(send);send.addActionListener(this);exit=newButton("退出");p1.add(exit);exit.addActionListener(this);f.addWindowListener(this);f.setVisible(true);try{sendSocket=newDatagramSocket(3000);}catch(Exceptione){msg.append(e+"tn");}}publicvoidreceiveMessage(){try{receiveSocket=newDatagramSocket(3001);while(true){byte[]buf=newbyte[500];receivePacket=newDatagramPacket(buf,buf.length);//receivePacket=newDatagramPacket(buf,buf.length);receiveSocket.receive(receivePacket);ByteArrayInputStreambin=newByteArrayInputStream(receivePacket.getData());BufferedReaderreader=newBufferedReader(newInputStreamReader(bin));msg.append("服务器:"+reader.readLine());msg.append("tn");reader.close();bin.close();}}catch(Exceptione){msg.append(e+"n");}}publicvoidsendMessage(){try{ByteArrayOutputStreambout=newByteArrayOutputStream();PrintStreampout=newPrintStream(bout);pout.print(str_send.getText());bytebuf[]=bout.toByteArray();sendPacket=newDatagramPacket(buf,buf.length,InetAddress.getByName(hostname),3333);sendSocket.send(sendPacket);msg.append("客户端:"+str_send.getText()+"tn");str_send.setText("");}catch(Exceptionerr){msg.append(err+"tn");}}publicvoidactionPerformed(ActionEvente){if(e.getSource()==send){sendMessage();}elseif(e.getSource()==exit){System.out.println("程序已经关闭,再见!!");System.exit(0);}}publicvoidwindowClosing(WindowEvente){System.out.println("聊天程序已经关闭,再见!!!");System.exit(0);}publicvoidkeyPressed(KeyEvente){if(e.getSource()==str_send){if(e.getKeyChar()==KeyEvent.VK_ENTER){sendMessage();}}}/*publicClient(){//Clientclient=newClient();display();receiveMessage();}*/publicstaticvoidmain(Stringargs[]){Clientclient=newClient();client.display();client.receiveMessage();}publicvoidkeyTyped(KeyEvente){}publicvoidkeyReleased(KeyEvente){}}然后我想在另一个程序里面实现这个程序的所有函数,即所有方法,功能怎么解决啊??
解决方案
解决方案二:
完全不知在说些什么...
解决方案三:
-.-||楼主还想实现什么方法?你该实现的不是已经实现了嘛
解决方案四:
对于这个类中的每一个方法,LZ可以看好他们的参数都是什么,在其他的类中调用时可以通过可参数赋值的方式来弄。
解决方案五:
比如说我有另一个程序Client我想在Client里面实现上面那个函数的所有功能怎么调用啊我现在这样调用newClient().display()运行Client时并没有完全实现上面的那个函数的所有功能
解决方案六:
代码太长了,没有时间看,出什么错?报什么错误堆栈?
解决方案七:
代码好长啊