Archive for the ‘Java Applet’ Category

  1. Hello, Java Applet World!

    Posted on 2月 28th, 2012 by cx20

    Java Applet

    Java Applet は Java プログラムの実行形態の1つである。ブラウザ上で動作する。「〜let」は小さいという意味。

    ソースコード(Java)

    import javax.swing.*;
     
    public class HelloApplet extends JApplet {
        public void init() {
            JLabel label = new JLabel("Hello, Java Applet World!");
            getContentPane().add(label);
        }
    }

    ソースコード(HTML)

    <html>
      <head>
        <title>Hello, World!</title>
      </head>
      <body>
        <applet code="HelloApplet.class" height="100" width="200"></applet>
      </body>
    </html>

    実行方法(AppletViewer による表示)

    $ appletviewer ./hello.html

    実行方法(ブラウザによる表示)

    1. Web サーバの公開フォルダ に配置
    2. ブラウザで表示
       http://localhost/doc/hello.html

    実行結果

    Hello, Java Applet World!