我编写了几个程序并编译了其中一些程序,但我知道我编写了一个聊天信使程序。当我编译服务器或客户端时,我总是从 javac 中得到一个错误。“错误:找不到符号”。并且两个错误都在其他类的构造函数中,应该如何在那里构造。例子:
Chat.java:11 error: cannot find symbol
Frame frm = new Frame();
^
Symbol: class Frame
location: class Chat
Chat.java:11 error: cannot find symbol
Frame frm = new Frame();
^
Symbol: class Frame
location: class Chat
主要的
package main;
public class Chat {
public static void main(String args[]){
Frame frm = new Frame();
frm.setLayout(null);
frm.setVisible(true);
frm.setSize(800, 600);
frm.setResizable(false);
// a loop who wait for an true boolean
frm.abfrage();
while(true){
frm.readChat();
}
}
}
没有函数的FRAME类(只有构造函数)
package main;
//action + windowlistener + event import;
//Inputreader,writer,reader and IOException import;
//socket import + exception;
//.. there are some Javax.swing imports;
public class Frame extends JFrame {
Client client;
JPanel textPanel;
static boolean start;
static JTextArea messengerText;
JTextField writenText;
JTextField portInfo;
JTextField hostInfo;
JButton senden;
JButton connect;
public String writenString;
public String chatString;
int port;
String adress;
public Frame(){
super("Chat by lionlak");
// this.client = client;
client = new Client("localhost",5483);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
//Deklarationen
start = false;
writenString = "Hallo vom Client";
chatString = "Chat by lionlak";
//Konstruktoren
//JPanel
textPanel = new JPanel();
//JTextField
writenText = new JTextField();
portInfo = new JTextField();
hostInfo = new JTextField();
messengerText = new JTextArea();
//JButton
senden = new JButton("SENDEN");
connect = new JButton("Connect");
//Listener
senden.addActionListener(new actionListener());
connect.addActionListener(new actionListener());
addWindowListener(new windowHandler());
//Eigenschaften
//JPanel
textPanel.setLayout(null);
textPanel.setBounds(10,150,490,780);
//JTextField
portInfo.setBounds(120,10,100,40);
portInfo.setText("5483");
hostInfo.setBounds(10, 10, 100, 40);
hostInfo.setText("127.0.0.1");
messengerText.setBounds(0,0,380,290);
messengerText.setText(chatString);
writenText.setBounds(0, 310, 280, 100);
writenText.setText("Deine Nachricht!");
//JButton
senden.setBounds(290, 310, 100, 40);
connect.setBounds(230, 10, 100, 40);
//Add
textPanel.add(messengerText);
textPanel.add(writenText);
textPanel.add(senden);
add(hostInfo);
add(portInfo);
add(connect);
add(textPanel);
}