[] STUDY ³»¿ë

ÀÛ¼ºÀÏ 2004-04-14
ÀÛ¼ºÀÚ park
Á¶È¸¼ö 1015
Á¦ ¸ñ ¸¶¿ì½º¸¦ »ç¿ëÇÏ¿© »ç°¢Çü ±×¸®±â

¸ñ·ÏÀ¸·Î | ¼öÁ¤ | »èÁ¦ | Á¤º¸Ãß°¡[reply] | ½Å±ÔÀÔ·Â

//  ¸¶¿ì½º¸¦  ÀÌ¿ëÇÏ¿©  »ç°¢Çü  ±×¸®±â

import  java.awt.*;
import  java.awt.event.*;

class    draw2  extends  Frame
{
    //  WindowAdapter
    myWinAdapter  myW  =  new  myWinAdapter();
    
    //  MouseAdapter  and  MouseMotionAdapter
    myMouseAdapter  myM  =  new  myMouseAdapter();
    myMouseMotionAdapter  myMM  =  new  myMouseMotionAdapter();

    //  ¸¶¿ì½º  ÁÂÇ¥
    int  fx,  fy;
    int  sx,  sy;
    int  ox,  oy;

    int  width,  height;
    int  odlWidth,  oldHeight;

    public  draw2()
    {
        setTitle("Draw");
        addWindowListener(myW);
        addMouseListener(myM);
        addMouseMotionListener(myMM);


        setSize(400,400);
    }

    public  void  paint(Graphics  g)
    {
    }

    public  void  drawRect()
    {
        Graphics  g  =  getGraphics();
        g.setXORMode(Color.white);
        g.setColor(Color.blue);

        odlWidth  =  ox  -  fx;
        oldHeight  =  oy  -  fy;

        width  =  sx  -  fx;
        height  =  sy  -  fy;

        g.drawRect(fx,  fy,  odlWidth,  oldHeight);

        g.drawRect(fx,  fy,  width,  height);
    }

    public  static  void  main(String[]  args)  
    {
        draw2  f  =  new  draw2();
        f.setVisible(true);
    }

    //  inner  classes
    class  myWinAdapter  extends  WindowAdapter
    {
        public  void  windowClosing(WindowEvent  e)
        {
            dispose();
            System.exit(0);
        }
    };

    class  myMouseAdapter  extends  MouseAdapter
    {
        public  void  mousePressed(MouseEvent  e)
        {
            fx=e.getX();
            fy=e.getY();

            ox=fx;
            oy=fy;

            sx=fx;
            sy=fy;
        }
    };


    class  myMouseMotionAdapter  extends  MouseMotionAdapter
    {
        public  void  mouseDragged(MouseEvent  e)
        {
            ox=sx;
            oy=sy;

            sx=e.getX();
            sy=e.getY();
            drawRect();
        }
    };

}

¸¶¿ì½º¸¦ »ç¿ëÇÏ¿© »ç°¢Çü ±×¸®±â °ú(¿Í) °ü·ÃµÈ Ãß°¡ Á¤º¸

  • ¸¶¿ì½º¸¦ »ç¿ëÇÏ¿© ¼±±×¸®±â [2004-04-14] [park´Ô Àç°ø] [Á¶È¸:2056]
  • ¸¶¿ì½º¸¦ »ç¿ëÇÏ¿© »ç°¢Çü ±×¸®±â [2004-04-14] [park´Ô Àç°ø] [Á¶È¸:1015]
  • ¸¶¿ì½º·Î »ç°¢Çü ±×¸®°í reDrawÇϱâ [2004-04-14] [park´Ô Àç°ø] [Á¶È¸:1593]
  • µµÇü ±×¸®±â¿Í ¸Þ´º [2004-04-16] [park´Ô Àç°ø] [Á¶È¸:1087]
  • ±×·¡ÇÈ ¸â¼Òµå [2003-10-21] [park´Ô Àç°ø] [Á¶È¸:981]

    ¸ñ·ÏÀ¸·Î | ¼öÁ¤ | »èÁ¦ | Á¤º¸Ãß°¡[reply] | ½Å±ÔÀÔ·Â