0
我想了解我在Internet上看到的教程的源代碼(看起來有些過時)。在Applet類中,我從add(string,Component)部分得到一個錯誤。Applet錯誤:類型Container中的方法add(String,Component)不適用
的方法,該型容器中添加(字符串,組件)不適用於
爲什麼我不能使用添加以下代碼的參數(字符串,ChatClient)?
import java.applet.*;
import java.awt.*;
import java.io.*;
import java.net.*;
public class ClientApplet extends Applet
{
public void init() {
String host = getParameter("host");
int port = Integer.parseInt(getParameter("port"));
ChatClient client = new ChatClient(host,port);
setLayout(new BorderLayout());
add(client, "Center");
}
}
嗯它仍然有下加紅線。參數(ChatClient,String)不適用於參數(ChatClient,String) – jaycee 2014-11-21 16:24:56
*「'不適用於參數(ChatClient,String)''*代碼試圖添加一個小程序到同一個小程序的另一個實例。這是行不通的。順便說一句 - 該代碼不會編譯。爲了更快地獲得更好的幫助,請發佈[MCVE](http://stackoverflow.com/help/mcve)(最小完整可驗證示例)或[SSCCE](http://www.sscce.org/)(Short,Self Contained ,正確的例子)。 – 2014-11-21 22:44:29