[英]Error during the compilation [duplicate]
这个问题已经在这里有了答案:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.Server;
import java.net.InetAddress;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JFrame;
public class Serverchat extends JFrame implements ActionListener {
static ServerSocket ser;
static Socket conn;
JFrame Frame;
JButton Send;
JPanel Panel1;
JTextField Msg;
JTextArea History;
DataInputStream dis;
DataOutputStream dos;
public Serverchat() throws IOException {
dis = new DataInputStream();
dos = new DataOutputStream();
ser = new ServerSocket();
conn = new Server();
Panel1 = new JPanel();
Msg = new JTextField();
History = new JTextArea();
Send = new JButton("Send");
Send.setBackground(Color.blue);
Frame = new JFrame("Server Side Chatting");
this.setSize(500, 500);
this.setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
History.setBounds(20, 20, 450, 360);
Panel1.add(History);
Msg.setBounds(20, 400, 340, 30);
Panel1.add(Msg);
Send.setBounds(375, 400, 95, 30);
Panel1.add(Send);
Send.addActionListener(this);
ser = new ServerSocket(InetAddress.getLocalHost());
ser = new ServerSocket(8080);
History.setText("Connection In Progress....");
History.setText(History.getText() + '\n' + "Finding The Client....");
try {
conn = ser.accept();
History.setText(History.getText() + '\n' + "Client Found");
DataInputStream dis = new DataInputStream(conn.getInputStream());
String Message = dis.readUTF();
History.setText(History.getText() + '\n' + " Client " + Message);
} catch (IOException e) {
History.setText(History.getText() + "\n" + "Error in Connection");
History.setText(History.getText() + "\n" + "Please Try Again or Exit");
}
}
}
public void actionPerformed(ActionEvent event) {
if (( event.getSource() == Send ) && (Message != " ") {
History.setText(History.getText()+ '\n' + "Me :" +Message.getText());
try {
DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
dos(Message.getText());
}
catch (IOException e2 ){}
public static void main(String[] args) throws IOException {
new Serverchat();
}
基本上,这是客户端聊天Java应用程序的服务器端。 在编译过程中会发生如下这样的错误:
error: class, interface, or enum expected
public Class Serverchat extends JFrame implements ActionListener
^
Serverchat.java:22: error: class, interface, or enum expected
JTextArea History;**
请帮助消除错误。
Java区分大小写。 尝试使用public class Serverchat …
。 此外,您还有一个右括号,不包括ActionListener
的实现,因此java.net.Server
是未定义的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.