?
Solved

filling Polygon at an angle using scrollbar values

Posted on 2004-04-07
9
Medium Priority
?
271 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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 2000 total points
ID: 10779946
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

801 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