2014年4月12日土曜日

開発環境

Head First Java 第2版 ―頭とからだで覚えるJavaの基本(Kathy Sierra (著)、Bert Bates (著)、島田 秋雄 (監修)、神戸 博之 (監修)、高坂 一城 (監修)、夏目 大 (翻訳)、オライリージャパン)の17章(プログラムの提供)、Java Web Start, .jnlpファイルを考えてみる。

おまけ

Java - GUIの基礎(内部クラス, アニメーション, 再描画, 塗りつぶし(repaint, fillRect, fillOval))で作ったのを、JWSを利用するプログラムを提供する手順で提供してみる。

コード(BBEdit, Emacs)

ch17/source/com/mkamimura/kamimura_blog/java/head_first_java/TestAnimation2.java

package com.mkamimura.kamimura_blog.java.head_first_java;

import javax.swing.*;
import java.awt.*;

public class TestAnimation2 {
    JFrame frame;
    int x = 50;
    int y = 50;

    public static void main(String [] args) {
        TestAnimation2 gui = new TestAnimation2();
        gui.go();
    }

    public void go() {
        frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        MyDrawPanel drawPanel = new MyDrawPanel();

        frame.getContentPane().add(BorderLayout.CENTER, drawPanel);

        frame.setSize(500, 500);
        frame.setVisible(true);

        try {
            Thread.sleep(10000);
        } catch (Exception ex) {}

        // 1
        while (x < 400) {
            x = x + 1;
            y = y + 1;
            drawPanel.repaint();

            try {
                Thread.sleep(10);
            } catch (Exception ex) {}
        }

        try {
            Thread.sleep(1000);
        } catch (Exception ex) {}

        // 2
        x = 50;
        y = 100;
        drawPanel.repaint();
        while (x < 400) {
            x = x + 1;
            drawPanel.repaint();

            try {
                Thread.sleep(10);
            } catch (Exception ex) {}
        }
        
        try {
            Thread.sleep(1000);
        } catch (Exception ex) {}

        // 3
        x = 400;
        drawPanel.repaint();
        while (x > 50) {
            x = x - 1;
            drawPanel.repaint();

            try {
                Thread.sleep(10);
            } catch (Exception ex) {}
        }

        try {
            Thread.sleep(1000);
        } catch (Exception ex) {}

        // 1
        x = 400;
        y = 50;
        drawPanel.repaint();
        while (x > 50) {
            x = x - 1;
            y = y + 1;
            drawPanel.repaint();

            try {
                Thread.sleep(10);
            } catch (Exception ex) {}
        }

        try {
            Thread.sleep(1000);
        } catch (Exception ex) {}
        // 2
        x = 50;
        y = 400;
        drawPanel.repaint();
        while (x < 400) {
            x = x + 1;
            y = y - 1;
            drawPanel.repaint();

            try {
                Thread.sleep(10);
            } catch (Exception ex) {}
        }

        try {
            Thread.sleep(1000);
        } catch (Exception ex) {}

        // 3
        x = 400;
        y = 400;
        drawPanel.repaint();
        while (x > 50) {
            x = x - 1;
            y = y - 1;
            drawPanel.repaint();

            try {
                Thread.sleep(10);
            } catch (Exception ex) {}
        }
    }
    
    class MyDrawPanel extends JPanel {
        public void paintComponent(Graphics g) {
            g.setColor(Color.white);
            g.fillRect(0, 0, this.getWidth(), this.getHeight());
            
            g.setColor(Color.red);        
            g.fillOval(x, y, 50, 50);
        }
    }
}

ch17/classes/manifest.txt

Main-Class: com.mkamimura.kamimura_blog.java.head_first_java.TestAnimation2

TestAnimation2.jnlp

<?xml version="1.0" encoding="utf-8"?>
<jnlp codebase="http://mkamimura.com/kamimura_blog/java/head_first_java" href="TestAnimation2.jnlp">

<information>
  <title>TestAnimation2</title>
  <vendor>kamimura</vendor>
  <homepage href="http://sitekamimura.blogspot.com" />
  <description>TestAnimation2 Java Web Start Demo</description>
  <icon href="../../../pictures/kamimura.png" />
  <offline-allowed />
</information>

<resources>
  <j2se version="1.3+"/>
  <jar href="TestAnimation2.jar"/>
</resources>

<application-desc main-class="com.mkamimura.kamimura_blog.java.head_first_java.TestAnimation2">
  
</jnlp>

入出力結果(Terminal)

$ ls -R
TestAnimation2.jnlp~ classes   source

./classes:
TestAnimation2.jar com   manifest.txt~
TestAnimation2.jnlp manifest.txt

./classes/com:
mkamimura

./classes/com/mkamimura:
kamimura_blog

./classes/com/mkamimura/kamimura_blog:
java

./classes/com/mkamimura/kamimura_blog/java:
head_first_java

./classes/com/mkamimura/kamimura_blog/java/head_first_java:
TestAnimation2$MyDrawPanel.class TestAnimation2.class

./source:
com

./source/com:
mkamimura

./source/com/mkamimura:
kamimura_blog

./source/com/mkamimura/kamimura_blog:
java

./source/com/mkamimura/kamimura_blog/java:
head_first_java

./source/com/mkamimura/kamimura_blog/java/head_first_java:
TestAnimation2.java TestAnimation2.java~
$

0 コメント:

コメントを投稿