Looking for simple rectangle drawing source code

Discussion in 'Java' started by Ramon, Dec 18, 2004.

  1. Ramon

    Ramon Guest

    I need to write a very simple "visual" widget drawing application.

    The app user will select an item from a palette and then
    by click and drag, create a rectangle.

    This must be the most common (after a simple click) operation
    in all the GUI environments.

    Anyway, I am looking for the code that implements the
    reactangle drawing/erasing as the mouse is dragged around.
    Any pointers??

    TIA,

    -Ramon
     
    Ramon, Dec 18, 2004
    #1
    1. Advertising

  2. Ramon

    Guest

    You might look at MouseMotionListener and MouseListener. The method for
    drawing a rectangle is simple. The method is drawRect and accepts 4
    parameters. The first two are the x and y coordinates of the upper left
    corner of the rectangle. The third is the width, and the fourth is the
    height.
     
    , Dec 18, 2004
    #2
    1. Advertising

  3. >I need to write a very simple "visual" widget drawing application.
    >
    > The app user will select an item from a palette and then
    > by click and drag, create a rectangle.
    >
    > This must be the most common (after a simple click) operation
    > in all the GUI environments.
    >
    > Anyway, I am looking for the code that implements the
    > reactangle drawing/erasing as the mouse is dragged around.
    > Any pointers??


    it is very easy...

    while mouse dragging you make following:

    first getGraphics from your Component or Canvas or whatever.
    then you set XOR painting mode on that Graphics
    then if there exist saved(!) rectangle you draw it.
    then you draw current rectangle.
    then you save your current rectangle.
    and dispose Graphics

    thats it!

    --
    Andrei Kouznetsov
    http://uio.dev.java.net Unified I/O for Java
    http://reader.imagero.com Java image reader
    http://jgui.imagero.com Java GUI components and utilities
     
    Andrei Kouznetsov, Dec 18, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    687
    Kevin Spencer
    Jan 9, 2006
  2. TahoeKid

    Looking for schematic drawing sdk

    TahoeKid, Nov 3, 2006, in forum: C Programming
    Replies:
    1
    Views:
    305
    james of tucson
    Nov 3, 2006
  3. Elliot
    Replies:
    1
    Views:
    368
    Knute Johnson
    Nov 14, 2007
  4. defn noob
    Replies:
    1
    Views:
    435
    Mark Space
    Jun 28, 2008
  5. John Nagle
    Replies:
    23
    Views:
    3,233
    Giacomo Boffi
    Sep 18, 2009
Loading...

Share This Page