Solved

filling Polygon at an angle using scrollbar values

Posted on 2004-04-07
9
265 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
[X]
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
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maven module vs maven project 3 74
String array comparison 4 46
java imports not found 4 52
Cisco ASA: Java web start no go, asdm launcher no go 3 58
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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

730 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