ページへ戻る

+ Links

 印刷 

blike​/Java​/p0007 :: OSASK計画

osaskwiki:blike/Java/p0007

お絵かき遊び anchor.png

  • (by K, 2010.07.11)
  • ここまでで紹介した命令のサンプルです。
Page Top

(1) 四角を3つ (ex07a.java) anchor.png

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

/* <applet code="ex07a.class" width="400" height="400"></applet> */

public class ex07a extends blike {
    public void run()
    {
        grp.setColor(new Color(0xc0c0c0)); /* 背景色:やや白い灰色 */
        grp.fillRect(0, 0, dim.width, dim.height);

        grp.setColor(new Color(0xff0000)); /* 赤 */
        grp.fillRect( 50,  50, 150, 100);

        grp.setColor(new Color(0x00ff00)); /* 緑 */
        grp.fillRect(100,  80, 150, 100);

        grp.setColor(new Color(0x0000ff)); /* 青 */
        grp.fillRect(150, 110, 150, 100);

        repaint();
    }
}
Page Top

(2) 北斗七星 (ex07b.java) anchor.png

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

/* <applet code="ex07b.class" width="400" height="400"></applet> */

public class ex07b extends blike {
    public void run()
    {
        grp.setColor(new Color(0x000080)); /* 濃い青 */
        grp.fillRect(0, 0, dim.width, dim.height);

        grp.setColor(new Color(0xffff00)); /* 黄色 */
        grp.drawString("*",  60, 120);
        grp.drawString("*",  90, 100);
        grp.drawString("*", 110, 102);
        grp.drawString("*", 135, 102);
        grp.drawString("*", 155, 120);
        grp.drawString("*", 185, 105);
        grp.drawString("*", 180,  80);

        grp.setColor(new Color(0x00ff00)); /* 緑 */
        grp.drawString("北斗七星", 120, 150);

        repaint();
    }
}
Page Top

(3) 四角のしましま (ex07c.java) anchor.png

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

/* <applet code="ex07c.class" width="400" height="400"></applet> */

public class ex07c extends blike {
    public void run()
    {
        grp.setColor(new Color(0xffffff));
        grp.fillRect(0, 0, dim.width, dim.height);

        grp.setColor(new Color(0x000000));
        grp.fillRect( 20,  20, 360, 360);
        grp.setColor(new Color(0xffffff));
        grp.fillRect( 40,  40, 320, 320);
        grp.setColor(new Color(0x000000));
        grp.fillRect( 60,  60, 280, 280);
        grp.setColor(new Color(0xffffff));
        grp.fillRect( 80,  80, 240, 240);
        grp.setColor(new Color(0x000000));
        grp.fillRect(100, 100, 200, 200);
        grp.setColor(new Color(0xffffff));
        grp.fillRect(120, 120, 160, 160);

        grp.setColor(new Color(0xff0000));
        grp.drawString("四角のしましま", 30, 397);

        repaint();
    }
}
Page Top

(4) いろいろな文字 (ex07d.java) anchor.png

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

/* <applet code="ex07d.class" width="400" height="400"></applet> */

public class ex07d extends blike {
    public void run()
    {
        grp.setColor(new Color(0xffffff));
        grp.fillRect(0, 0, dim.width, dim.height);
        grp.setColor(new Color(0x000000));
        grp.setFont(new Font("Dialog", Font.PLAIN, 12)); /* 普通の大きさ */
        grp.drawString("こんにちは ABC", 60, 110);
        grp.setFont(new Font("Dialog", Font.PLAIN, 24)); /* 2倍の大きさ */
        grp.drawString("こんにちは ABC", 60, 140);
        grp.setFont(new Font("Dialog", Font.ITALIC, 24)); /* 2倍で斜体 */
        grp.drawString("こんにちは ABC", 60, 170);
        grp.setFont(new Font("Dialog", Font.BOLD, 24)); /* 2倍で太字 */
        grp.drawString("こんにちは ABC", 60, 200);
        repaint();
    }
}

Last-modified: 2010-07-13 (火) 00:00:00 (JST) (319d) by lina