Anybody knows how to bounce them off the edge of the frame ...

I want them to change position randomly and smothly and also bounce off the edge of the frame. i will be so happy if you can help me.
Here is the code:
FlatWorld:
import java.awt.*;
import javax.swing.*;
import java.util.*;
* This FlatWorld contains random number(between 1 and 10) of disks
* that can be drawn on a canvas.
public class FlatWorld
    // initialize the width and height of the Canvas in FlatWorld...
    final int WIDTH = 400;
    final int HEIGHT = 400;
    // create random numbers of disks (1-10) using array.
    Random myRandom = new Random();
    int numbersOfDisks = myRandom.nextInt(10) + 1;
    Disk myDisk[] = new Disk[numbersOfDisks];
    // The Canvas on which things can be drawn or painted...
    private Canvas myCanvas;
    * creates a Canvas and disks
   FlatWorld()
        //Creates our disks using array.
        for( int i = 0; i < numbersOfDisks; i++ )
            myDisk[i] = new Disk(WIDTH,HEIGHT);
        //creates a canvas and store it in the instance variable...
        myCanvas = new Canvas(WIDTH,HEIGHT,this);
   /* Draws our disks using array.
    * @param graphicsContext The Graphics context required to do the drawing.
    * Supplies methods like "setColor" and "fillOval". */
   public void drawYourself(Graphics graphicsContext)
        for (int i = 0; i < numbersOfDisks; i++)
            myDisk.drawDisk(graphicsContext);
public void change()
final int movementScale = 8;
for (int i = 0; i < numbersOfDisks; i++)
int deltax = (int)( Math.random() - 0.5 * movementScale );
int deltay = (int)( Math.random() - 0.5 * movementScale );
myDisk[i].move(deltax, deltay);
Disk:
import java.awt.*;
import java.util.*;
* The Disk class is used to creates a disk with a random position
* and a random color and a random diameter (between 1/20 width and 1/4 width)
public class Disk
    /* instance variables */                    
    private int x;
    private int y;
    private int Diameter;
    private Color randomColor;
    private int red, green, blue;
     * Constructor for objects of class Disk
    //creat a disk at a 2D random position between width and height
    public Disk(int width, int height)
        /* Generates a random color red, green, blue mix. */
        red =(int)(Math.random()*256);
        green =(int)(Math.random()*256);
        blue =(int)(Math.random()*256);
        randomColor = new Color (red,green,blue);
        /* Generates a random diameter between 1/20 and 1/4 the width of the world. */
        double myRandom = Math.random();
        Diameter = (width/20) + (int)(( width/4 - width/20 )*myRandom);
        /* Generates a random xy-offset.
         * If the initial values of the xy coordinates cause the disk to draw out of the boundry,
         * then the x and/or y will change their values in order to make the whole disk visible in
         * the boundry. */
        int randomX = (int)(Math.random() * width);
        int randomY = (int)(Math.random() * height);
        int endPointX = randomX + Diameter;
        int xPixelsOutBound = endPointX - width;
        if ( endPointX > width)
            randomX = randomX - xPixelsOutBound;
        int endPointY = randomY + Diameter;
        int yPixelsOutBound = endPointY - width;
        if ( endPointY > width)
            randomY = randomY - yPixelsOutBound;
        setXY(randomX , randomY);
        /* replace values of newX and newY (randomX and randomY) into the x and y variables
         * @param newX The x-position of the disk
         * @param newY The y-position of the disk */
        public void setXY( int newX, int newY )
            x = newX;
            y = newY;
        /* Draw a disk by its coordinates, color and diameter...
         * @param graphicsContext The Graphics context required to do the drawing.
         * Supplies methods like "setColor" and "fillOval". */
        public void drawDisk(Graphics graphicsContext)
            graphicsContext.setColor(randomColor);
            graphicsContext.fillOval( x , y, Diameter , Diameter );
        public void move (int deltaX, int deltaY)
            x = x + deltaX;
            y = y + deltaY;
}[i]Canvas:import java.awt.*;
import javax.swing.*;
public class Canvas extends JPanel
// A reference to the Frame in which this panel will be displayed.
private JFrame myFrame;
// The FlatWorld on which disks can be create...
FlatWorld myFlatWorld;
* Initialize the Canvas and attach a Frame to it.
* @param width The width of the Canvas in pixels
* @param height The height of the Canvas in pixels
public Canvas(int width, int height, FlatWorld sourceOfObjects)
myFlatWorld = sourceOfObjects;
// Set the size of the panel. Note that "setPreferredSize" requires
// a "Dimension" object as a parameter...which we create and initialize...
this.setPreferredSize(new Dimension(width,height));
// Build the Frame in which this panel will be placed, and then place this
// panel into the "ContentPane"....
myFrame = new JFrame();
myFrame.setContentPane(this);
// Apply the JFrame "pack" algorithm to properly size the JFrame around
// the panel it now contains, and then display (ie "show") the frame...
myFrame.pack();
myFrame.show();
* Paint is automatically called by the Java "swing" components when it is time
* to display or "paint" the surface of the Canvas. We add whatever code we need
* to do the drawing we want to do...
* @param graphics The Graphics context required to do the drawing. Supplies methods
* like "setColor" and "fillOval".
public void paint(Graphics graphics)
// Clears the previous drawing canvas by filling it with the background color(white).
graphics.clearRect( 0, 0, myFlatWorld.WIDTH, myFlatWorld.HEIGHT );
// paint myFlatWorld
myFlatWorld.drawYourself(graphics);
//try but if --> {pauses the program for 100 miliseconds} dont work -->
try {Thread.sleep(70);}
     catch (Exception e) {}
     myFlatWorld.change();
     repaint();

Here is my contribution:
FlatWorld:
import java.awt.*;
import javax.swing.*;
import java.util.*;
* This FlatWorld contains random number(between 1 and 10) of disks
* that can be drawn on a canvas.
public class FlatWorld {
   // initialize the width and height of the Canvas in FlatWorld...
   final int WIDTH = 400;
   final int HEIGHT = 400;
   // create random numbers of disks (1-10) using array.
   Random myRandom = new Random();
   int numbersOfDisks = myRandom.nextInt(10) + 1;
   FlatWorldDisk myDisk[] = new FlatWorldDisk[numbersOfDisks];
   // The Canvas on which things can be drawn or painted...
   private FlatWorldCanvas myCanvas;
    * creates a Canvas and disks
   public FlatWorld() {       
        //Creates our disks using array.
        for( int i = 0; i < numbersOfDisks; i++ ) {
            myDisk[i] = new FlatWorldDisk(WIDTH,HEIGHT);
        //creates a canvas and store it in the instance variable...
        myCanvas = new FlatWorldCanvas(WIDTH,HEIGHT,this);
   /* Draws our disks using array.
    * @param graphicsContext The Graphics context required to do the drawing.
    * Supplies methods like "setColor" and "fillOval". */
   public void drawYourself(Graphics graphicsContext) {
        for (int i = 0; i < numbersOfDisks; i++) {
            myDisk.drawDisk(graphicsContext);
public void change() {
final int movementScale = 8;
for (int i = 0; i < numbersOfDisks; i++) {
int deltax = (int)( Math.random() - 0.5 * movementScale );
int deltay = (int)( Math.random() - 0.5 * movementScale );
myDisk[i].move(deltax, deltay, WIDTH, HEIGHT);
public static void main(String[] args) {
new FlatWorld();
FlatWorldDisk:
import java.awt.*;
import java.util.*;
* The FlatWorldDisk class is used to creates a disk with a random position
* and a random color and a random diameter (between 1/20 width and 1/4 width)
public class FlatWorldDisk {
   /* Constants */
   private static final int DIRECTION_NW = 1;
   private static final int DIRECTION_N  = 2;
   private static final int DIRECTION_NE = 3;
   private static final int DIRECTION_W  = 4;
   private static final int DIRECTION_E  = 5;
   private static final int DIRECTION_SW = 6;
   private static final int DIRECTION_S  = 7;
   private static final int DIRECTION_SE = 8;
   /* instance variables */               
   private int x;
   private int y;
   private int diameter;
   private Color randomColor;
   private int red, green, blue;
   private int direction;
    * Constructor for objects of class FlatWorldDisk
   //creat a disk at a 2D random position between width and height
   public FlatWorldDisk(int width, int height) {
      /* Generates a random color red, green, blue mix. */
      red =(int)(Math.random()*256);
      green =(int)(Math.random()*256);
      blue =(int)(Math.random()*256);
      randomColor = new Color (red,green,blue);
      /* Generates a random diameter between 1/20 and 1/4 the width of the world. */
      double myRandom = Math.random();
      diameter = (width/20) + (int)(( width/4 - width/20 )*myRandom);
      /* Generates a random xy-offset.
       * If the initial values of the xy coordinates cause the disk to draw out of the boundry,
       * then the x and/or y will change their values in order to make the whole disk visible in
       * the boundry. */
      int randomX = (int)(Math.random() * width);
      int randomY = (int)(Math.random() * height);
      int endPointX = randomX + diameter;
      int xPixelsOutBound = endPointX - width;
      if (endPointX > width) randomX = randomX - xPixelsOutBound;
      int endPointY = randomY + diameter;
      int yPixelsOutBound = endPointY - width;
      if (endPointY > width) randomY = randomY - yPixelsOutBound;
      setXY(randomX , randomY);
      /* Generates a random direction */
      direction = (int)(Math.random() * 8) + 1;
   /* replace values of newX and newY (randomX and randomY) into the x and y variables
    * @param newX The x-position of the disk
    * @param newY The y-position of the disk */
   public void setXY(int newX, int newY) {
      x = newX;
      y = newY;
   /* Draw a disk by its coordinates, color and diameter...
    * @param graphicsContext The Graphics context required to do the drawing.
    * Supplies methods like "setColor" and "fillOval". */
   public void drawDisk(Graphics graphicsContext) {
      graphicsContext.setColor(randomColor);
      graphicsContext.fillOval( x , y, diameter , diameter );
   public void move(int deltaX, int deltaY,
                    int width, int height) {
      int dx = Math.abs(deltaX);
      int dy = Math.abs(deltaY);
      int olddir = direction;
      int newdir = olddir;
      switch(olddir) {
         case DIRECTION_NW: { int newX = x - dx, newY = y - dy;
                              if ((newX < 0) && ((y - dy) < 0))         newdir = DIRECTION_SE;
                              else if (((newX) >= 0) && ((y - dy) < 0)) newdir = DIRECTION_SW;
                              else if (((newX) < 0) && ((y - dy) >= 0)) newdir = DIRECTION_NE;
                              if (newdir != olddir) {
                                 direction = newdir;
                                 move(deltaX, deltaY, width, height);
                              else {
                                 x = newX; y = newY;
                              break;
         case DIRECTION_N:  { int newY = y - dy;
                              if ((newY) < 0) newdir = DIRECTION_S;
                              if (newdir != olddir) {
                                 direction = newdir;
                                 move(deltaX, deltaY, width, height);
                              else {
                                 y =newY;
                              break;
         case DIRECTION_NE: { int newX = x + dx, newY = y - dy;
                              if (((newX + diameter) > width) && (newY < 0))       newdir = DIRECTION_SW;
                              else if (((newX + diameter) > width) && (newY >= 0)) newdir = DIRECTION_NW;
                              else if (newY < 0)                                   newdir = DIRECTION_SE;
                              if (newdir != olddir) {
                                 direction = newdir;
                                 move(deltaX, deltaY, width, height);
                              else {
                                 x = newX; y = newY;
                              break;
         case DIRECTION_W:  { int newX = x - dx;
                              if (newX < 0) newdir = DIRECTION_E;
                              if (newdir != olddir) {
                                 direction = newdir;
                                 move(deltaX, deltaY, width, height);
                              else {
                                 x = newX;
                              break;
         case DIRECTION_E:  { int newX = x + dx;
                              if (newX + diameter > width) newdir = DIRECTION_W;
                              if (newdir != olddir) {
                                 direction = newdir;
                                 move(deltaX, deltaY, width, height);
                              else {
                                 x = newX;
                              break;
         case DIRECTION_SW: { int newX = x - dx, newY = y + dy;
                              if ((newX < 0) && ((newY + diameter) > height))     newdir = DIRECTION_NE;
                              else if (newX <0)                                   newdir = DIRECTION_SE;
                              else if ((newY + diameter) > height)                newdir = DIRECTION_NW;
                              if (newdir != olddir) {
                                 direction = newdir;
                                 move(deltaX, deltaY, width, height);
                              else {
                                 x = newX; y = newY;
                              break;
         case DIRECTION_S:  { int newY = y + dy;
                              if ((newY + diameter) > height) newdir = DIRECTION_N;
                              if (newdir != olddir) {
                                 direction = newdir;
                                 move(deltaX, deltaY, width, height);
                              else {
                                 y =newY;
                              break;
         case DIRECTION_SE: { int newX = x + dx, newY = y + dy;
                              if (((newX + diameter) > width) && ((newY + diameter) > height)) newdir = DIRECTION_NW;
                              else if ((newX + diameter) > width)                              newdir = DIRECTION_SW;
                              else if ((newY + diameter) > height)                             newdir = DIRECTION_NE;
                              if (newdir != olddir) {
                                 direction = newdir;
                                 move(deltaX, deltaY, width, height);
                              else {
                                 x = newX; y = newY;
                              break;
FlatWorldCanvas remains unchanged.
Hope this will help,
Regards.

Similar Messages

  • I recently downloaded Ios 7 and all the songs that i have purchased before but deleted off my itunes because i didn't want them showed up. I don't know how to delete them off my ipod and i really don't want them there

    I recently downloaded Ios 7 and all the songs that i have purchased before, but deleted off my itunes because i didn't want them, showed up. I don't know how to delete them off my ipod and i really don't want them there. Is there a way to get them off? The songs dont show up in my itunes on my computer, just on my ipod with a download button next to them. I don't want them there anymore because i don't like that kind of music anymore and i don't know how to get them to go away.

    There is a similar setting for Videos on that Settings screen, so if you leave that 'on' you may have similar happening in the Videos app

  • I had a iphone 4 and upgraded to a 5s, I backed up my photos to icloud on my 4 but now do not know how to access them now that I have the 5s.  So I can't retreive my 400 pix from my old backup. Help!????

    I just upgraded from an iphone 4 to 5a s, I backed up all my photos to the cloud with the 4 but now cannot access them with my 5s.  Does anyone know how to do this?  Help?

    Did you restore the backup of your iPhone 4 to your iPhone 5?  That would restore the camera roll photos along with app data, text messages, ringtones, apps and other purchased media, etc.

  • I had a 3rd Gen iPad. I did not get the pictures off of it. They are all in iCloud, I can not find out for the life of me how to get them off of iCloud without the iPad that I do not have anymore, I sold it. Any help would be epic. Thank you in advance!

    I have an iPhone 5 now that is also in my iCloud, yet it won't let me access the iPad iCloud.
    I would love to have all the pictures from the iPad iCloud backup.

    Really?? No one knows??  
    This is an Apple support forum is it not?
    If anyone can at least point me in the right direction that would be great!!

  • I have a new Mac and want to install my CS2.  Anybody know how I can do this?  I have the original discs and SN.

    I have an old Mac that has my original CS2 on it.  I am having trouble because the activation server is down for CS2, but I have the discs.  I'm confused about why I can't still download the software I purchased years ago.  Please help!
    Carissa

    CS2 cannot be installed on modern Macs (which use Intel processors) running OS X Yosemite (10.10).
    CS2 is a PowerPC application which can only run on older PowerPC Macs.
    Intel Macs can run PowerPC apps but only when Rosetta is installed. Apple discontinued Rosetta in OS X 10.7.
    Rosetta (software) - Wikipedia, the free encyclopedia
    To run CS2 on older PowerPC Macs, you must install the non-activation version of CS2 and use the new serial number provided by Adobe
    Error: Activation Server Unavailable | CS2, Acrobat 7, Audition 3

  • I have a very light scrach in my iPod touch screen anybody know how to get them out

    Iinhave a light scratch in my iPod touch 4th gen screen and am wondering if there is a way to get the scratch out any suggestions help

    I would just leave it be. You can havesone try to polish the scratch out but it may make the screen hazy

  • I just updated the software on my Apple TV, and now the closed captioning is not working. Somebody had the same problem? Anybody knows how to fix it?

    I just updated the software on my Apple TV, and now the closed captioning is not working. Somebody had the same problem? Anybody knows how to fix it?

    I just updated the software on my Apple TV, and now the closed captioning is not working. Somebody had the same problem? Anybody knows how to fix it?

  • When I connect my Mac Mini 2011 with Lion to a TV via HDMI and an earphone cable is plugged in, it´s not possible to choose sound out via hdmi, as opposed to connection via minidisplay port. Anybody knows how to fix this?

    When I connect my Mac Mini 2011 with Lion to a TV via HDMI and an earphone cable is plugged in, it´s not possible to choose sound out via hdmi, as opposed to connection via the minidisplay port. Anybody knows how to fix this?

    Was just on the phone with Apple about this.
    The solution was as follows for me anyway...
    Go to your Finder
    Choose the Go Menu
    Choose Computer
    Choose your Macintosh Hard Drive
    Choose your "Library" Folder
    Choose the "Preferences" Folder
    There should be a folder called "Audio"
    Move that whole folder to the trash
    Empty the Trash
    Restart from the Apple Menu
    When you are back up and running;
         Choose System Preferences from the Apple Menu
         Choose Sound
          In the output tab you should now be able to make the HDMI "Sticky"
          Enjoy your sound over HDMI and no more dirty knees or broken backs unplugging the desktop speakers!
    Mac Mini 2011 2.5Ghz 8 GB of RAM - Planar 17" VGA via display port adapter and Samsung 26" LCD TV via HDMI

  • I need to erase the contents of my phone and restore to factory settings. Does anybody know how to save your texts so you don't lose them?  Can I back those up to iCloud?  My phone was very likely hacked (Apple's advice was to call the police!)

    "I need to erase the contents of my phone and restore to factory settings. Does anybody know how to save your texts so you don't lose them?  Can I back those up to iCloud?  My phone was very likely hacked (Apple's advice was to call the police!)"
    That was all I could put in the initial "box."  Then it brought me to this page with instructions on how to write a good sentence.
    Proceeding ...
    After going back and forth between Apple, AT&T and the police (all telling me to go to the other two) I took AT&Ts suggestion and got a new number. One tech warned against doing a backup, especially on my Mac, saying if my phone had been hacked then whatever bug was there would then invade my computer. But nobody knows how to determine if the phone has been hacked or a virus was planted there. Unfortunately I know who would have reason to do such a thing and all I can say is that he is at the top technologically and could easily do it. Almost impossible to prove, however.
    So I need to preserve my text messages and my emails as well. I backed up my photos to that Microsoft product (One-Drive) and it froze (Surprise, Surprise) with four short videos to go, and no way of stopping that (when I tried it crashed repeatedly) so I'm in crisis mode here.
    Help ...
    Running 8.0 on 5S
    Thanks!

    Betty I don't know if you fixed your hacking problem but I feel your pain. I've seen some strange things going on between my iMac and my iPhone and Apple has told me the same thing, call the police which I have done. The hackers have stole 500.00 out of my checking account have access to every internet account I use and no matter how often I change the password their right back on the account. I closed my FB account 3 times only to have someone reopen it. Right now I've got a link in my reading list (Safari) that if I click on it, it allows me to log onto my FB account anonymously.
    I've seen a green folder come out of no where while I was trying to delete my passwords out of keychain when that green folder was put into the key chain I was immediately locked out. I than went into system preferences to try to make changes to my security settings, when I clicked on the icon it wouldn't open. I've seen log files of automator receiving commands and sending out my personal information thats on my computer.
    I have a legitamate program called iExplorer that allows you to look at the contents of your iPhone back ups and saw a transaction someone made at the Apple store for some full length movies, some albums, ibooks and other apps but when I called the iTunes store and they said none of those items were showing up on my account. If their not on my account how can they be on my iPhone 6? One day someone was using my gmail account and unknowingly used google maps to search for an Italian restaurant, than a Mexican restaurant than a coffee shop and their search showed up on my iPhone but I didn't have my gmail account installed on my iPhone 6. Using my computer I logged onto my gmail account and looked at the maps history and sure enough there were the searches when I'd hover my curser over the link it gave me the longitude and latitude of the where the hacker was when he was using google maps. I know whoever reads this thinks Im crazy but I've documented everything and can prove the things that I have mentioned in this post actually happened.
    One day I had my laptop (pc) and my iMac next to each other as I was using both. when I clicked on airport it showed that my laptop and my iMac had made a connection and were actually communicating with each other. I know I didn't do it I don't know how. The iMac was logged into my iCloud account while my laptop wasn't. I have formatted my iPhone at least a dozen times, Apple and an Apple retailer have formatted my hard drive not to mention the numerous times I have formatted it but the hackers keep getting on my devices. Im formatting my lap top at this very second because during the course of the night I left the ethernet cable plugged into it and they locked me out of my c: drive, and configured the system so I can't download any updates from Microsoft, overtime I type in www.microsoft.com it changes to ww38.microsoft.com which takes me to a blank page. I right clicked on the page I was redirected to and read the java script and couldn't believe that someone had actually configured Internet Explorer to redirect me to a blank page when I tried to go to Microsoft. Apples answer to all this is there was nothing wrong with my iPhone or my iMac and if I thought there was a problem to call the police which I have done.
    Theres no doubt the hackers are reading this while I type it or will read it and I simply don't care anymore. I no longer email anyone, don't use my iCloud account and have taken precautions to protect my credit but if I ever find out who has invaded my privacy to this extreme the police are going to want to talk to me because Im going to hurt them like they've never been hurt before

  • Suddenly, time machine is very slow. Used to take up a minute and now more than half an hour. Does anybody know how this can happen? Indexing the back-up disk is off, but Timde Machine keeps on indexing!

    Suddenly, time machine is very slow. Used to take up a minute and now more than half an hour. Does anybody know how this can happen? Indexing the back-up disk is off, but Timde Machine keeps on indexing!

    same issue here...

  • With IOS7, how do you turn off the apps running in the background?  I know how to pull them up with the double tap but how to shut them down so one doesn't have too many running?

    With IOS 7, how do you tunr off apps running in background?  I know to double click to bring up the apps running in the multitask function but not how to turn them off.  I know if too many apps are running, it is a mess.  Help.  Could not find in instructions anywhere.

    First, Double Tap the home button.  Then after that slide up the pictures of apps then there closed.
         Jake

  • HT1339 My ipod is stuck at step 9 in this guide. Itunes told me to keep my ipod connected to itunes, and my Ipod shows the Apple logo as it should (though I can´t see any progress bar). Do anybody know how  long step 9 takes. I have turned off my firewall

    My ipod is stuck at step 9 in this guide. Itunes told me to keep my ipod connected to itunes, and my Ipod shows the Apple logo as it should (though I can´t see any progress bar). Do anybody know how  long step 9 takes. I have turned off my firewall.
    Please Help!

    If it happens again and the reset (home + power buttons) doesn't work, just let the battery drain; you'll know when the screen shuts off. Charge it back up and it should be fine. Frankly, I'm surprised this worked for you. Usually I hear people with this problem say that holding both buttons doesn't work, and they have to do the battery drain.
    If the issue is incurable next time, you have a one-year warranty from the date of purchase.

  • HT4623 the wifi turn-on/off feature does not work on my iphone... it's stuck on off and won't turn on. Does anybody know how to fix it?

    the wifi turn-on/off feature does not work on my iphone... it's stuck on off and won't turn on. Does anybody know how to fix it?

    Hello khalidbadir,
    I would be concerned too if my touchscreen was not responding on my iPhone.  I recommend following the steps in this article to address an unresponsive touchscreen:
    iPhone, iPad, iPod touch: Troubleshooting touchscreen response
    http://support.apple.com/kb/ts1827
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • I began to purchase songs off iTunes, a prompt message appears whether you want to buy the song after the first click... I ticked the box to say I didn't want this warning again... But now I wish I had that - Anybody know how to get that message back???

    I began to purchase songs off iTunes, a prompt message appears whether you want to buy the song after the first click... I ticked the box to say I didn't want this warning again... But now I wish I had that - Anybody know how to get that warning/prompt message back???

    Sign-in to your iTunes Store account (Store menu > View my account).
    At the bottom of the Account Information page is a Reset box to click to reset all warnings for buying and downloading.  Click the "Done" button when you're finished.

  • HT1933 I have been charged for downloading Indira Budiman from itunes multiple times, how to report to itunes?  Is anybody else also having problems like this? And also need to know how to block them from charging again?

    I have been charged for downloading Indira Budiman from itunes multiple times, how to report to itunes?  Is anybody else also having problems like this? And also need to know how to block them from charging again?

    I don't know who/what Indira Budiman is, but you can contact iTunes Support via this page : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption
    If it's an app then does it allow you to make in-app purchases within it ? If it does then you can turn off in-app purchases via Settings > General > Restrictions on your device.

Maybe you are looking for