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 小程序不与 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

于 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 回答