简体   繁体   中英

Java applet don't work in browser

People i make a java applet:

    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) { }
    }
}

and i received some error:

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  

what i do wrong??

Java applets do not run with the main, you need init. Must also extend JApplet.

import javax.swing.JApplet;

public class PegaIP extends Applet

public void init() replaces public static void main(String[] args)

A resource can be found here: http://docs.oracle.com/javase/tutorial/deployment/applet/getStarted.html

People this is code works fine for me:

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

Thanks everyone help me...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM