我不知道自己做错了什么,邮件实际上并未发送,也没有显示在邮件区域中。我无法弄明白。也许有人可以帮助我。 代码已编译但我没有收到错误。该计划根本不起作用。我能做些什么来使它工作并提高GUI的质量(让它存储我们写的东西)?
服务器:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ionutserver;
import static java.awt.SystemColor.text;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.text.BadLocationException;
/**
*
* @author Ionutz
*/
public class IonutServer {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException, BadLocationException {
JTextField areaMessage = new JTextField();
areaMessage.setBounds(10, 20, 150, 80);
JTextArea input = new JTextArea();
input.setBounds(10, 200, 150, 80);
JButton send = new JButton("Send");
send.setBounds(300, 100 , 100, 30);
JFrame frame = new JFrame("Server Ionut");
JPanel panel = new JPanel(null);
panel.add(areaMessage); panel.add(input);
panel.add(send); frame.add(panel); frame.setLocationRelativeTo(null); frame.setSize(600, 400); frame.setVisible(true);
ServerSocket s = new ServerSocket(100);
Socket s1= s.accept();
BufferedReader br = new BufferedReader(new InputStreamReader(
s1.getInputStream()));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
s1.getOutputStream()));
send.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(e.getSource() == send) {
try {
bw.write(input.getText());
bw.flush();
} catch (IOException ex) {
}
}
}
});
}
}

和客户:
package ionutclient;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.text.BadLocationException;
public class IonutClient {
public static void main(String[] args) throws IOException, BadLocationException {
JTextField areaMessage = new JTextField();
areaMessage.setBounds(10, 20, 150, 80);
JTextArea input = new JTextArea();
input.setBounds(10, 200, 150, 80);
JButton send = new JButton("Send");
send.setBounds(300, 100 , 100, 30);
JFrame frame = new JFrame("Client Ionut");
JPanel panel = new JPanel(null);
panel.add(areaMessage); panel.add(input);
panel.add(send); frame.add(panel); frame.setLocationRelativeTo(null); frame.setSize(600, 400); frame.setVisible(true);
Socket s = new Socket("192.161.0.100",100);
BufferedReader br = new BufferedReader(new InputStreamReader(
s.getInputStream()));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
s.getOutputStream()));
send.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(e.getSource() == send) {
try {
bw.write(input.getText());
bw.flush();
} catch (IOException ex) {
}
}
}
});
}
}