1

これが私の小さなコードです。アプレットに追加されたボタンがあります。ボタンには画像アイコンがあります。これをサーバーから実行すると、コードは正常に実行されますが、ボタンに画像が表示されません。

.java ファイルのディレクトリ:C:\Program Files\OpenLaszlo Server 4.9.0\Server\lps-4.9.0\App ここでクラス ファイルを生成しています。ここにhtmlファイルを保存しています。また、画像フォルダはこのフォルダにあります。html のコード:

<html>
<applet code="applet.class" width="800" height="600">
</applet>
</html> 


/*

* .java コードは次のとおりです。

import java.applet.Applet;
import java.awt.Image;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JButton;

/**
 *
 * @author USER
 */
public class applet extends Applet {
    JButton button;
    URL url;
    Image myImage;
    ImageIcon myIcon;


    public void init(){



       button = new JButton();
       this.add(button);


       try{
                 url = new URL(getCodeBase(), "image/REC1.jpg");
           }catch(Exception e){}
         myImage = getToolkit().createImage(url);
         myIcon = new ImageIcon(myImage);
//         myIcon = new ImageIcon("image/REC1.jpg");
         button.setIcon(myIcon);
    }

    public void paint(){



    }
}
4

2 に答える 2

2

私はこれを使用していますが、動作しています:

        URL url = applet.class.getResource("/image/"+name_of_picture);
        Image I = this.getToolkit().getImage(url);  
于 2012-07-05T09:26:19.930 に答える
0
 url = new URL(getCodeBase(), "/image/REC1.jpg");
于 2012-07-05T09:34:43.173 に答える