DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2002

    More info on simple program

    Hi Jim

    Thanks for your interest. I will try to elaborate further on the specific problem I have encountered.

    My problem is in geting more than one asterisk per input number to show in the applet window, using the command

    g.drawString ("*");

    The applet runs in Kawa 5 and ie6 but only prints one asterisk per integer i.e. if I enter 6 the applet shows

    instead of


    When I write the program as an application the program works using the


    The program although inelegant should work, I think the problem is with using g.drawString to output the asterisks ( or maybe not ).

    thanks Mark

  2. #2
    Join Date
    Sep 2002
    Hi, Mark

    A few thoughts on your problem.

    First, it seems that your drawString() method is causing the non appearance of the astrisks. You've written:

    g.drawString("*" + num5,25, 25);

    which means the asterisk and num5 will be drawn however many times the for() loop specifies IN EXACTLY THE SAME POSITION. So, although it LOOKS like it's only drawn once, it is ACTUALLY drawn the number of times in the for() loop...just in the same place. Like a typewriter that has got stuck, pressing the "q" key 10 times will print "q" ten times in the same place. To remedy the sitiuation change the 'x' coordinate to a variable which changes due to the loop. For example:


    Notice I've left out the num5...or it'll get printed however many times the for() loop specifies AS WELL. You'll need to draw the number string first, using relevant coordinates: leaving enough room for it AND the asterisks, and then draw the asterisks.

    I've also noticed the following:

    for(int i5=1; i5<= num5; i5++)
    if (i5 <= num5)

    the second piece of code seems to be unnecessary. The for() loop will only perform while i5 is 1 to 5 inclusive. Therefore, anything INSIDE that loop will only be performed while i5 is 1 to 5 inclusive.

    Finally, are you wanting the user to enter 5 separate numbers BEFORE all the maths and asterisks things are done? It looks like there is only one opportunity for input at present. To enable 5 numbers you'll need to use another loop ( eg. for() ) and an array to store them in.

    Hope this is of some use to you.
    Joyous Monkey

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.