-
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);
-
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
-
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
-
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
-
thanks
thankyou for your help, i managed to solve my problem!
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks