How to make Rectangle persistant when another rectangle is drawn

Hello,
Please some one help with this,
actually what i m tryin to do is, when i mouse click n drag the mouse n release it , i want a rectangle to be drawn.
and when i click on another location then also i want a rectangle to be drawn and the previusly drawn rectangle should also be vissible.
I am able to draw the rectangle but whe i draw a new rectangle the old rectangle vanishes.
i should be able to draw any number of rectangles, and all the rectangle
should be vissible.
can any one plz help me with this.
Plz help
Regards
Sanam
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
<applet code = "Test.class" width = 1020 height = 600>
</applet>
public class Test extends Applet implements MouseListener
     private Color color = Color.black;
     int x1, y1, x2, y2 = 0;
     int width, height = 0;
     int startX, startY = 0;
     boolean drawObject = false;
     boolean moveObject = false;
     Rectangle myRectangle = new Rectangle(startX,startY,width,height);
     public void init()
          setBackground(Color.gray);
          addMouseListener(this);
          int i = 5;
     public void paint(Graphics g)
          //recover Graphics2D
          Graphics2D g2 = (Graphics2D)g;
          g2.setColor(color);
          if(drawObject)
               //create Rectangle Object
               myRectangle = new Rectangle(startX,startY,width,height);
          else if (moveObject)
               myRectangle.setLocation(x2,y2);
          g2.draw(myRectangle);
     //--> Start of section dealing with Mouse Events
     public void mouseClicked(MouseEvent e)
     public void mouseEntered(MouseEvent e)
     public void mouseExited(MouseEvent e)
     public void mousePressed(MouseEvent e)
          x1 = e.getX();
          y1 = e.getY();
          //Check to see if mouse is pressed in the current rectangle.
          if(myRectangle.contains(x1,y1))
               //move the object instead of moving it
               drawObject = false;
               moveObject = true;
          else
               //draw the object, don't move
               drawObject = true;
               moveObject = false;
     public void mouseReleased(MouseEvent e)
          //get the positions of where the mouse was released
          x2 = e.getX();
          y2 = e.getY();
          if (x1 != x2 && y1 != y2)
               //maths to work out where to draw the object
               if(x1 < x2 && y1 < y2)
               {//1
                    startX = x1;
                    startY = y1;
                    height = y2 - y1;
                    width = x2 - x1;
               else if (x1 > x2 && y1 > y2)
               {//2
                    startX = x2;
                    startY = y2;
                    height = y1 - y2;
                    width = x1 - x2;
               else if (x1 > x2 && y1 < y2)
               {//3
                         startX = x2;
                    startY = y1;
                    height = y2 - y1;
                    width = x1 - x2;
               else if (x1 < x2 && y1 > y2)
               {//4
                    startX = x1;
                    startY = y2;
                    height = y1 - y2;
                    width = x2 - x1;
          repaint();
}

Every time you repaint it only draws what you tell it to, so how bout something like this:
Add a vector to store the rectangles:
Vector<Rectangle> rectangles = new Vector<Rectangle>();In paint when you create a new rectangle add it to the vector:
         public void paint(Graphics g) {
          //recover Graphics2D
          Graphics2D g2 = (Graphics2D)g;
          g2.setColor(color);
          if(drawObject) {
               //create Rectangle Object
               myRectangle = new Rectangle(startX,startY,width,height);
               rectangles.add(myRectangle);
          } else if (moveObject) {
               myRectangle.setLocation(x2,y2);
          for (int i = 0; i < rectangles.size(); i++) {
               g2.draw(rectangles.get(o));
      }When you check to see if the click is in a rectangle check them all:
     //Check to see if mouse is pressed in the current rectangle.
     for (int i = 0; i < rectangles.size; i++) {
          if(rectangles.get(i).contains(x1,y1)) {
               //move the object instead of moving it
               drawObject = false;
               moveObject = true;
               myRectangle = rectangles.get(i);
     }Just briefly looked over your code so there may be a few other places you need to change. Also if you post code its a lot easier to read if you put it in code tags.
Alex.

Similar Messages

  • HT4199 how do I fix it when "another device is using computer IP address" and I can't get wireless to work anymore? It used to work fine.

    How do I fix it when "another device is using computer IP address"? Airport used to work fine. I've already tried turning everything on and off several times.

    I would recommend that you do the following as a minimum:
    Power-down the modem, AirPort base station, and computer(s).
    Power-up the modem; wait at least 10-15 minutes to allow it adequate time to initialize.
    Power-up the AirPort base station; wait at least 5-10 minutes. Note: The AirPort's status light may continue to flash amber after it has intialized. That is because, there may be some additional configuration items necessary, like setting up wireless security, before the overall setup is completed to get a green status.
    Power-up your computer(s).
    If the above steps do not solve the problem, start over with step 1 above, but then perform the next steps between steps 1 & 2. above.
    Disconnect the AirPort base station from the Internet broadband modem.
    While all of the devices are powered-down, perform a "factory default" reset on the base station. This will get it back to its "out-of-the-box" configuration and make setting it up much easier, especially if you use the "Assist me" process within the AirPort Utility. (ref: Resetting an AirPort Base Station or Time Capsule)
    After the base station resets, go ahead and power it back down.
    Reconnect the AirPort base station to the Internet broadband modem. For the Extreme and Time Capsule, be sure to connect the cable to the base station's WAN (circle-of-dots) port.
    Continue with step 2 in the first set of steps.
    In this basic configuration, the AirPort base station will broadcast an unsecured wireless network with a Network Name (SSID) of Apple Network NNNNNN. Network clients, connected to the base station either by wire or wireless, should now be able to access the Internet through the ISP's modem. Once Internet connectivity has been verified, you can use the AirPort Utility to configure the base station for wireless security and any other desired options. Please post back your results.

  • How to make session invalid when user refresh the page?

    How to make session invalid when user refresh the page?

    I have a <form> in a JSP file that has another JSP file as an action.
    I have main.jsp that has <form> with action.jsp file as an action.
    Now when I submit the <form>, request forwarded to action.jsp and it will take the action. But this file is taking so long, hence user refresh the page again and again, hence duplicate request processing is occuring.
    I want to prevent this.

  • How to make instruments persistent...

    Hi Forte Experts
    I keep setting the KeepAliveCycle parameter on my server, and it seems to disappear every now and then (at reboot?)
    So what is the correct procedure to set and keep this parameter alive...
    Do I have to modify the startup scripts to set this parameter during/After startup or can I just do some 'save' command somewhere... Am I just missing some Install command somewhere??
    I am using escript - forte version 3.0.e.2
    Best wishes from
    The Manual Reader..
    jens chr /KAD denmark
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

    You need to put the values in the fortedef.csh or .sh file. This way every
    time the node manager starts up it will set the values automatically.
    setenv FORTE_KEEP_CYCLE 600
    setenv FORTE_KEEP_COUNT 3
    setenv FORTE_KEEP_INTERVAL 10
    ka
    Kamran Amin
    Forte Technical Leader, Core Systems
    (203)-459-7362 or 8-204-7362 - Trumbull
    [email protected]
    From: JCJJ[SMTP:[email protected]]
    Sent: Wednesday, January 20, 1999 5:08 PM
    To: [email protected]
    Subject: How to make instruments persistent...
    Hi Forte Experts
    I keep setting the KeepAliveCycle parameter on my server, and it seems to
    disappear every now and then (at reboot?)
    So what is the correct procedure to set and keep this parameter alive...
    Do I have to modify the startup scripts to set this parameter during/After
    startup or can I just do some 'save' command somewhere... Am I just
    missing some Install command somewhere??
    I am using escript - forte version 3.0.e.2
    Best wishes from
    The Manual Reader..
    jens chr /KAD denmark
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

  • How to make it selected when clicked and open popup

    Hi,
    I 've a form in the parent page with many form elements.
    I've 2 radio buttons with values "Yes" and "No". I am opening a modal popup when clicked on "Yes" radio button. The modal popup is opening fine.
    But when I click "Yes", it' s not selected. After modal popup is closed, when I return to parent page, the option "Yes" is still not selected.
    How to make it selected when clicked and open popup?

    Perhaps try moving the application to your preferred desktop and then right-click it's dock icon > options > Assign to This Desktop.

  • CS6 Fluid Grids - how to make images resize when page is resized? [was: Hello]

    I am new to fluid grid layouts in Dreamweaver cs6, I want to insert a GIF file on my index page but I do not know how to make it so when the page shrinks the GIF or image shrinks as well. The only code that I have found is
    img, {
        max-width: 100%;
    But this code already exists in the css file when you create a new fluid grid based layout
    img, object, embed, video {
        max-width: 100%;
    can anyone help a newbie please..

    this is my source code
    <!doctype html>
    <!--[if lt IE 7]> <html class="ie6 oldie"> <![endif]-->
    <!--[if IE 7]>    <html class="ie7 oldie"> <![endif]-->
    <!--[if IE 8]>    <html class="ie8 oldie"> <![endif]-->
    <!--[if gt IE 8]><!-->
    <html class="">
    <!--<![endif]-->
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Kyle Childress Foundation</title>
    <link href="boilerplate.css" rel="stylesheet" type="text/css">
    <link href="/layout.css" rel="stylesheet" type="text/css">
    <!--
    To learn more about the conditional comments around the html tags at the top of the file:
    paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/
    Do the following if you're using your customized build of modernizr (http://www.modernizr.com/):
    * insert the link to your js here
    * remove the link below to the html5shiv
    * add the "no-js" class to the html tags at the top
    * you can also remove the link to respond.min.js if you included the MQ Polyfill in your modernizr build
    -->
    <!--[if lt IE 9]>
    <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <script src="respond.min.js"></script>
    </head>
    <body>
    <div class="gridContainer clearfix">
      <div id="animation"><img src="images/images/kyleanimation2014gif2.gif" alt="kylechildressfoundationanimation"></div>
    </div>
    </body>
    </html>
    this is my css
    @charset "UTF-8";
    @import url("/kyle.css");
    /* Simple fluid media
       Note: Fluid media requires that you remove the media's height and width attributes from the HTML
       http://www.alistapart.com/articles/fluid-images/
    img, object, embed, video {
        max-width: 100%;
    /* IE 6 does not support max-width so default to width 100% */
    .ie6 img {
        width:100%;
        Dreamweaver Fluid Grid Properties
        dw-num-cols-mobile:        5;
        dw-num-cols-tablet:        8;
        dw-num-cols-desktop:    10;
        dw-gutter-percentage:    25;
        Inspiration from "Responsive Web Design" by Ethan Marcotte
        http://www.alistapart.com/articles/responsive-web-design
        and Golden Grid System by Joni Korpi
        http://goldengridsystem.com/
    /* Mobile Layout: 480px and below. */
    .gridContainer {
        margin-left: auto;
        margin-right: auto;
        width: 87.36%;
        padding-left: 1.82%;
        padding-right: 1.82%;
    #LayoutDiv1 {
        clear: both;
        float: left;
        margin-left: 0;
        width: 100%;
        display: block;
    #animation {
        clear: both;
        float: left;
        margin-left: 0;
        width: 100%;
        display: block;
    #image {
        clear: both;
        float: left;
        margin-left: 0;
        width: 100%;
        display: block;
    /* Tablet Layout: 481px to 768px. Inherits styles from: Mobile Layout. */
    @media only screen and (min-width: 481px) {
    .gridContainer {
        width: 90.675%;
        padding-left: 1.1625%;
        padding-right: 1.1625%;
    #LayoutDiv1 {
        clear: both;
        float: left;
        margin-left: 0;
        width: 100%;
        display: block;
    #animation {
        clear: both;
        float: left;
        margin-left: 0;
        width: 100%;
        display: block;
    #image {
        clear: both;
        float: left;
        margin-left: 0;
        width: 100%;
        display: block;
    /* Desktop Layout: 769px to a max of 1232px.  Inherits styles from: Mobile Layout and Tablet Layout. */
    @media only screen and (min-width: 769px) {
    .gridContainer {
        width: 88.2%;
        max-width: 1232px;
        padding-left: 0.9%;
        padding-right: 0.9%;
        margin: auto;
    #LayoutDiv1 {
        clear: both;
        float: left;
        margin-left: 0;
        width: 100%;
        display: block;
    #animation {
        clear: both;
        float: left;
        margin-left: 0;
        width: 100%;
        display: block;
    #image {
        clear: both;
        float: left;
        margin-left: 0;
        width: 100%;
        display: block;
    the animation GIF is 700 x 908
    I changed the code from max-width to just width 100% but it still did not work ,, please help

  • How to make swatches persistent from one document to the next?

    I want to have a custom swatches in my  workspace each time I open a document. How can I make swatches persistent in InDesign?

    You can have swatches available in new documents if you make them part of your defaults by loading them while no document is open, but there is no way that I know of to open any existing document that doesn't have a particular swatch and have that particular swatch available without loading it yourself. Probably the quickest way to load them into existing documents would be to:
    Make a frame
    Fill it with a swatch
    Repeat steps 1 & 2 until you have a frame for each swatch you want to transfer
    Grab all of the frames and drag them together into a library as one entry
    When you open a file, drag the frames from the library to the doc and immediately delete them while they are still selected. All of the swatches will have been added to your swatches list, and it's a little quicker than going to the swatches fly-out, selecting Load Swatches and navigating to a file that has the swatches saved in it, but that's another way if you prefer.

  • How to make data persist in form?

    Hi
    I've made multiple forms for a Web site. Each form is within its own module. The problem is the data entered into a form disappears as soon as the user shifts to another form (and consequently, another module). How to make the data persist in the form even if the user shifts away to another module? I've tried using a Model to hold the data but the data didn't stay in the text fields.
    <fx:Declarations>
         <fx:Model  id="babyModel1">
              <BabyForm>
                   <CleaningProducts>{babyCleanProd.text}</CleaningProducts>
                   <BabyProducts>{babyProd.text}</BabyProducts>
              </BabyForm>
         </fx:Model>
    </fx:Declarations>
    <mx:Form id="babyQuestionnaire" x="140" y="40" >
         <mx:FormItem width="100%" label="Baby Cleaning Products1">
              <s:RichEditableText 
                   id="babyCleanProd"
                   width="200"
                   height="100"
                   backgroundColor="#ffffff"
                   paddingLeft="4" paddingRight="4" paddingTop="4" paddingBottom="4"
                   color="#222222"
                   />
         </mx:FormItem>
         <mx:FormItem width="100%" label="Baby Products1">
              <s:RichEditableText  id="babyProd"
                       width="200"
                        height="100"
                        backgroundColor="#ffffff"
                        paddingLeft="4" paddingRight="4" paddingTop="4" paddingBottom="4"
                        color="#222222"/>
             </mx:FormItem>
    </mx:Form>
    Any solutions? The data persists in the text fields if the forms are all in the same central application but then there's lots of code for each form.
    Thanks for your attention.
    Kearney

    I thought ModuleLoader could only load one Module at a time, and unloaded the current Module when called to load the next Module. This app has only one ModuleLoader, which loads various modules as different states are called.
    If the Model to hold the form data is in the shell application, how to wire each Model to each Form (assuming the forms are still in various modules)?
    Thanks.
    Kearney

  • How to make open a pagein another window

    When I click on the image, another page is opening, but in
    (at the place) my first window.
    Here the script :
    on(press){ getURL("
    http://www.mysite.com/anotherpage.htm/","_self")
    How can I make it open in another window?

    bobarchie wrote:
    > When I click on the image, another page is opening, but
    in (at the place) my
    > first window.
    >
    > Here the script :
    change this :
    > on(press){ getURL("
    http://www.mysite.com/anotherpage.htm/","_self")
    to this
    on(press){ getURL("
    http://www.mysite.com/anotherpage.htm/","_blank")
    Regards
    Urami
    Happy New Year guys - all the best there is in the 2006 :)
    <urami>
    http://www.Flashfugitive.com
    </urami>
    <web junk free>
    http://www.firefox.com
    </web junk free>

  • Can 3 vertical Radio Buttons span 3 rows in a table? AND how to make form highlight when radio butto

    I am trying to add 3 grouped vertical radio buttons where one is on each line of a 3 row table. When I group the 3 buttons it squeezes them into one row, is there a way I can have them grouped and one in each.
    Also, I would like to know how to make part of the form highlight when one of the 3 buttons is selected

    Hi,
    If I am not wrong, a table cell can hold only one component or none. In order to place the radio group to different positions vertically, you can use subforms instead of table.
    Asiye

  • How To Make Text Disappear When Mouse is On a Button?

    Hello,  I'm completely new to Flash and well I need some help. I created a page that has static text in the center.
    The page has buttons on side and when I rollover a button text appears, but the problem is that when I rollover a button, the static text in the center is there and I want to hide it as I can't read anything because the texts are overlapped.
    How do I make the text in the center disappear/hide when I rollover a button and how do I make it reappear when the the mouse is off the button?
    I hope what I am explaining makes sense.

    You can assign onRollOver and onRollOut code to the buttons to make the text dispappear, but you'll need to make the text a movieclip with an instance name that you can use to target it to turn it invisible.  In the simple example below, the button has an instance name of "btn" and the text movieclip has an instance name of "text_mc"
    btn.onRollOver = function(){
          text_mc._visible = false;
    btn.onRollOut = function(){
          text_mc._visible = true;

  • How to make attachments "show" when sending mail?

    Hello
    How can I make sure that when I add attachments to my mail it would show in the body of the mail on the receivers end,
    regardless of what mailprovider or program he/she is using. (e.g. a pdf file)
    Any clues?

    If you make sure your message is in rich text (Format -> Make Rich Text, if it says Make Plain Text it's already rich text) and make sure that you're sending Windows-friendly attachments (Edit -> Attachments), that will increase the chances. But there is *no way* to guarantee that an attachment will be displayed inline at all, since different mail clients work differently and different people have different settings... many people prefer plain text e-mails, and there is nothing you can do about that.

  • How to make phone vibrate when call is answered?

    Hi!
    Does anybody know how to make a BB phone (Bold 9700) to have a short vibrate when your call is being answered, so that you don't have to look at the phone or hold it to your ear when making a call?
    Appreciate any advice, thks!

    Hello Daven02,
    You might want to try using a bluetooth headset as there is no way to enable a vibration when a call is connected.
    You can find a variety of supported headsets at the Shop BlackBerry website.
    Thanks and have a great day!
    -HMthePirate
    Come follow your BlackBerry Technical Team on twitter! @BlackBerryHelp
    Be sure to click Kudos! for those who have helped you.Click Solution? for posts that have solved your issue(s)!

  • How to make round curves when you are animatting with the Rec mode?

    Hi! I am making a project in motion. I recored a freind writing words and stuff in the roof of my house with two flashlights. My plans was to follow the lights with motion traking: Analize move or match move. And then add a particle emmite for making something like this: http://www.youtube.com/watch?v=MZf2W3S7gV0&feature=fvw . When i tried to make the match move it was imposible. So i desided to make it manually with the REC button. And it work perfectly, the only problem is that it can's achive the round cruves (bezier like). I can only make squared like turns and it looks awful. I have also tried bezier as a path but i don't know how to make the particle emmiter follow it with different speeds, becouse the movement of the flashlight is inconstant.
    What can i do to make a round curved path and make a particle emmiter follow it with the rec button with the different speeds of the flashlights? Please help me!!!! I have to deliver this work for tuesday!
    Thanks for you time y hope you can help me out as soon as possible.
    Juan Javier.
    PD Sorry for my english! jajajaja.

    Juan Javier Ibarra Pitts wrote:
    When i tried to make the match move it was imposible.
    Hi
    Why was it impossible?
    It sounds like tracking is the only way your going to achieve what your after given the way you've shot your footage and the spatial and temporal nuances therein.
    You'll find comprehensive instructions on how to track particles to footage starting on page 49 of this document:
    http://manuals.info.apple.com/en/MotionSupplementalDocumentation.pdf
    Regards.

  • How to make mac speak when logging on or waking up

    hi, i was wondring how you make your mac speak to you and say welcome or hello everytime you log on or wake it up.
    if anybody knows, plesae help.
    Thanks!

    A login greeting is simple.  Make a small application with Automator:
    1. Choose Application from the Automator template.
    2. Add one action: Run Shell Script.  In this action, replace cat with say welcome.
    Save the application and store it somewhere.  (The Applications folder is a good choice.)
    Open System Preferences, choose Accounts, then select the account you want to target.  In that account, select Login Items.  Drag your new application to the login item window to create a link to the file.  Close System Preferences.
    Each time that you login to that account, the application will run and the Mac will say "Welcome."   Once it becomes annoying, return to the Login Items to remove the link to your application.
    A spoken wake-up message is trickier, but it can be done.  See these discussions: https://discussions.apple.com/message/3240458 and http://hints.macworld.com/article.php?story=20060908113605812, then get a copy of SleepWatcher, http://www.bernhard-baehr.de/.

Maybe you are looking for

  • What is the best "5" 1 Port USB 2.0 PCI Controller Card for my G5 10.5.8

    Greetings all. My old school G5 needs additional 2.0 USB ports. I've looked on line at "Newegg" etc., but the descriptions are vague. Please advise and thank you in advance. Ma6hine

  • External monitor goes black when macbook pro has magsafe connected

    Hi, I have bought an external monitor about 1 week ago, and I have it connected with a minidisplay to dvi cable, and a dvi cable to the monitor. It was working OK -well, it had some sudden flash to black screen that lasted about 1 second, but nothing

  • Security for Advanced Editing Options

    I work in a regulated environment and need to remove the ability for all end users to access the TouchUp Text Tool in the Advanced Editing Menu. NOTE WE ARE USING ACROBAT STANDARD V6.0.1. Can I make a change in the registry to remove this option? Any

  • Selection on timestamps

    Hello all, I like to write a report with ranges of date and time in the selection screen. The table to be selected contains a timestamp. How can I convert several date and time ranges in corresponding timestamp ranges for the selection? Many thanks f

  • Need immediate help with layers

    Hello. Can someone please tell me how I get a selected background to  "go behind" the writing. Its an elementary question, Im aware, but Ive been fiddling with this thing for ages and can't see a way out. Thanks L