编译期间出错

时间:2016-01-13 11:12:59

标签: java swing enums compilation try-catch

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;**

请帮助您删除错误。

1 个答案:

答案 0 :(得分:1)

Java区分大小写。试试public class Serverchat …。此外,您有一个结束括号,不包括ActionListener的实现,java.net.Server未定义。