JAppletを使ったサーバ上画像の表示
戻る
意外にこれからAppletが復権するかもしれない^^;ホンマかいな?(2009/06/24記)
::::::::::::::
ImageLoadingApplet.java
::::::::::::::
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
/**
* <pre>
* Appletでサーバ内の画像をロード・表示する方法
* </pre>
* $Id: ImageLoadingApplet.java,v 1.4 2006/03/09 13:56:39 kishi Exp kishi $
* @author KISHI Yasuhiro
*/
public class ImageLoadingApplet extends JApplet {
private Image image;
private URL base;
public void init() {
try {
base = getDocumentBase();
} catch ( Exception e ) {}
image = getImage( base, "FREE.gif" );
Container contentPane = getContentPane();
contentPane.setLayout( new FlowLayout() );
MyPanel panel = new MyPanel( image );
panel.setPreferredSize( new Dimension( 800 , 600 ) );
contentPane.add( panel );
}
}
::::::::::::::
MyPanel.java
::::::::::::::
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
/**
* $Id: MyPanel.java,v 1.7 2006/03/09 14:00:33 kishi Exp kishi $
* @author KISHI Yasuhiro
*/
public class MyPanel extends JPanel {
public MyPanel( Image image ) {
setLayout( null );
ImageIcon icon = new ImageIcon( image );
JButton button = new JButton( icon );
// イメージのサイズにボタンのサイズを合わせる
button.setSize( icon.getIconWidth(), icon.getIconHeight() );
// 位置を設定
button.setLocation( 100, 200 );
this.add( button );
}
}
::::::::::::::
../bin/LoadImage.html
::::::::::::::
<html>
<body>
<applet archive="ImageLoading.jar" code="ImageLoadingApplet" width=640 height=480>
</applet>
</body>
</html>
戻る