1: 2010-07-11 (日) 12:31:36 k-tan |
現: 2024-01-08 (月) 12:58:53 lina |
| * お絵かき遊び [#k4d8f611] | | * お絵かき遊び [#k4d8f611] |
| -(by [[K]], 2010.07.11) | | -(by [[K]], 2010.07.11) |
| + | -ここまでで紹介した命令のサンプルです。 |
| + | |
| + | *** (1) 四角を3つ (ex07a.java) [#w150f91f] |
| + | 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(); |
| + | } |
| + | } |
| + | |
| + | *** (2) 北斗七星 (ex07b.java) [#ife64f71] |
| + | 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(); |
| + | } |
| + | } |
| + | |
| + | *** (3) 四角のしましま (ex07c.java) [#s76ad042] |
| + | 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(); |
| + | } |
| + | } |
| + | *** (4) いろいろな文字 (ex07d.java) [#t0a98e3f] |
| + | 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(); |
| + | } |
| + | } |