1

Java アプレットで簡単な記憶ゲームを作成しました。カスタム ローダー (特別なアプレット属性 - docs.oracle.com/.../special_attributes.htmlに gif として追加) に問題があり、数秒間白い画面のまま消えてしまいます。

index.html

(...)
<body>
    <center>
    <script src="http://www.java.com/js/deployJava.js"></script>
    <script>
        var attributes = {code:'(...).Memo.class', archive:'Memo.jar', width: 1200, height: 900}; 
        var parameters = {image: 'res/loading0.gif', boxbgcolor: 'white', boxborder: 'false', centerimage: 'true'}; 
        deployJava.runApplet(attributes, parameters, '1.6'); 
    </script>
    <noscript>
        (...)
    </noscript>
    <script type="text/javascript" language="JavaScript" src="http://www.oracle.com/ocom/groups/systemobject/@mktg_admin/documents/systemobject/s_code_download.js"></script>
    <script type="text/javascript" language="JavaScript" src="http://www.oracle.com/ocom/groups/systemobject/@mktg_admin/documents/systemobject/s_code.js"></script>
    <script type="text/javascript" language="javascript">var s_code=s.t();if(s_code)document.write(s_code)</script>
    </center>
</body>
(...)

このローダーは、アプレットの警告メッセージの直後に消えますが、まだいくつかの画像をロードする必要があり、時間がかかります。どうすれば修正できますか?

Memo.cs - 画像をロードするメイン クラス

public class Memo extends JApplet {

    //...   

    public void init() {
        //...   
        try {
            SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { createGUI(); }});
        } 
        catch(Exception e) {
            e.printStackTrace();
        }
    }

    private void createGUI() {
        final Model model = new Model(...);
        final View view = new View(model);

        getContentPane().add(view, BorderLayout.CENTER);
        setBackground(backgroundColor);
        setPreferredSize(new Dimension(width, height));

        model.setLoading(loadImages(loadingPath, format, 1));
        model.setCardsImages(loadImages(cardImagePath, format, 13));
        //...
        model.setAppState(AppStates.PROCESS);

        model.startNewGame();
        view.repaint();
    }

    private Image[] loadImages(String path1, String path2, int count) {
        Image[] imgs = new Image[count];        
        for(int i = 0; i < count; ++i) {
            imgs[i] = getImage(getCodeBase(), path1 + i + path2);
        }
        return imgs;
    }
}

- - - - - - - - - - 解決 - - - - - - - - - -

メディアトラッカーがうまく動かなかったので、JavaScript で試してみました。これは私のコードです:

index.html の新機能 (head)

    <script language="javascript" type="text/javascript">
        function setApplet() 
        {
            document.getElementById('loader').innerHTML = "";
        }
    </script>

index.html 内のローダー div とアプレット div (本体)

  • loading.gifアニメーション化されたローダー アイコンです。
  • loading0.gif偽のローダー アイコン - 画像 1x1 - デフォルトの Java ローダーを非表示に設定

また、アプレットは準備が整うまで空白です。

        <div id="loader" style="font-size: 14pt; font-weight: bold;">
            <p>Loading... Please wait</p>
            <img src="res/loading.gif" alt="Loading... Please wait" />
        </div>
        <div id="applet">
            <script src="http://www.java.com/js/deployJava.js"></script>
            <script>
                var attributes = {code:'(...).Memo.class', archive:'Memo.jar', width: 1200, height: 900}; 
                var parameters = {image: 'res/loading0.gif', boxbgcolor: 'white', boxborder: 'false', centerimage: 'true'}; 
                deployJava.runApplet(attributes, parameters, '1.6'); 
            </script>
            (...)
        </div>

Memo.cs の新機能

    private void runJs() throws JSException, Exception {
        JSObject setApplet = null;
        setApplet = (JSObject) JSObject.getWindow(this);
        setApplet.call("setApplet", null);
    }
4

1 に答える 1

1

I think the best chance of success here can be achieved through Cascading Style Sheets & JavaScript.

CSS

Have the applet load in an element that is set the proper size, but at an absolute location that is not visible on the page. E.G. x = -2000px, y = -2000px. At the same time, display a fixed size (same as the applet) div element where the applet is to appear. The on-screen element shows the 'loading..' image.

JS

Have JS poll a public method of the applet that is set true when ready. When that method returns true, swap the style (that determines position) of the applet and 'loading..' element.

于 2013-08-28T10:01:57.153 に答える