Solved

filling Polygon at an angle using scrollbar values

Posted on 2004-04-07
9
261 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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:

707 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

20 Experts available now in Live!

Get 1:1 Help Now