0

ゲームをロードしているJavaアプリケーションを持っていて、それをアプレットにしてhtml Webページにロードしようとしましたが、ロードしようとするとエラーが発生してロードされません。誰かお願いします私を助けて、私が間違っていることを教えてください。

Java アプリケーション コード:

import java.applet.*;
import java.awt.Dimension;
import java.io.*;
import java.net.*;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.*;

public class OSRSLoader
    implements AppletStub
{
    static JMenuBar menubar;
    static JFrame i;

    public static void main(String args[])
        throws Exception
    {
        new OSRSLoader();
    }

    public OSRSLoader()
        throws Exception, FileNotFoundException
    {
        JFrame i = new JFrame("RS Oldschool Client Beta V1:00");

        i.setSize(new Dimension(763, 514));
        i.setPreferredSize(new Dimension(763, 514));
        JLabel label = new JLabel();
        ImageIcon icon = new ImageIcon(new URL("http://www.runescape.com/image/rsp777/oldschool_ani.gif"));
        icon.setImageObserver(null);
        label.setIcon(icon);
        i.add(label);
        i.pack();
        i.setVisible(true);
        String str = getPageSource(new URL("http://oldschool38.runescape.com"));
        Pattern pattern = Pattern.compile("gamep\\w+");
        Matcher match = pattern.matcher(str);
        if(match.find())
        {
            OSRSLoader stub = new OSRSLoader(Pattern.compile("<param name=\"([^\\s]+)\"\\s+value=\"([^>]*)\">"), str);
            Download("http://oldschool38.runescape.com/", (new StringBuilder(String.valueOf(match.group(0)))).append(".jar").toString());
            stub.setCodeBase(new URL((new StringBuilder("http://oldschool38.runescape.com/")).append(match.group(0)).append(".jar").toString()));
            stub.setDocumentBase(new URL((new StringBuilder("http://oldschool38.runescape.com/")).append(match.group(0)).append(".jar").toString()));
            stub.getParameter((String)parameters.get("java_arguments"));
            URLClassLoader classLoader = new URLClassLoader(new URL[] {
                new URL("file:gamepack.jar")
            });
            Applet applet = (Applet)classLoader.loadClass("client").newInstance();
            applet.setStub(stub);
            applet.setSize(new Dimension(763, 514));
            applet.init();
            applet.start();
            i.add(applet);
            i.pack();
            i.setDefaultCloseOperation(3);
            label.setVisible(false);
        }
    }



    public OSRSLoader(Pattern parameterPattern, String frameSource)
    {
        String key;
        String value;
        for(Matcher param = parameterPattern.matcher(frameSource); param.find(); System.out.println((new StringBuilder("Parameter Loaded. Key = ")).append(key).append(", value =").append(value).toString()))
        {
            key = param.group(1);
            value = param.group(2);
            parameters.put(key, value);
        }

    }

    private String getPageSource(URL url)
        throws IOException, InterruptedException
    {
        URLConnection cn = url.openConnection();
        cn.addRequestProperty("Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
        cn.addRequestProperty("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
        cn.addRequestProperty("Accept-Encoding", "gzip,deflate");
        cn.addRequestProperty("Accept-Language", "en-gb,en;q=0.5");
        cn.addRequestProperty("Connection", "keep-alive");
        cn.addRequestProperty("Host", "www.runescape.com");
        cn.addRequestProperty("Keep-Alive", "300");
        cn.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:9.0.1) Gecko/20100101 Firefox/9.01");
        DataInputStream di = new DataInputStream(cn.getInputStream());
        byte tmp[] = new byte[cn.getContentLength()];
        di.readFully(tmp);
        di.close();
        Thread.sleep(250 + (int)Math.random() * 500);
        return new String(tmp);
    }

    public void appletResize(int i, int j)
    {
    }

    public void setCodeBase(URL codeBase)
    {
        this.codeBase = codeBase;
    }

    public void setDocumentBase(URL documentBase)
    {
        this.documentBase = documentBase;
    }

    public AppletContext getAppletContext()
    {
        return null;
    }

    public URL getCodeBase()
    {
        return codeBase;
    }

    public URL getDocumentBase()
    {
        return documentBase;
    }

    public String getParameter(String name)
    {
        return (String)parameters.get(name);
    }

    public boolean isActive()
    {
        return false;
    }

    public static void Download(String world, String archive)
        throws Exception
    {
        URLConnection jarConnection = (new URL((new StringBuilder(String.valueOf(world))).append(archive).toString())).openConnection();
        FileOutputStream out = new FileOutputStream("./gamepack.jar");
        InputStream input = jarConnection.getInputStream();
        byte info[] = new byte[1024];
        int ln;
        while((ln = input.read(info)) != -1) 
            out.write(info, 0, ln);
    }

    private static Map parameters = new HashMap();
    private URL codeBase;
    private URL documentBase;

}

Java アプレット コード:

import java.applet.*;
import java.awt.*;
import java.io.DataInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Main extends Applet implements AppletStub {


    public void init() {
    }

     public void run() throws FileNotFoundException, Exception {
     new Main();
     }

     public Main() throws Exception, FileNotFoundException {

            String str = getPageSource(new URL("http://oldschool38.runescape.com"));
            Pattern pattern = Pattern.compile("gamep\\w+");
            Matcher match = pattern.matcher(str);
            if(match.find())
            {
                Main stub = new Main(Pattern.compile("<param name=\"([^\\s]+)\"\\s+value=\"([^>]*)\">"), str);
                Download("http://oldschool38.runescape.com/", (new StringBuilder(String.valueOf(match.group(0)))).append(".jar").toString());
                stub.setCodeBase(new URL((new StringBuilder("http://oldschool38.runescape.com/")).append(match.group(0)).append(".jar").toString()));
                stub.setDocumentBase(new URL((new StringBuilder("http://oldschool38.runescape.com/")).append(match.group(0)).append(".jar").toString()));
                stub.getParameter((String)parameters.get("java_arguments"));
                URLClassLoader classLoader = new URLClassLoader(new URL[] {
                    new URL("file:gamepack.jar")
                });
                Applet applet = (Applet)classLoader.loadClass("client").newInstance();
                applet.setStub(stub);
                applet.setPreferredSize(new Dimension(765, 503));
                applet.setSize(new Dimension(765, 503));
                applet.init();
                applet.start();
            }
        }
     public Main(Pattern parameterPattern, String frameSource)
        {
            String key;
            String value;
            for(Matcher param = parameterPattern.matcher(frameSource); param.find(); System.out.println((new StringBuilder("Parameter Loaded. Key = ")).append(key).append(", value =").append(value).toString()))
            {
                key = param.group(1);
                value = param.group(2);
                parameters.put(key, value);
            }

        }

        private String getPageSource(URL url)
            throws IOException, InterruptedException
        {
            URLConnection cn = url.openConnection();
            cn.addRequestProperty("Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
            cn.addRequestProperty("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
            cn.addRequestProperty("Accept-Encoding", "gzip,deflate");
            cn.addRequestProperty("Accept-Language", "en-gb,en;q=0.5");
            cn.addRequestProperty("Connection", "keep-alive");
            cn.addRequestProperty("Host", "www.runescape.com");
            cn.addRequestProperty("Keep-Alive", "300");
            cn.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:9.0.1) Gecko/20100101 Firefox/9.01");
            DataInputStream di = new DataInputStream(cn.getInputStream());
            byte tmp[] = new byte[cn.getContentLength()];
            di.readFully(tmp);
            di.close();
            Thread.sleep(250 + (int)Math.random() * 500);
            return new String(tmp);
        }

        public void appletResize(int i, int j)
        {
        }

        public void setCodeBase(URL codeBase)
        {
            this.codeBase = codeBase;
        }

        public void setDocumentBase(URL documentBase)
        {
            this.documentBase = documentBase;
        }

        public AppletContext getAppletContext()
        {
            return null;
        }

        public URL getCodeBase()
        {
            return codeBase;
        }

        public URL getDocumentBase()
        {
            return documentBase;
        }

        public String getParameter(String name)
        {
            return (String)parameters.get(name);
        }

        public boolean isActive()
        {
            return false;
        }

        public static void Download(String world, String archive)
            throws Exception
        {
            URLConnection jarConnection = (new URL((new StringBuilder(String.valueOf(world))).append(archive).toString())).openConnection();
            FileOutputStream out = new FileOutputStream("./gamepack.jar");
            InputStream input = jarConnection.getInputStream();
            byte info[] = new byte[1024];
            int ln;
            while((ln = input.read(info)) != -1) 
                out.write(info, 0, ln);
        }

        private static Map parameters = new HashMap();
        private URL codeBase;
        private URL documentBase;

    }

HTMLでロードしようとしたときのエラーは次のとおりです。java.lang.reflect.invocationtargetexception 詳細をクリックすると、次のように表示されます。

Java Plug-in 10.25.2.17
Using JRE version 1.7.0_25-b17 Java HotSpot(TM) Client VM
User home directory = C:\Users\Will
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
4

0 に答える 0