/*****************************/ /* */ /*  お絵描きソフト第一回  */ /* */ /* 1998/ 5/20 宍戸 輝光 */ /* */ /*****************************/ import java.awt.*; class Gedcv1 extends Canvas { // キャンバス用クラス private Image img; private int w,h; private Graphics g_img; Gedcv1(Image im) { // コンストラクタ w=200; // キャンバスの大きさ設定 h=200; resize(w,h); img=im; // 渡されたイメージをキャンバスのイメージに設定 g_img=img.getGraphics(); // キャンバスに描画するGrahics g_img.setColor(Color.white); // キャンバス初期化 g_img.fillRect(0,0,w,h); g_img.setColor(Color.black); g_img.drawRect(0,0,w-1,h-1); g_img.setColor(Color.blue); // 描画色設定 } public boolean mouseDown(Event evt,int x,int y) { // マウスイベント if (x<1 || y<1 || x>w-3 || y>h-3) // 枠の部分なら戻る return false; g_img.fillRect(x,y,2,2); // 点を打つ repaint(); return true; } public boolean mouseDrag(Event evt,int x,int y) { if (x<1 || y<1 || x>w-3 || y>h-3) return false; g_img.fillRect(x,y,2,2); repaint(); return true; } public void paint(Graphics g){ g.drawImage(img,0,0,this); // イメージを表示 } public void update(Graphics g){ paint(g); } } public class Ged1 extends java.applet.Applet { // メインクラス Gedcv1 cv; public void init(){ cv=new Gedcv1(createImage(200,200)); // キャンバス作成 add(cv); // キャンバス配置 } }