can anyone find an answer to the following please:


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: can anyone find an answer to the following please:

  1. #1
    Join Date
    Nov 2004
    Posts
    32

    can anyone find an answer to the following please:

    I have created a container with water in it and labelled the container at different heights. (from 0 - 100ml)

    5 pixels = 1ml

    i now want to type in the command line: java water 50
    so that the container is blue up to the number 50.

    i am uncertain of how to calculate this so this works,

    i am using the following:

    g.setColor(Color.blue);
    g.fillRect(140,60,25,600);

  2. #2
    Join Date
    Dec 2004
    Location
    france
    Posts
    35
    what about dropping that's code so we could take a look
    the things i don't wana be doing the work in your place so please show us how much motivated you are by dropping what you got
    then you'll be more likely to get and answer
    good luck

  3. #3
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    If your container is represented as a rectangle and is going to contain a maximum of 100 ml, and you use 5 pixels on the y axis to represent 1ml, then the rectangle has to be (at least) 500 pixels high.
    A full container will then be drawn like this:
    (I have 'chosen' a topleft= (0,0) and a container width of 200)

    g.setColor(Color.blue);
    g.fillRect(0,0,200,500);

    Assuming your input is ml (and not pixels)
    Using this, your setup will be:

    public void fillWater(int amount, Graphics g) {
    int full=500;
    int pxPerML=5;
    Color oldColor=g.getColor():
    g.setColor(Color.blue);
    g.fillRect(0,full-amount*pxPerML,200,amount*pxPerML);
    g.setColor(oldColor);
    }

    I've also inluded the two lines of code that ensures that when fillWater has finished the color setting for the grapics is the same as before (a good habit).
    eschew obfuscation

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    just one more thing, if your full container is drawn like this:

    g.setColor(Color.blue);
    g.fillRect(140,60,25,600);

    then according to your setup your container is 600 pixels high and contains 120 ml.

    then you will have to do this:

    g.fillRect(140,60+full-amount*pxPerML,25,amount*pxPerML);
    eschew obfuscation

  5. #5
    Join Date
    Nov 2004
    Posts
    32

    Smile thanks

    thankyou for your help, i managed to solve my problem!

  6. #6
    Join Date
    Dec 2004
    Location
    france
    Posts
    35
    well that kind of great but I'm not take credit for something i didn't really do , there's ain't no honor in that
    so i think you're tahnks should go right that dude
    named:sjalle
    Thanks for your understanding

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center