gpt4 book ai didi

java - 编译时出错

转载 作者:行者123 更新时间:2023-12-01 10:35:34 24 4
gpt4 key购买 nike

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)类 Serverchat ...。此外,您有一个右大括号排除了 ActionListener 的实现,java.net.Server 未定义。

关于java - 编译时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34765170/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com