AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

No compilation error but not the required output

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits
View previous topic :: View next topic  
Author Message
kt via JavaKB.com
Guest





PostPosted: Sat Apr 16, 2005 4:21 pm    Post subject: No compilation error but not the required output Reply with quote



This program is to input 20 numbers in the range 0 to 100 and display a
histogram that shows how many numbers are in the range 0 to 9, 10 to 19, 20
to 29..
public class Histogram extends Applet
{
private int [] num = {5, 7, 8, 19, 25, 30, 37, 41, 43, 50, 52, 55,
61, 63, 70, 76, 84, 91, 95, 98}; // input array

private int [] hist = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // histogram count

public void drawHist()
{
for( int i = 0; i {
hist[num[i] / 10] += 1;
}

}

public void paint (Graphics g)
{
int x = 20;
int y = 20;
int height = 40;


for(int i = 0; i < hist.length; i++)
{
drawHist();
int width = hist[i];
g.fillRect(x, y, width * 10, height);
x = x + 10;
}

}

}

But i see a solid black rectangle that stretches when the applet window is
dragged. It doesn't look like histogram. I don't know what am i doing wrong.
Any help appreciated,
Kt

--
Message posted via http://www.javakb.com
Back to top
Frederik Coppens
Guest





PostPosted: Sun Apr 17, 2005 5:50 pm    Post subject: Re: No compilation error but not the required output Reply with quote



You're drawing a number of horizontal lines that overlap.
That's why you see one big rectangle.
Also, you're calling drawHist 10 times. It's enough to call it once, before
the loop.

"kt via JavaKB.com" <forum (AT) nospam (DOT) JavaKB.com> schreef in bericht
news:343a05c04d714e1eb58b6ae453463e46 (AT) JavaKB (DOT) com...
Quote:
This program is to input 20 numbers in the range 0 to 100 and display a
histogram that shows how many numbers are in the range 0 to 9, 10 to 19,
20
to 29..
public class Histogram extends Applet
{
private int [] num = {5, 7, 8, 19, 25, 30, 37, 41, 43, 50, 52, 55,
61, 63, 70, 76, 84, 91, 95, 98}; // input array

private int [] hist = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // histogram count

public void drawHist()
{
for( int i = 0; i {
hist[num[i] / 10] += 1;
}

}

public void paint (Graphics g)
{
int x = 20;
int y = 20;
int height = 40;


for(int i = 0; i < hist.length; i++)
{
drawHist();
int width = hist[i];
g.fillRect(x, y, width * 10, height);
x = x + 10;
}

}

}

But i see a solid black rectangle that stretches when the applet window is
dragged. It doesn't look like histogram. I don't know what am i doing
wrong.
Any help appreciated,
Kt

--
Message posted via http://www.javakb.com



Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.