Drawing multiple shape

I am working on a small program to draw multiple shape, I am having problem because I can not draw more than one shape on the screen at the same time . can you help me pls
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.applet.Applet;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.Rectangle2D;
import java.awt.Color;
public class BoxClickApplet extends Applet
int x1,y1;
int click=-1;
          class MyMouseListener implements MouseListener
          public void mousePressed(MouseEvent event){}
          public void mouseReleased(MouseEvent event){}
          public void mouseClicked(MouseEvent event)
               click++;
if (click==0)
                              x1=getWidth()/2-20;
                              y1=getHeight()-40;
                              repaint();
                              ((Graphics2D)g).fill(r);
               if (click==1)
                              x1=getWidth()/2-20;
                              y1=getHeight()/2-20;
                              repaint();
               if (click==2)
                              x1=getWidth()/2-20;
                              y1=0;
                              repaint();
if (click==3)
                         x1=getWidth()/2-20;
                         y1=getHeight()/2;
                         repaint();
                         x1=getWidth()/2-20;
                         click=-1;
public void mouseEntered(MouseEvent event){}
          public void mouseExited(MouseEvent event){}
MyMouseListener listener = new MyMouseListener();
addMouseListener(listener);
public void paint(Graphics g)
     g.setColor(Color.GREEN);
     Rectangle2D.Double r = new Rectangle2D.Double (x1,y1,40,40);
((Graphics2D)g).fill(r);

//  <applet code="BCA" width="400" height="400"></applet>
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
public class BCA extends Applet
    BufferedImage image;
    int width = 40;
    int height = 40;
    public void init()
        addMouseListener(new MyMouseListener());
    public void paint(Graphics g)
        if(image == null)
            initImage();
        g.drawImage(image, 0, 0, this);
    private void initImage()
        int w = getWidth();
        int h = getHeight();
        int type = BufferedImage.TYPE_INT_RGB;
        image = new BufferedImage(w, h, type);
        Graphics2D g2 = image.createGraphics();
        g2.setBackground(getBackground());
        g2.clearRect(0,0,w,h);
        g2.dispose();
    private void addRectangle(Point p)
        Graphics2D g2 = (Graphics2D)image.getGraphics();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(Color.GREEN);
        g2.fill(new Rectangle(p.x-width/2, p.y-height/2, width, height));
        g2.dispose();
    private void clearImage()
        Graphics g = image.getGraphics();
        g.setColor(getBackground());
        g.fillRect(0, 0, image.getWidth(), image.getHeight());
        g.dispose();
    class MyMouseListener extends MouseAdapter
        public void mousePressed(MouseEvent event)
            if(event.getClickCount() == 2)
                clearImage();
            else
                addRectangle(event.getPoint());
            repaint();
}

Similar Messages

  • Drawing Multiple Shapes Out of One

    Hi everyone,
    I am building a marketing brochure, and I wanted to know if it were possible to make one shape into many using just inDesign. In the sample image, you can see the polygon includes multiple shapes from what appears to be a larger shape. The pen and rectangle tool can get some of the shapes, but the more cumbersome ones, i.e., such as a shape similar to the one below the "goals" text seem almost impossible to do with just the pen or rectangle tool.

    See this quick video.
    To make a rounded corner for one side hold down shift key then drag.
    https://dl.dropboxusercontent.com/u/72277778/multiple%20shapes.mp4

  • How can you fix transparency less than 100% when drawing multiple shapes with the pencil tool?

    I draw a (fill only) shape at 50% with the pencil tool and when I go to draw another, the transparency jumps back to 100%. I would like it to stay at 50% for every mark I make, anyone know how? I wish to build up multiple semi-translucent vector shapes like in the attached image.
    Many Thanks.
    Mark

    In the bottom of the Appearance Palette, toggle the (deep breath) New Art Maintains Appearance / New Art Has Basic Appearance button (pant pant).
    I leave it to you to do three things:
    1. Figure out which state of that stupidly-designed single button means which setting.
    2. Figure out if the stupidly-designed tooltip that appears when you hover over that stupid button means:
    A. ...that what the tooltip reads is the current setting, or...
    B. ...that what the tooltip reads is the setting you will get if you click the stupidly-designed single button.
    3. Remember what you figured out the next time you need to visit that stupidly-designed button.
    Adobe doesn't understand this is a simple yes/no decision, and that a far more intuitive simple labeled checkbox will do.
    JET

  • Drawing Rectangle shape using Labview 8.0

    Is it possible to draw a rectagle shape using Labview 8.0? I found in the HELP content tat it did exist some function related, but when i click on "place to block diagram" it doesnt work. So i susect tat it is for further version of Labview.
    I have an idea of how to draw the rectagle, which is by drawing line from point to point. Since i need to draw multiple of rectangle, so i hope tat there is an easier way to do it.
    Thanks for ur time and help.

    You can have the numbers created, programmatically
    Attachments:
    Example_VI_BD2.png ‏3 KB

  • Applying shape styles to multiple shapes or paint strokes...

    Is it possible to apply a shape style (such as "Hard Chalk") so multiple shapes or strokes at once?
    Dragging and dropping onto one line at a time until the drawing is completely made up of chalk strokes is quite tedious...
    Alternatively, perhaps there is a way to combine paint strokes...grouping is OK, but you can't drop a shape style onto a group...so it doesn't help here.
    any thoughts?

    Hi Daniel,
    If you need to use the master page for multiple site collections, then you’d better to choose the option 2 or options 3, as you do not need to make copies of the CSS or JS files and re-upload them to each site collection.
    And per my knowledge, option 3 is better. Because the CSS or JS files are stored at the local system of SharePoint server in option 3, it is faster than referring a file which is stored in database in option 2.
    Generally, it depends based on your situation as you don’t like option 3 when the CSS or JS files are not accessible in SPD.
    Thanks,
    Victoria
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Victoria Xia
    TechNet Community Support

  • How to draw multiple lines on same panel??

    hiya
    i would like to know how can I draw multiple lines on the same panel ?? I have already use repaint(); but it just come out the lastest line (say line 3) i draw .......those previous lines(say line 1 and 2) are disappear ........
    Thanks for your help mate

    http://www.java2s.com/ExampleCode/2D-Graphics/Line.htm

  • Can we draw multiple lines on a single CAShapeLayer?

    I want to draw multiple lines on a single layer of CAShapeLayer by UITouch. Is it possible?

    if they use the same appleID then you can do it at www.icloud.com

  • How to draw 2D shapes on the image generated by JMF MediaPlayer?

    Hello all:
    IS there any way that we can draw 2D shapes on the image generated by JMF
    MediaPlayer?
    I am currently working on a project which should draw 2D shapes(rectangle, circle etc) to
    mark the interesting part of image generated by JMF MediaPlayer.
    The software is supposed to work as follows:
    1> first use will open a mpg file and use JMF MediaPlayer to play this video
    2> if the user finds some interesting image on the video, he will pause the video
    and draw a circle to mark the interesting part on that image.
    I know how to draw a 2D shapes on JPanel, however, I have no idea how I can
    draw them on the Mediaplayer Screen.
    What technique I should learn to implement this software?
    any comments are welcome.
    thank you
    -Daniel

    If anyone can help?!
    thank you
    -Daniel

  • I want to draw multiple selection for some field on Type M program.

    Hi. everyone.
    I'm programing on Type M program but I don't know how do I draw multiple selection on Type M.
    Is it possible?
    If you know some related website or on-line document, please let me know that.

    It means Online program. it is not report progeam.
    I want to design a multiple selection on screen.

  • How to draw vector shape?

    I use following statement to draw a shape
    [CODE]for(....){
      sprite.graphics.beginFill(..);
      sprite.graphics.drawRect(x,y,1,1);
      sprite.graphics.endFill();
    }[/CODE]
    But I find above shape is not vector shape.Because I change the IE size,I find the size of shape don't automatic change. How to use sprite.graphics to create vector shape?
    Thanks

    Set Flash object size to 100% x 100% in the HTML - then you'll see your drawing changes the size as you resize the browser window.
    Kenneth Kawamoto
    http://www.materiaprima.co.uk/

  • Slowing Down Arrow Keys when Drawing Geometric Shapes?

    I have a MacPro Intel 8-core with 16 GB RAM and running Mac OSX 0.5.6 and AICS4.
    I also use a WACOM Intuos3 Tablet.
    This is not a new problem - also happened with AICS3.
    When I try to draw a shape - say a polygon, or star, etc., the up/down arrow keys on the keyboard do add/subtract sides, vertexes, etc. as they should, but they won't increase/decrease in increments. For instance if I draw a 5 sided Polygon and tap the down arrow while using the polygon tool, instead of giving me a 4 sided polygon, I get a triangle. Conversly, if I tap the up arrow it jumps to maybe a 20 sided polygon, but no way to slow it down to get say a 10 sided polygon.
    Does anyone else experience this behavior. Is there a trick i am missing?

    It's a very common issue and primarily due to the WACOM drivers from what I see. There is no work around for it that I'm aware of, other than to unplug the tablet.

  • I can't able to access shapes(circle,star) in tool,only rectangle is used.what to do for drawing other shapes?

    i can't able to access shapes(circle,star) in tool,only rectangle is used.what to do for drawing other shapes?

    Mylenium is right; we don't know enough to help you.
    Screenshots of your interface would help. Also, more information about your OS, version of AE, etc.: FAQ: What information should I provide?

  • Is there an easier way to draw a shape in 3d to match X,Y, Z of photo?

    I usually start a project in 2d and import photos, draw shapes and text in this 2d environment. I find it easier this way because they all start out on the same plane, and when manipulating in 3d later, this initial plane acts as a reference plane that I can shift X,Y,Z and rotation paramaters from. I then add a new camera and turn everything into 3d. However, as I work further in the timeline, I sometimes want to add a rectangle that overlaps exactly on top of a photo lying in 3d space as to cover it. When I start the shape command in the active camera view and draw the rectangle to match the outline of the photo, it seems like the photo and rectangle are on the same plane in this view. However, when I check this by going to the perspective view and checking from other angles I see that the rectangle was placed on an arbitrary plane and the rectangle is not overlapping the photo.
    To correct this, I open the inspector of the photo and write down it's X,Y,Z positions and also it's X,Y,Z rotation parameters. Then I go to the rectangle that I have already drawn and in the wrong plane, open it's inspector properties, and replace with the X,Y,Z and rotation parameters of the photos. Then fine tune the orthogonal positions and scaling within the plane with the 3d tranform tool. This seems like a lot of work, especially when I have to do it a 100 times. Looking for an easier way to draw a shape on the same plane of a photo in 3d space.
    Thanks

    Howdy,
    This is a really good question about one of the bigger challenges of building a 3D project. When you add objects to the Canvas (including drawing), they get added in the camera's viewspace, facing the camera and sharing the same up-vector (i.e. positive Y is up). This is all well and good, but what about doing what you ask, where you want to add an object in the localspace of another object? Let's look at your example: adding a shape that is coplanar to a photo, with the camera not necessarily aligned with the photo.
    As Mark suggested, you can draw the shape in the camera's viewspace and then drag-and-drop the Position and Rotation channels from the photo onto the shape. This will replace the shape's Position and Rotation values with that of the photo, making them coplanar and located in the same place. The shortcoming of this method is that you draw the shape at a size that seems correct in the Canvas, but once it's moved to the same place as the photo, it will often turn out to be too small or large. Then you have to make further tweaks.
    Another solution is to use the Isolate command. Isolate temporarily aligns the current view to the selected object and solos that object. So you could isolate the photo and then draw the shape in the Canvas and it will be coplanar with the photo. The only caveat is that the moment you finish drawing the shape, it will disappear. This is because the photo is still isolated (and soloed). As soon as you de-isolate the photo, everything will reappear.
    The easiest way to use Isolate for new photos—not ones already in the project—is to place the photo in a 3D group, position the group where you want the photo and shape to be, then isolate the group and add anything you want to it (shapes, image, text, etc).

  • Anybody know where I can find Draw Multiple Lines.vi?

    I don't mean the actual function itself. I know you just right-click and scroll through the menus for that. But I want to find a VI that showcases how the Draw Multiple Lines.vi is used. As of yet I can't find one anywhere. I've read the Detailed Help that Labview provides when I look at the function under Context Help, and it mostly makes sense. The only thing that's not working is how to implement the array that provides the line points into the function. I tried connecting a 1D array to the function and it was no dice. I get the quentessential error:
    You have connected two terminals of a different type. The source is 1D array of double. The sink is 1D array of cluster of 2 elements.
    So I know there is a special array called a Cluster Array, I think. Does it want me to attach that instead?

    ShogunOrta wrote:
    I just want to programmatically draw a line on the Front Panel from point A to point B. That's all.
    You can only do it with the restriction that it has to be bounded to a picture indicator. To draw anywhere on the front panel, we would need this idea implemented.
    A plain 1D array does not define points because each point has an x and a y.  Hierarchical data structure are actually quite easy once you play a little bit with them.

  • How to draw a shape with line tool then fill with colour

    How can i draw a shape with the line tool and then fill it with colour

    Click and drag from one anchor point to the next, making sure that each new line segment begins where the last one ended. The Line Tool will snap onto the anchors.
    Once you're done creating what looks like a closed path, the lines are still separate objects. To combine them into one path, select them all and press Ctrl/Cmd+J (for Join) or via the menu select Object > Path > Join.
    The Pen Tool can be used in a similar manner, but each segment will be a continuation rather than a separate object. The last (closing) click will be indicated by a tiny circle on the mouse pointer.
    If you make an open path, Ai will still "fill" it with a fill color by assuming a straight path between the last open anchor points. Individual straight paths, however, such as those drawn by the line tool, have no "inside", so they won't show the fill color even if you have assigned one.
    Allen

Maybe you are looking for