Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

filling Polygon at an angle using scrollbar values

Posted on 2004-04-07
9
264 Views
Last Modified: 2010-03-31
I just can't get my swimming pool (polygon pool) to fill with water at an angle (polygon water).  

My code so far:-

import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;


//<APPLET code=SwimmingPool.class width=600 height=350> </APPLET>

public class SwimmingPool extends Applet implements AdjustmentListener
{
      private Scrollbar slider;
      private int sliderValue;
      private int currentX;

      public void init()
      {
            Label title1;
            title1 = new Label("Change Pool Volume");
            add(title1);
            slider=new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 441);
            add(slider);
            slider.addAdjustmentListener(this);
      }

      public void paint(Graphics g)
      {
            int xValues[] = {40, 440, 440, 40};
            int yValues[] = {40, 40, 60, 100};
            Polygon pool = new Polygon(xValues, yValues, 4);
            g.drawPolygon(pool);

            int unit = 1;
            //float unit2 = 0.4f;
            int xValues2[] = {40, 40+ currentX, 40 + currentX, 40};
            int yValues2[] = {40*unit, 40, 100, 100};            
            Polygon water = new Polygon(xValues2, yValues2, 4);
            g.fillPolygon(water);
      }

      public void adjustmentValueChanged(AdjustmentEvent e)
      {
            currentX=slider.getValue();
            repaint();
      }
}
0
Comment
Question by:buglouie
  • 3
  • 3
  • 2
9 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10779630
try setting the colour before painting:

g.setColor(Color.blue);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10779821
How does that make any difference to your previous result, apart from changing the color?
0
 

Author Comment

by:buglouie
ID: 10779858
this has only changed the color - not the scaled "fill".  Still very stuck!
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 86

Expert Comment

by:CEHJ
ID: 10779868
So why did you accept the answer?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10779875
Please post a 0-point question to

http://www.experts-exchange.com/Community_Support/

and ask them to reopen the question
0
 
LVL 92

Expert Comment

by:objects
ID: 10779893
> Still very stuck!

Why didn't you say so :)

 try the following:

double ratio = (400 - currentX) / 400.0;
int yValues2[] = {40, 40, 60 + (int)(40*ratio), 100};  

> Please post a 0-point question to
http://www.experts-exchange.com/Community_Support/
> and ask them to reopen the question

You can just ask them, to change the grade to an "A" ;-)

0
 

Author Comment

by:buglouie
ID: 10779924
Absolutely fantastic - thanks.
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 10779946
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MySQL  on Tomcat 8 68
printf performancy 11 70
Java syntax, or is it Selenium 6 30
Running JavaFX on the Raspberry Pi 27 41
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question