<?xml version="1.0" encoding="utf-8"?><!DOCTYPE article  PUBLIC '-//OASIS//DTD DocBook XML V4.4//EN'  'http://www.docbook.org/xml/4.4/docbookx.dtd'><article><articleinfo><title>盤の表示</title><revhistory><revision><revnumber>25</revnumber><date>2012-03-27 04:50:03</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>24</revnumber><date>2012-01-12 06:04:32</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>23</revnumber><date>2012-01-12 06:02:06</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>22</revnumber><date>2012-01-11 06:58:51</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>21</revnumber><date>2012-01-11 06:17:16</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>20</revnumber><date>2012-01-11 06:14:10</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>19</revnumber><date>2012-01-11 03:56:59</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>18</revnumber><date>2012-01-11 03:55:01</date><authorinitials>masahiko</authorinitials><revremark>名前を'Java課題13'から変更。</revremark></revision><revision><revnumber>17</revnumber><date>2011-09-16 00:56:00</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>16</revnumber><date>2011-01-12 00:31:47</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>15</revnumber><date>2011-01-11 12:36:03</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>14</revnumber><date>2011-01-09 01:00:49</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>13</revnumber><date>2010-11-06 12:53:30</date><authorinitials>masahiko</authorinitials><revremark>名前を'Java課題12'から変更。</revremark></revision><revision><revnumber>12</revnumber><date>2010-11-06 12:53:17</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>11</revnumber><date>2009-12-16 00:24:06</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>10</revnumber><date>2009-12-06 12:43:54</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>9</revnumber><date>2009-12-06 12:36:55</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>8</revnumber><date>2009-12-06 12:36:27</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>7</revnumber><date>2009-12-06 01:49:01</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>6</revnumber><date>2009-12-04 06:02:59</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>5</revnumber><date>2009-12-04 06:00:50</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>4</revnumber><date>2009-12-04 04:12:54</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>3</revnumber><date>2009-12-03 06:50:49</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>2</revnumber><date>2009-12-03 06:14:42</date><authorinitials>masahiko</authorinitials></revision><revision><revnumber>1</revnumber><date>2009-12-03 02:26:49</date><authorinitials>masahiko</authorinitials></revision></revhistory></articleinfo><section><title>盤の表示</title><para>配列 ban の内容にしたがって画像を指定の位置に表示するプログラムを作ります。 </para><para>画像を表示する(3)では、次の値を使って表示しました。 </para><itemizedlist><listitem override="none"><para><inlinemediaobject><imageobject><imagedata fileref="http://ei-www.hyogo-dai.ac.jp/~masahiko/moin.cgi/%E7%9B%A4%E3%81%AE%E8%A1%A8%E7%A4%BA?action=AttachFile&amp;do=get&amp;target=setumei1c.png"/></imageobject><textobject><phrase>setumei1c.png</phrase></textobject></inlinemediaobject> </para></listitem></itemizedlist><para>これと同じことをピースの数だけ繰り返して行えば 盤全体を表示することができる。 </para><!--rule (<hr>) is not applicable to DocBook--><section><title>各ピースの表示</title><para>次の値がわかれば表示することができる。 </para><itemizedlist><listitem><para>ax </para></listitem><listitem><para>ay </para></listitem><listitem><para>sx </para></listitem><listitem><para>sy </para></listitem></itemizedlist><para>横方向x, 縦方向y の位置にあるピースの値は ban[x][y] に記憶されている。 </para><para>したがって </para><itemizedlist><listitem><para>ax, ay は x, y を使って計算できるはず </para></listitem><listitem><para>sx, sy は ban[x][y] を使って計算できるはず </para></listitem></itemizedlist><para>例えばban[x][y]の値が１１のときは </para><itemizedlist><listitem override="none"><para>sx = 300 </para></listitem><listitem override="none"><para>sy = 200 </para></listitem></itemizedlist><para>になればよいが、これは値１１から計算で求めることができる。 </para><!--rule (<hr>) is not applicable to DocBook--></section><section><title>プログラム</title><itemizedlist><listitem override="none"><programlisting format="linespecific" language="java" linenumbering="numbered" startinglinenumber="1"><token><![CDATA[import]]></token><![CDATA[ ]]><methodname><![CDATA[javax.swing.*]]></methodname><![CDATA[;]]>
<token><![CDATA[import]]></token><![CDATA[ ]]><methodname><![CDATA[java.awt.*]]></methodname><![CDATA[;]]>
<token><![CDATA[import]]></token><![CDATA[ ]]><methodname><![CDATA[java.awt.event.*]]></methodname><![CDATA[;]]>

<token><![CDATA[public]]></token><![CDATA[ ]]><token><![CDATA[class]]></token><![CDATA[ ]]><methodname><![CDATA[Game5]]></methodname><![CDATA[ ]]><token><![CDATA[extends]]></token><![CDATA[ ]]><methodname><![CDATA[JPanel]]></methodname><![CDATA[ ]]><token><![CDATA[implements]]></token><![CDATA[ ]]><methodname><![CDATA[MouseListener]]></methodname>
<![CDATA[{]]>
<![CDATA[        ]]><methodname><![CDATA[Image]]></methodname><![CDATA[ ]]><methodname><![CDATA[img]]></methodname><![CDATA[;]]>
<![CDATA[        ]]><token><![CDATA[int]]></token><![CDATA[ ]]><methodname><![CDATA[cx]]></methodname><![CDATA[, ]]><methodname><![CDATA[cy]]></methodname><![CDATA[;]]>
<![CDATA[        ]]><token><![CDATA[int]]></token><![CDATA[[][] ]]><methodname><![CDATA[ban]]></methodname><![CDATA[;]]>
<![CDATA[        ]]>
<![CDATA[        ]]><methodname><![CDATA[Game5]]></methodname><![CDATA[()]]>
<![CDATA[        {]]>
<![CDATA[                ]]><methodname><![CDATA[ImageIcon]]></methodname><![CDATA[ ]]><methodname><![CDATA[ii]]></methodname><![CDATA[ = ]]><token><![CDATA[new]]></token><![CDATA[ ]]><methodname><![CDATA[ImageIcon]]></methodname><![CDATA[(]]><phrase><![CDATA["game0.png"]]></phrase><![CDATA[);]]>
<![CDATA[                ]]><methodname><![CDATA[img]]></methodname><![CDATA[ = ]]><methodname><![CDATA[ii]]></methodname><![CDATA[.]]><methodname><![CDATA[getImage]]></methodname><![CDATA[();]]>
<![CDATA[                ]]><methodname><![CDATA[addMouseListener]]></methodname><![CDATA[(]]><token><![CDATA[this]]></token><![CDATA[);]]>
<![CDATA[                ]]><methodname><![CDATA[ban]]></methodname><![CDATA[ = ]]><token><![CDATA[new]]></token><![CDATA[ ]]><token><![CDATA[int]]></token><![CDATA[[4][4];]]>
<![CDATA[                ]]><methodname><![CDATA[shokika]]></methodname><![CDATA[();]]>
<![CDATA[        }]]>

<![CDATA[        ]]><token><![CDATA[void]]></token><![CDATA[ ]]><methodname><![CDATA[shokika]]></methodname><![CDATA[()]]>
<![CDATA[        {]]>
<![CDATA[                ]]><methodname><![CDATA[盤の表現の演習]]></methodname>
<![CDATA[        }]]>
<![CDATA[        ]]>
<![CDATA[        ]]><token><![CDATA[public]]></token><![CDATA[ ]]><token><![CDATA[void]]></token><![CDATA[ ]]><methodname><![CDATA[paintComponent]]></methodname><![CDATA[(]]><methodname><![CDATA[Graphics]]></methodname><![CDATA[ ]]><methodname><![CDATA[g]]></methodname><![CDATA[)]]>
<![CDATA[        {]]>
<![CDATA[                ]]><token><![CDATA[int]]></token><![CDATA[ ]]><methodname><![CDATA[w]]></methodname><![CDATA[, ]]><methodname><![CDATA[h]]></methodname><![CDATA[, ]]><methodname><![CDATA[ax]]></methodname><![CDATA[, ]]><methodname><![CDATA[ay]]></methodname><![CDATA[, ]]><methodname><![CDATA[sx]]></methodname><![CDATA[, ]]><methodname><![CDATA[sy]]></methodname><![CDATA[, ]]><methodname><![CDATA[x]]></methodname><![CDATA[, ]]><methodname><![CDATA[y]]></methodname><![CDATA[;]]>
<![CDATA[                ]]><methodname><![CDATA[w]]></methodname><![CDATA[ = 100;]]>
<![CDATA[                ]]><methodname><![CDATA[h]]></methodname><![CDATA[ = 100;]]>
<![CDATA[                ]]><token><![CDATA[for]]></token><![CDATA[ (]]><methodname><![CDATA[x]]></methodname><![CDATA[ = 0; ]]><methodname><![CDATA[x]]></methodname><![CDATA[ < 4; ]]><methodname><![CDATA[x]]></methodname><![CDATA[++)]]>
<![CDATA[                        ]]><token><![CDATA[for]]></token><![CDATA[ (]]><methodname><![CDATA[y]]></methodname><![CDATA[ = 0; ]]><methodname><![CDATA[y]]></methodname><![CDATA[ < 4; ]]><methodname><![CDATA[y]]></methodname><![CDATA[++)]]>
<![CDATA[                        {]]>
<![CDATA[                                ]]><methodname><![CDATA[ax]]></methodname><![CDATA[ = ? ;]]>
<![CDATA[                                ]]><methodname><![CDATA[ay]]></methodname><![CDATA[ = ? ;]]>
<![CDATA[                                ]]><methodname><![CDATA[sx]]></methodname><![CDATA[ = ? ;]]>
<![CDATA[                                ]]><methodname><![CDATA[sy]]></methodname><![CDATA[ = ? ;]]>
<![CDATA[                                ]]><methodname><![CDATA[g]]></methodname><![CDATA[.]]><methodname><![CDATA[drawImage]]></methodname><![CDATA[(]]><methodname><![CDATA[img]]></methodname><![CDATA[, ]]><methodname><![CDATA[画像を表示する]]></methodname><![CDATA[(3)]]><methodname><![CDATA[の演習]]></methodname><![CDATA[, ]]><token><![CDATA[this]]></token><![CDATA[);]]>
<![CDATA[                        }]]>
<![CDATA[                ]]><methodname><![CDATA[g]]></methodname><![CDATA[.]]><methodname><![CDATA[setColor]]></methodname><![CDATA[(]]><methodname><![CDATA[Color]]></methodname><![CDATA[.]]><methodname><![CDATA[blue]]></methodname><![CDATA[);]]>
<![CDATA[                ]]><methodname><![CDATA[g]]></methodname><![CDATA[.]]><methodname><![CDATA[fillRect]]></methodname><![CDATA[(]]><methodname><![CDATA[cx]]></methodname><![CDATA[*100, ]]><methodname><![CDATA[cy]]></methodname><![CDATA[*100, 100, 100);]]>
<![CDATA[        }]]>
<![CDATA[        ]]>
<![CDATA[        ]]><token><![CDATA[public]]></token><![CDATA[ ]]><token><![CDATA[void]]></token><![CDATA[ ]]><methodname><![CDATA[mousePressed]]></methodname><![CDATA[(]]><methodname><![CDATA[MouseEvent]]></methodname><![CDATA[ ]]><methodname><![CDATA[e]]></methodname><![CDATA[)]]>
<![CDATA[        {]]>
<![CDATA[                ]]><token><![CDATA[int]]></token><![CDATA[ ]]><methodname><![CDATA[x]]></methodname><![CDATA[, ]]><methodname><![CDATA[y]]></methodname><![CDATA[;]]>
<![CDATA[                ]]><methodname><![CDATA[x]]></methodname><![CDATA[ = ]]><methodname><![CDATA[e]]></methodname><![CDATA[.]]><methodname><![CDATA[getX]]></methodname><![CDATA[();]]>
<![CDATA[                ]]><methodname><![CDATA[y]]></methodname><![CDATA[ = ]]><methodname><![CDATA[e]]></methodname><![CDATA[.]]><methodname><![CDATA[getY]]></methodname><![CDATA[();]]>
<![CDATA[                ]]><methodname><![CDATA[cx]]></methodname><![CDATA[ = ]]><methodname><![CDATA[クリック時の処理]]></methodname><![CDATA[(2)]]><methodname><![CDATA[の演習]]></methodname><![CDATA[;]]>
<![CDATA[                ]]><methodname><![CDATA[cy]]></methodname><![CDATA[ = ]]><methodname><![CDATA[クリック時の処理]]></methodname><![CDATA[(2)]]><methodname><![CDATA[の演習]]></methodname><![CDATA[;]]>
<![CDATA[                ]]><methodname><![CDATA[repaint]]></methodname><![CDATA[();]]>
<![CDATA[        }]]>
<![CDATA[        ]]><token><![CDATA[public]]></token><![CDATA[ ]]><token><![CDATA[void]]></token><![CDATA[ ]]><methodname><![CDATA[mouseEntered]]></methodname><![CDATA[(]]><methodname><![CDATA[MouseEvent]]></methodname><![CDATA[ ]]><methodname><![CDATA[e]]></methodname><![CDATA[) { }]]>
<![CDATA[        ]]><token><![CDATA[public]]></token><![CDATA[ ]]><token><![CDATA[void]]></token><![CDATA[ ]]><methodname><![CDATA[mouseExited]]></methodname><![CDATA[(]]><methodname><![CDATA[MouseEvent]]></methodname><![CDATA[ ]]><methodname><![CDATA[e]]></methodname><![CDATA[) { }]]>
<![CDATA[        ]]><token><![CDATA[public]]></token><![CDATA[ ]]><token><![CDATA[void]]></token><![CDATA[ ]]><methodname><![CDATA[mouseReleased]]></methodname><![CDATA[(]]><methodname><![CDATA[MouseEvent]]></methodname><![CDATA[ ]]><methodname><![CDATA[e]]></methodname><![CDATA[) { }]]>
<![CDATA[        ]]><token><![CDATA[public]]></token><![CDATA[ ]]><token><![CDATA[void]]></token><![CDATA[ ]]><methodname><![CDATA[mouseClicked]]></methodname><![CDATA[(]]><methodname><![CDATA[MouseEvent]]></methodname><![CDATA[ ]]><methodname><![CDATA[e]]></methodname><![CDATA[) { }]]>
<![CDATA[        ]]>
<![CDATA[        ]]><token><![CDATA[public]]></token><![CDATA[ ]]><token><![CDATA[static]]></token><![CDATA[ ]]><token><![CDATA[void]]></token><![CDATA[ ]]><methodname><![CDATA[main]]></methodname><![CDATA[(]]><methodname><![CDATA[String]]></methodname><![CDATA[[] ]]><methodname><![CDATA[args]]></methodname><![CDATA[)]]>
<![CDATA[        {]]>
<![CDATA[                ]]><methodname><![CDATA[JFrame]]></methodname><![CDATA[ ]]><methodname><![CDATA[f]]></methodname><![CDATA[;]]>
<![CDATA[                ]]>
<![CDATA[                ]]><methodname><![CDATA[f]]></methodname><![CDATA[ = ]]><token><![CDATA[new]]></token><![CDATA[ ]]><methodname><![CDATA[JFrame]]></methodname><![CDATA[();]]>
<![CDATA[                ]]><methodname><![CDATA[f]]></methodname><![CDATA[.]]><methodname><![CDATA[setVisible]]></methodname><![CDATA[(]]><symbol><![CDATA[true]]></symbol><![CDATA[);]]>
<![CDATA[                ]]><methodname><![CDATA[f]]></methodname><![CDATA[.]]><methodname><![CDATA[setTitle]]></methodname><![CDATA[(]]><phrase><![CDATA["15Game"]]></phrase><![CDATA[);]]>
<![CDATA[                ]]><methodname><![CDATA[f]]></methodname><![CDATA[.]]><methodname><![CDATA[setSize]]></methodname><![CDATA[(420, 450);]]>
<![CDATA[                ]]><methodname><![CDATA[f]]></methodname><![CDATA[.]]><methodname><![CDATA[setDefaultCloseOperation]]></methodname><![CDATA[(]]><methodname><![CDATA[JFrame]]></methodname><![CDATA[.]]><methodname><![CDATA[EXIT_ON_CLOSE]]></methodname><![CDATA[);]]>
<![CDATA[                ]]><methodname><![CDATA[f]]></methodname><![CDATA[.]]><methodname><![CDATA[add]]></methodname><![CDATA[( ]]><token><![CDATA[new]]></token><![CDATA[ ]]><methodname><![CDATA[Game5]]></methodname><![CDATA[() );]]>
<![CDATA[        }]]>
<![CDATA[}]]>
</programlisting></listitem></itemizedlist><!--rule (<hr>) is not applicable to DocBook--></section><section><title>演習</title><para>４箇所ある ? に計算式を入れプログラムを完成させなさい。 </para><itemizedlist><listitem override="none"><para>１つの計算式で書けない人は、２つの式に分けて書いてもよい。 </para></listitem></itemizedlist><para>…の演習とあるところには、これまでの演習の解答が入ります。 </para></section></section></article>