[] STUDY ³»¿ë

ÀÛ¼ºÀÏ 2004-04-14
ÀÛ¼ºÀÚ park
Á¶È¸¼ö 1593
Á¦ ¸ñ ¸¶¿ì½º·Î »ç°¢Çü ±×¸®°í reDrawÇϱâ

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

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

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

//  µµÇüÀÇ  Á¾·ù  Å¬·¡½º
class  drawData
{
    int  fx,  fy;
    int  sx,  sy;
    Color      lineColor;
    int  type;  //  1=¼±,  2=»ç°¡Çü,  3=¿ø
}

class  drawRect  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;

    
    Vector  vector  =  new  Vector(10,5);

        public  drawRect()
        {
                setTitle("DrawRect");
                addWindowListener(myW);
                addMouseListener(myM);
                addMouseMotionListener(myMM);


                setSize(400,400);
        }

        public  void  paint(Graphics  g)
        {
            int  i;
            drawData  data;
            int  w,  h;
            for(i=0  ;  i<vector.size();  i++)
            {
                data  =  (drawData)vector.elementAt(i);
                if(data.type==2)  //  Rect
                {
                    g.setColor(data.lineColor);
                    w=  data.sx  -  data.fx;
                    h=  data.sy  -  data.fy;
                    
                    g.drawRect(data.fx,  data.fy,w,h);
                }
            }
        }

        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)  
        {
                drawRect  f  =  new  drawRect();
                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;
                }
                
                public  void  mouseReleased(MouseEvent  e)  //µµÇüÀÇ  ¸¶¹«¸®
                {
                    Graphics  g  =  getGraphics();
                    g.setColor(Color.blue);
                        g.drawRect(fx,  fy,  width,  height);
                        
                        drawData  ddd=new  drawData();
                        ddd.fx=fx;
                        ddd.fy=fy;
                        ddd.sx=sx;
                        ddd.sy=sy;
                        ddd.lineColor=g.getColor();
                        ddd.type=2;
                        
                        vector.addElement(ddd);
                        
                }                
        };


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

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

}

¸¶¿ì½º·Î »ç°¢Çü ±×¸®°í reDrawÇϱ⠰ú(¿Í) °ü·ÃµÈ Ãß°¡ Á¤º¸

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

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