Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

this question is about a java applet modification

Posted on 2004-10-06
10
Medium Priority
?
215 Views
Last Modified: 2010-03-31
in this program my teacher asked me to add some new features to this program by modifying the source code , he asked like ten things which i know and i've already modify but the two things i dont get are this :

i need to add more ovals to this program at less 5 more

i need to change the color of the ovals by maintaining the gredient effect of the original applet ( this question an expert answered for me thanks)

this is the code :

public class Wormhole extends Applet
{
    /**
     * Do all the drawing.
     */
    public void paint(Graphics g)
    {
        // Draw the black background.
        g.setColor(Color.black);
        g.fillRect(0, 0, 500, 350);
       
        // Draw ten nested "holes."
        drawHole(0, g);
        drawHole(1, g);
        drawHole(2, g);
        drawHole(3, g);
        drawHole(4, g);
        drawHole(5, g);
        drawHole(6, g);
        drawHole(7, g);
        drawHole(8, g);
        drawHole(9, g);
         
        // Draw the text, in white with a blue drop shadow.
        g.setColor(Color.blue);
        g.setFont(new Font("TimesRoman", Font.BOLD, 36));
        g.drawString("On to Cydonia!", 22, 300);
       
        g.setColor(Color.white);
        g.drawString("On to Cydonia!", 20, 298);
    }
   
    /**
     * Using the supplied Graphics object, draw the n-th hole.
     * n should be between 0 (darkest, largest) and 9 (lightest,
     * smallest).
     */
    private void drawHole(int n, Graphics g)
    {
        int X0 = 50,        // x-anchor
            Y0 = 50,        // y-anchor
            W0 = 350,        // initial width
            H0 = 200,        // initial height
            X_INC = 30,        // x-anchor increment
            Y_INC = 10,        // y-anchor increment
            RG_INC = 10,    // red-green increment
            BLUE_INC = 25;    // blue increment
           
        g.setColor(new Color(n * RG_INC, n * RG_INC, (n + 1) * BLUE_INC));
        g.fillOval(X0 + n * X_INC, Y0 + n * Y_INC,
                    W0 - n * X_INC, H0 - n * 2 * Y_INC);
    }
}



ok my teacher told me to add more lines like this one  (drawHole(10, g);) and then do the multiplications (ohh boy multiplication ??????) this is the part i dont get how you multiply this can you tell me step by step cause  my assignment works great but to be honest i just guess the numbers and i dont know how to do it , please tell me what should i multiply depending on the ovals you will add  to the applet , thanks in advance

Mijangos
         
0
Comment
Question by:mijangos
[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
  • 5
  • 5
10 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12244496
why doesn't adding extra calls to drawHole() work?
0
 

Author Comment

by:mijangos
ID: 12244772
if you add the extra ( drawHole() ) lines and you run the program you'll see that the extra oval wont appear at less you modify the variables , variables that already have the values that you need to multiply in order for the new ovals to appear thats what i cant do in other words i dont know what to multiply as my teacher said .

Mijangos
0
 
LVL 92

Expert Comment

by:objects
ID: 12244842
you could add an extra method and call that as well as the original one, eg.

    private void drawHole2(int n, Graphics g)
    {
        int X0 = 150,        // x-anchor
            Y0 = 150,        // y-anchor
            W0 = 350,        // initial width
            H0 = 200,        // initial height
            X_INC = 30,        // x-anchor increment
            Y_INC = 10,        // y-anchor increment
            RG_INC = 10,    // red-green increment
            BLUE_INC = 25;    // blue increment
           
        g.setColor(new Color(n * RG_INC, n * RG_INC, (n + 1) * BLUE_INC));
        g.fillOval(X0 + n * X_INC, Y0 + n * Y_INC,
                    W0 - n * X_INC, H0 - n * 2 * Y_INC);
    }
0
Technology Partners: 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!

 

Author Comment

by:mijangos
ID: 12244874
yes thats a solution but in this case i cant add any more methods to the program i can only modify the  , X_INC , Y_INC , RG_INC , BLUE_INC variables in this program
0
 
LVL 92

Expert Comment

by:objects
ID: 12244892
then perhaps add another call to fillOval() in drawHole:

    private void drawHole2(int n, Graphics g)
    {
        int X0 = 150,        // x-anchor
            Y0 = 150,        // y-anchor
            W0 = 350,        // initial width
            H0 = 200,        // initial height
            X_INC = 30,        // x-anchor increment
            Y_INC = 10,        // y-anchor increment
            RG_INC = 10,    // red-green increment
            BLUE_INC = 25;    // blue increment
           
        g.setColor(new Color(n * RG_INC, n * RG_INC, (n + 1) * BLUE_INC));
        g.fillOval(X0 + n * X_INC, Y0 + n * Y_INC,
                    W0 - n * X_INC, H0 - n * 2 * Y_INC);
        g.fillOval(X0 + 100 + n * X_INC, Y0 + 100 + n * Y_INC,
                    W0 - n * X_INC, H0 - n * 2 * Y_INC);
    }
0
 

Author Comment

by:mijangos
ID: 12244919
yes this is a solution , but i cant add any other method to this program the only thing i can change are this variables values to get what i want , by the way this is the sentence of what my teacher asked :

Change the number of ovals drawn to at least 12; you may draw more if you like. [Beware: You will need to change the spacing and/or the x and y anchor values to accomodate a different number of ovals.]
0
 
LVL 92

Expert Comment

by:objects
ID: 12244937
thats not adding a new method.

> Change the number of ovals drawn to at least 12; you may draw more if you like.

that suggests to me adding extra calls to drawHole() as I suggested originally.

> [Beware: You will need to change the spacing and/or the x and y anchor values to accomodate a different number of ovals.]

And also adjust the variables as appropriate.
say to shift it up and to the left a nd little and lessen spacing:

        int X0 = 50,        // x-anchor
            Y0 = 50,        // y-anchor
            W0 = 350,        // initial width
            H0 = 200,        // initial height
            X_INC = 20,        // x-anchor increment
            Y_INC = 7,        // y-anchor increment
            RG_INC = 10,    // red-green increment
            BLUE_INC = 25;    // blue increment
0
 

Author Comment

by:mijangos
ID: 12244996
yes thats what am talking about , how you multiply or what you did to get  the results 20 , 7 , 10 , 25  ?
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 12245022
i just picked arbitrary values, play around with them until you get it looking the way u want.
 
0
 

Author Comment

by:mijangos
ID: 12245035
yeah thats exactly what i did i've picked arbitrary values , i was wondering if there was a fast and easy way to do instead of just playing around with the numbers until you get what you want thanks men and bare with me a newbie :)
0

Featured Post

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.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

670 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