Need help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Need help

  1. #1
    Join Date
    Jan 2006
    Posts
    2

    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

  2. #2
    Join Date
    Aug 2005
    Location
    Melbourne...Australia
    Posts
    279
    What do you have so far?

  3. #3
    Join Date
    Jan 2006
    Posts
    2
    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);
    }
    }
    }

  4. #4
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    balls can be drawn with

    Code:
    g.fillOval(int x, int y, int width, int height);
    and boxes (only outline) with

    Code:
    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?

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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

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