Solved

filling Polygon at an angle using scrollbar values

Posted on 2004-04-07
9
262 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
 
LVL 86

Expert Comment

by:CEHJ
ID: 10779868
So why did you accept the answer?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

929 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now