Solved

this question is about a java applet modification

Posted on 2004-10-06
10
211 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
replace a word with other 1 44
Tomcat: Unable to run tomcat service. 2 20
How to determine if a string is a valid SHA value 7 34
printf performancy 11 42
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

777 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