Solved

this question is about a java applet modification

Posted on 2004-10-06
10
210 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
  • 5
  • 5
10 Comments
 
LVL 92

Expert Comment

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

Author Comment

by:mijangos
Comment Utility
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
Comment Utility
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
 

Author Comment

by:mijangos
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:mijangos
Comment Utility
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
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
i just picked arbitrary values, play around with them until you get it looking the way u want.
 
0
 

Author Comment

by:mijangos
Comment Utility
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

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).

Join & Write a Comment

Suggested Solutions

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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
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:

771 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

10 Experts available now in Live!

Get 1:1 Help Now