Solved

this question is about a java applet modification

Posted on 2004-10-06
10
212 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
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 

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 500 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
V.simple question about Android packages and libraries 1 30
Protect jar file - windows app 2 65
check java version using powershell 13 184
jmss example java 2 24
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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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…

808 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