[英]Java applet don't work in browser
我做一個Java小程序的人:
import java.net.InetAddress;
public class PegaIP {
public static void main(String[] args) {
try {
getAppletContext().showDocument
(new URL("javascript:UpdateIP(\"" + InetAddress.getLocalHost().getHostAddress() + "\")"));
} catch (Exception e) { }
}
}
我收到一些錯誤:
Plug-in 10.9.2.05 do Java
Usando versão JRE 1.7.0_09-b05 Java HotSpot(TM) Client VM
Diretório home do usuário = C:\Users\Edilsom
c: limpar janela da console
f: concluir objetos da fila de finalização
g: coleta de lixo
h: exibir esta mensagem de ajuda
l: descartar lista de carregadores de classes
m: imprimir uso de memória
o: log do trigger
q: ocultar console
r: recarregar configuração da política
s: descartar propriedades do sistema e de implantação
t: descartar lista de threads
v: descartar pilha de threads
x: limpar cache do carregador de classes
0-5: definir nível de rastreamento como <n>
Match: beginTraversal
Match: digest selected JREDesc: JREDesc[version 1.6+, heap=-1--1, args=null, ref=http://java.sun.com/products/autodl/j2se, sel=false, null, null], JREInfo: JREInfo for index 0:
platform is: 1.7
product is: 1.7.0_09
location is: http://java.sun.com/products/autodl/j2se
path is: C:\Program Files (x86)\Java\jre7\bin\javaw.exe
args is: null
native platform is: Windows, x86 [ x86, 32bit ]
JavaFX runtime is: JavaFX 2.2.3 found at C:\Program Files (x86)\Java\jre7\
enabled is: true
registered is: true
system is: true
Match: ignoring maxHeap: -1
Match: ignoring InitHeap: -1
Match: digesting vmargs: null
Match: digested vmargs: [JVMParameters: isSecure: true, args: ]
Match: JVM args after accumulation: [JVMParameters: isSecure: true, args: ]
Match: digest LaunchDesc: null
Match: digest properties: []
Match: JVM args: [JVMParameters: isSecure: true, args: ]
Match: endTraversal ..
Match: JVM args final:
Match: Running JREInfo Version match: 1.7.0.09 == 1.7.0.09
Match: Running JVM args match: have:<> satisfy want:<>
CacheEntry[http://localhost/3gloja/pegaip.class]: updateAvailable=true,lastModified=Tue Nov 20 22:46:40 GMT-03:00 2012,length=780
我做錯了什么?
Java applet不能與main一起運行,需要init。 還必須擴展JApplet。
導入javax.swing.JApplet;
公共類PegaIP擴展了Applet
public void init()替換了public static void main(String [] args)
可以在這里找到資源: http : //docs.oracle.com/javase/tutorial/deployment/applet/getStarted.html
這個代碼對我來說很好的人:
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import javax.swing.JApplet;
public class PegaIP extends JApplet {
@Override
public void init() {
try {
getAppletContext().showDocument (new URL("javascript:UpdateIP(\"" + InetAddress.getLocalHost().getHostAddress() + "\")"));
} catch (UnknownHostException | MalformedURLException e) {
System.err.println("Ocorreu erro na criação da GUI");
}
}
}
謝謝大家幫我...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.