0

私が 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  

私は何を間違っていますか??

4

2 に答える 2

2

Java アプレットはメインでは実行されないため、init が必要です。JApplet も拡張する必要があります。

javax.swing.JApplet をインポートします。

public class PegaIP はアプレットを拡張します

public void init() は public static void main(String[] args) を置き換えます

リソースは次の場所にあります: http://docs.oracle.com/javase/tutorial/deployment/applet/getStarted.html

于 2012-11-21T16:24:23.997 に答える
1

これはコードであり、私にとってはうまく機能します:

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");
        }
    }
}

みんな助けてくれてありがとう...

于 2012-11-22T00:50:29.913 に答える