|
¸ñ·ÏÀ¸·Î | ¼öÁ¤ | »èÁ¦ | Á¤º¸Ãß°¡[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(); } }; } |
¸ñ·ÏÀ¸·Î | ¼öÁ¤ | »èÁ¦ | Á¤º¸Ãß°¡[reply] | ½Å±ÔÀÔ·Â |