Need help
i need some help on how to draw 2D box and circle using loops under this condition...any1 kind enough to help me?
max amount of balls a box can hold is 50 balls ( 5 length x 10 height)
box and ball is a variable
[225 byte] By [
D4rkS0uL] at [2007-11-11 7:53:36]

# 2 Re: Need help
this is wad i have currently and i also have another problem which is that the ballValue and boxValue beside the scrollbar does not refresh...
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Division extends Applet implements AdjustmentListener {
int ballValue=0;
int boxValue=0;
int extra,noex;
Scrollbar ball,box;
Panel p1;
public void adjustmentValueChanged(AdjustmentEvent event){
ballValue = ball.getValue();
boxValue = box.getValue();
repaint();
}
public void init() {
p1 = new Panel();
p1.setLayout(new GridLayout(2,3));
p1.add(new Label("Enter number of balls : "));
p1.add(ball = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,501));
p1.add(new Label(""+ballValue));
p1.add(new Label("Enter number of boxes : "));
p1.add(box = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,11));
p1.add(new Label(""+boxValue));
add(p1);
ball.addAdjustmentListener(this);
box.addAdjustmentListener(this);
}
public void paint(Graphics g) {
extra= ballValue%boxValue;
noex= ballValue/boxValue;
if((ballValue%boxValue==0)||(boxValue==1))
{ g.drawString("Each box contains "+noex+" ball(s).",100,100);}
else if(boxValue>ballValue)
{ g.drawString("Not enough balls for "+boxValue+" boxes!!",100,100);}
else{
g.drawString("Can't divide "+ballValue+" balls equally into "+boxValue+" boxes!!",100,100);
g.drawString("There are "+extra+" balls left after division!!",100,120);
}
}
}
# 3 Re: Need help
balls can be drawn with
g.fillOval(int x, int y, int width, int height);
and boxes (only outline) with
g.drawRect(int x, int y, int width, int height);
See javadoc for class Graphics for more details.
But i have to say that I'm not shure about what you intend to do.
Where are the coordinates of your balls and boxes and how do you want them to be drawn?