Solved

this question is about a java applet modification

Posted on 2004-10-06
10
213 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
Independent Software Vendors: 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 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

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
Running JavaFX on JDeveloper 12C 1 116
collection output issue 9 95
Setup GlassFish 4 55
Java import explained 4 49
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

751 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