我編程幾個方案,我已經整理了一些人,但知道我有編程的聊天信使。當我編譯服務器或客戶端時,我總是從javac中得到一個錯誤。 「錯誤:找不到符號」。而這兩個錯誤都是在其他類的構造函數中應該如何構造的。 例如: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();
}
}
}
框架類無功能(僅構造函數)
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);
}
import java.awt.Frame; –
您需要包含更多信息。例如,使用「Frame」的代碼。目前,大多數人認爲你指的是'java.awt.Frame',但有可能你不是。 –
我的建議是:使用像Eclipse這樣的IDE,它會有所幫助。顯然,學習足夠的Java來理解基礎。 – logoff