I need to reverse this problem, code included

Hello, I am trying to master Java and I have a long way to go. I am still trying to get a grip on the fundamentals. I have a program (the code is below) that I am trying to manipulate and get to do something a little different then it does. The program is basically used to teeach noobies (me) multithreading. This program (which I did not not write I have just been playing with it to learn different things) creates a ball (thread) and moves it 1000 times within the frame bouncing when it hits the wall on any side. I want to make it so the normal priority ball goes left to right and the high priority ball goes from top to bottom, but also when the button is pressed for either one to create a new ball it does not create one in the same spavce but a little bit over (the ball is sized to 15 so each time a new one is made it should move over the width of the ball + maybe 5 or 10) and by doing this i also have to make it so that if too many balls are made then it wont go off the screen but go backwards. I know I need to tweak the move method in class ball. I am trying to learn how to do this so I am not asking for an answer just guidence. If you can get me started I will figure it out and just post again as needed. Any help will be appreciated. Thankyou
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.*;
import javax.swing.*;
public class Bounce
   public static void main(String[] args)
      JFrame frame = new BounceFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.show();
class BounceFrame extends JFrame
   public BounceFrame()
      setSize(450,350);
      setTitle("Priority Threads");
      Container contentPane = getContentPane();
      canvas = new BallCanvas();
      contentPane.add(canvas, BorderLayout.CENTER);
      JPanel buttonPanel = new JPanel();
      addButton(buttonPanel, "Start-Normal Priority",
         new ActionListener()
               public void actionPerformed(ActionEvent evt)
                  addBall(Thread.NORM_PRIORITY, Color.red);
      addButton(buttonPanel, "Express-High Priroty",
         new ActionListener()
               public void actionPerformed(ActionEvent evt)
                  addBall(Thread.NORM_PRIORITY + 2, Color.black);
      addButton(buttonPanel, "Close",
         new ActionListener()
               public void actionPerformed(ActionEvent evt)
                  System.exit(0);
      contentPane.add(buttonPanel, BorderLayout.SOUTH);
   public void addButton(Container c, String title,
      ActionListener listener)
      JButton button = new JButton(title);
      c.add(button);
      button.addActionListener(listener);
   public void addBall(int priority, Color color)
      Ball b = new Ball(canvas, color);
      canvas.add(b);
      BallThread thread = new BallThread(b);
      thread.setPriority(priority);
      thread.start();
   private BallCanvas canvas;
class BallThread extends Thread
   public BallThread(Ball aBall) { b = aBall; }
   public void run()
      try
         for (int i = 1; i <= 1000; i++)
            b.move();
            sleep(5);
      catch (InterruptedException exception)
   private Ball b;
class BallCanvas extends JPanel
   public void add(Ball b)
      balls.add(b);
   public void paintComponent(Graphics g)
      super.paintComponent(g);
      Graphics2D g2 = (Graphics2D)g;
      for (int i = 0; i < balls.size(); i++)
         Ball b = (Ball)balls.get(i);
         b.draw(g2);
   private ArrayList balls = new ArrayList();
class Ball
   public Ball(Component c, Color aColor)
      canvas = c;
      color = aColor;
   public void draw(Graphics2D g2)
      g2.setColor(color);
      g2.fill(new Ellipse2D.Double(x, y, XSIZE, YSIZE));
   public void move()
      x += dx;
      y += dy;
      if (x < 0)
         x = 0;
         dx = -dx;
      if (x + XSIZE >= canvas.getWidth())
         x = canvas.getWidth() - XSIZE;
         dx = -dx;
      if (y < 0)
         y = 0;
         dy = -dy;
      if (y + YSIZE >= canvas.getHeight())
         y = canvas.getHeight() - YSIZE;
         dy = -dy;
      canvas.repaint();
   private Component canvas;
   private Color color;
   private int XSIZE=15;
   private int YSIZE=15;
   private int x = 0;
   private int y = 0;
   private int dx = 2;
   private int dy = 2;

I want to make it so the normal priority ball goes left to right and the high priority ball goes from top to bottom,You've only got the One Move() Method so all balls Move the same no matter what.
Maybe add some new Fields to the Ball Class and access them in your Move() method.
public Ball(Component c, Color aColor)
      canvas = c;
      color = aColor;
   }so maybe even:
public Ball( Component c, Color aColor ,int DX_forthisBall, int DY_forthisBall)with accessor methods for same
such as
public int getDX()
but also when the button is pressed for either one to create a new ball it does not create one in the same spavce but a little bit over (the ball is sized to 15 so each time a new one is made it should move over the width of the ball + maybe 5 or 10) Every Time You Create a New Ball
It has the same starting coordinates, because of your Code Design:
in the Canvas part:
private int x = 0;Modify your Constructor, to allow a Different initial position to be set, keep track of the Starting positions for each new Ball as you desire.
After a "Quick" look over your code, it seems all
Balls are created with various Colors and Priorities
However All are created Equal otherwise:
X=0 , Y = 0 ;dx =2 ; dy = 2; XSIZE = 15 ; YSIZE = 15
Perhaps you want to make it so that the Ball Class looks after
How Big each ball is and how fast and in which direction it moves.
So you would replace lines like:
if (x + XSIZE >= canvas.getWidth())
         x = canvas.getWidth() - XSIZE;
         dx = -dx;
      }with something like
Ball B; // this should refer to the currently being processed ball
// but is just here for example
if (x + B.getWidth() >= canvas.getWidth())
         x = canvas.getWidth() - B.getWidth();
         dx = -(Ball.getDX() );
      }SOme adaptation along those lines should do what you require

Similar Messages

  • Adobe Creative Cloud is needed to resolve this problem. However, it is missing or damaged

    Creative Cloud will not run without throwing up a window "Adobe Creative Cloud is needed to resolve this problem. However, it is missing or damaged. Please download and install a new copy of the Creative Cloud". I download the app and run the installer, and it simply throws up the same window over again... "Adobe Creative Cloud is needed to resolve this problem. However, it is missing or damaged. Please download and install a new copy of the Creative Cloud". I'm stuck in a loop! Can someone help me urgently please? I'm on system 10.9.5

    Hi tiff_meek,
    You can try the steps:
    For Mac
    Go to Applications-->Utilities-->Adobe Installers.
    Uninstall Adobe Creative Cloud.
    ** If it says application is running in the background then open Activity Monitor and close the process of Creative cloud.
    Once the creative cloud is uninstalled then follow the below mentioned steps:
    Please go to Library
        1. Click on Finder then Click on Go and Go to folder
        2. Type /Library and click on Go
        3. Go to Application Support and Adobe and then delete OOBE folder.
        4. Redo Step 1
        5. Type ~/Library and click on Go
        6. Go to Application Support and Adobe and then delete OOBE folder.
        7. Go to https://creative.adobe.com/products/creative-cloud?promoid=KLYVF
    Download Adobe Creative cloud, Install it.
    If the above steps do not work. Try enabling root user account and then try to open Adobe Creative cloud.
    Enable root user: Enabling and using the "root" user in Mac OS X
    Thanks,
    Nikhil Gupta

  • I desperately need to solve this problem even geeks on call could not

    I desperately need to solve this problem
    Posted: May 17, 2006 5:29 PM Reply Email
    How to Connecti computers over the internet using IP addresses
    Posted: Mar 8, 2006 7:18 PM
    Reply Email
    No one has been able to help me solve this problem even geeks on call
    So please out there give me some good advice. This feels like a level 5
    I have three computers at three different locations. The first one is a emac at my office running classic 9.2. The second location is a power book g4 running 10.4.5. at my home. The third is a power book g3 running OS 9.2.2at a third location.
    What I am trying to do is to access my computer at my office from the other two locations. My office has two computers that are on a network and talk to each other. They are both EMAC"S. They are connected by a ethernet network which is connected to a DSL modem which keeps me on the Internet all the time.
    At the other two locations I have direcway satellite which is broadband which also stays on all the time on the internet.
    I need to be able to access a data base on my main computer at my office and run the program which is an Omnis 7 program. I have multi user capabilities for this program, so that all the computers can access the data files at the same time and reqad and write.
    So this is my dileema.
    Any help would be greatly appreciated
    powerbook g3,emac Mac OS 9.2.x also 9.2 os, and 9.22 o.s.and 10.4
    eww
    Posts: 2,224
    Registered: Jul 28, 2000
    New! Re: I desperately need to solve this problem
    Posted: May 17, 2006 6:08 PM in response to: drpresseye

    well, at any or all of the locations you may need to open up the ports through your routers to allow ARD access.
    Also, I'm wondering if you are experiencing problems between using old and new versions of remote desktop.
    In any case, when you say you have multi-user capabilities, to me that implies that from location 2 and 3 you want to open the database file directly, not open it within an RDC session on a machine at location 1. That will be a different issue. Now you are talking about file shares over TCP/IP.

  • When I tried to open PS CC2014, it flashed a bit then quit, same with DW and INDD ... I also got this error message: Adobe creative cloud is needed to resolve this problem. However, it is missing or damaged. Please download and install a new copy of the C

    This morning when I tried to open my CC2014 Photoshop, it started to open, then quit suddenly. Same with Dreamweaver and InDesign. I am a professional and do not have the time to screw around with this. When I tried to run CC app, I get an error that says "Adobe creative cloud is needed to resolve this problem. However, it is missing or damaged. Please download and install a new copy of the Creative Cloud from 'http://www.adobe.com/go/adobecreativecloudapp'." I did so and tried to run the app and got the same error. I tried the cleaner and it removed all of my apps, then I tried to install again, and got the same error. I am getting desperate now, I have clients waiting for their projects. I need help, please.

    Allisonf55952352 have you utilized the steps listed in Error: "Failed to install" | Creative Cloud Desktop to resolve the current error?  If not do you have any questions regarding the steps listed with the document?

  • I have moved my file from my old computer.  Now that I am trying to play songs and movies iTunes says the original file could not be found.  How do I reverse this problem?

    I have moved my file from my old computer.  Now that I am trying to play songs and movies iTunes says the original file could not be found.  How do I reverse this problem?

    Put the files back where iTunes expects them to be.

  • I need make icloud account but tell me the operation couldn't be completed please iam need to solve this problem necessary, Thank you

    i need make icloud account but tell me the operation couldn't be completed please iam need to solve this problem necessary, Thank you

    Why don't you use the option "Get a Free Apple ID" to create a new iCloud account with a free @icloud.com email address for all the iCloud service like Mail, Contacts, Calendars, Reminders, Notes Storage & Backup etc.?
    This would be the easiest way.

  • I desperately need to solve this problem

    How to Connecti computers over the internet using IP addresses
    Posted: Mar 8, 2006 7:18 PM
    Reply Email
    I Can't believe that no one can help me with this problem. There were no responses in march so I am trying again.
    I have three computers at three different locations. The first one is a emac at my office running classic 9.2. The second location is a power book g4 running 10.4.5. at my home. The third is a power book g3 running OS 9.2.2at a third location.
    What I am trying to do is to access my computer at my office from the other two locations. My office has two computers that are on a network and talk to each other. They are both EMAC"S. They are connected by a ethernet network which is connected to a DSL modem which is on a static IP which keeps me on the Internet all the time.
    At the other two locations I have direcway satellite which is broadband which also stays on all the time on the internet.
    I need to be able to access a data base on my main computer at my office and run the program which is an Omnis 7 program. I have multi user capabilities for this program, so that all the computers can access the data files at the same time and reqad and write.
    So this is my dilema.
    I really need help

    In order to establish a secure connection into your
    office network you should really consider getting a
    VPN router.
    Once your router is configured you can then use a
    PPTP client to connect to your Office VPN server.
    Do I need a special VPN server or can one of my emacs double as a VPN server ?
    OS9 does not have built in vpn client so you need to
    use something like tunel builder.
    For your OSX mac you can use internet connect to
    establish a VPN connection.
    One your connection is established you can connect to
    the computers in your office as if your a local
    machine.

  • I buy I phone from USA and I use this I phone in Iraq I get this message  Please insert another SIM card from a supported carrier or request that this iPhone be unlocked by your carrier so I need to solve this problem

    Dear ,
    I buied I phone from USA and I sent to  Iraq to use it there but when used it I get this message :
    The SIM card that you currently have installed in this iPhone is from a carrier that is not supported under the activation policy that is currently assigned by the activation server. This is not a hardware issue with the iPhone. Please insert another SIM card from a supported carrier or request that this iPhone be unlocked by your carrier
    so I need support to resolve this problem and  procedure  and how I can  iPhone be unlocked.
    BR,
    Ammar Jumaa

    ammarjr wrote:
    ... how I can  iPhone be unlocked.
    Sorry...  but...  ONLY the US Carrier it is Locked to can unlock it.
    You need to Contact them.
    Note:  No one here will know who that Carrier is.

  • Hey guys i really need help with this problem...

    Hey guys how is everyone? I have a Soundblaster X-Fi XtremeMusic. and i am having a real annoying problem, here is how it all started. I took the time and dusted out my computer by using a can of air duster, and i think a little got on there and it turned into frost. Weird thing is it happened before and i never had this problem. I turn my computer on and crank the volume up i receive no sound what so ever. I know it has to work because i have a pair of DJ headset hooked into the jack, and i heard a little pop sound. And no audio, every last port on the card i cannot get no sound out of it except one of them, it's really annoying i hate this doing this and i have to hook my 5.1 using one jack just to get sound. And it doesnt sound good i have some really powerful 1,000 watt speakers with 2 amps. I know this is yet due to the fact i only have the lime jack in This is the only way it'll work. And i have a THX cable and it works sometime. I hope my soundcard isnt messed up. I really hope you guys can help me with this issue. I cannot contact creative cust service via email because i dont have my box no more, and my serial number is faded on the card (i think that was the serial)
    I try to explain the best way i can describe it. Below is my System Specs.
    <pre>Processor: AMD Athlon X3 425 @ 2.7GHz
    Video Card: ATI HD 5770 1GB
    Hard Drive:1TB Western Digital, 500GB Western Digital, 300GB Seagate (all SATA connections)
    Heatsink: Zalman CNPS7000C-Cu
    Power Supply: Antec 550 Watts True Power II
    Sound Card: Creative Soundblaster XI-FI Xtreme Music
    Motherboard: ASUS M4A79XTD EVO
    DVD Drives x2. Plextor DVD-RW/DL/ Sony DVD-ROM Drive via PATA connections</pre> Thanks in advance hope you all have a splended weekend.

    Hello
    Thank you for your help but unfortunately still have troubles with the soundcard.
    I upgraded my system to
    RAM: Corsair Vengeance LP 16GB DDR3
    Processor: AMD Phenom II X6 1090T Processor, Black Edition 3.3GHz
    Video Card: Sapphire 100314-3L Radeon HD 6870 1GB
    Hard Drive: 1TB Western Digital, 500GB Western Digital, 300GB Seagate (all SATA connections)
    Heatsink: Zalman CNPS7000C-Cu
    Power Supply: Corsair TX850W 850 Watt SLI/Crossfire Certified
    Sound Card: Creative Labs Soundblaster X-FI Titanium Fatal1ty Professional (getting this soon)
    Motherboard: ASUS M4A79XTD EVO (BIOS: 2102)
    DVD Drive(s): Plextor DVD-RW/DL/ Sony DVD-ROM Drive via PATA connections
    And i still run into problems i think its a matter of a hardware issue. The plugs dont really work
    only one does (where lime goes in) And the bass has toned down as well... Isn't as powerful
    as it used to be, so my best be is to upgrade to Creative Labs Soundblaster X-FI Titanium Fatal1ty Professional
    Thats my only hope...
    But again thank you for your help

  • OS X version 10.8.5; Email problem. Last Email received on my computer was on 5/27/2014. I need to fix this problem. I am receiving mail on my iPhone

    OS X version 10.8.5.
    Last Email was dated 5/27/2014. Can some one help me fix this problem?

    As a test launch iPhoto with the Option key held down and create a new, test library.  Import some photos and test to see if the same problem persists. Does it?

  • I try signing into iMessage and it takes about 45-50 seconds to do. When that happens it tells me there is a network problem. I am positive I don't have a network problem and I need help on this problem please??

    I try to sign in and it just takes forever to do I try and try and do it over and over and it brings me the same results. Created a new Apple ID and when I did it still tells me there is a network problem. But the thing is I am still able to use the Internet I need help?? And it does the exact same thing for FaceTime so I don't know what to do??

    Error -3259 is a network timeout error, usually. This article might help:
    http://support.apple.com/kb/TS2799

  • Need help with this problem.

    I have just updated my ipod and it is saying i need to connect it to my Apple iPod Power Adapter, the problem is that i do not have one.
    Is there anyway to reset the update process untill i get a adapter.
    I have tried resetting it with the instructions given on this site, but it is just showing a picture of the Apple iPod Power Adapter plug.

    When updating or restoring some iPods via a usb connection, it needs to be plugged into power via the charger to complete the process, and this is why you see that icon displayed. It's also why older iPods that required this step were supplied with a power adaptor as standard.
    You may be able to complete the process via a car charger, or via a powered firewire port on the computer (with the required 6 pin cable of course) if you have access to either of those. Or maybe visit an Apple store if one is nearby.
    Or you can try this.
    http://www.bearsdriving.com/blog/archives/2005/10/youripod_tipo.html
    Other than that, your iPod cannot be used until you complete this process.

  • I need help solving this problem!!

    Hi, i'm new to java and have written only a few programs, i recently wrote one and had the following error but dont know why...........
    Exception in thread "main" java.lang.NoClassDefFoundError: quadraticsolverApp
    I have included my code below.....
    import java.applet.Applet;
    public class quadraticsolver extends Applet
    public double a, b, c ;
    public void init()
    a=0;
    b=0;
    c=0;
    public String getRoot1()
    if (getDescriminent() < 0.0 || this.a == 0.0)
    return "" + ((-b + Math.sqrt(-getDescriminent()))/(2 * a)) + " i";
    else
    return "" + ((-b + Math.sqrt(getDescriminent()))/(2 * a));
    public String getRoot2()
    if (getDescriminent() < 0.0 || a == 0.0)
    return "" + ((-b - Math.sqrt(-getDescriminent()))/(2 * a)) + " i";
    else
    return "" + ((-b - Math.sqrt(getDescriminent()))/(2 * a));
    public double getDescriminent()
    return (b*b - 4 * a * c);
    public void setA(double bValue)
    a = bValue;
    public void setB(double bValue)
    b = bValue;
    public void setC(double bValue)
    c = bValue;
    Thanks for the help
    Noel
    email: [email protected]

    Besides that, the code is broken. For instance
    return "" + ((-b - Math.sqrt(-getDescriminent()))/(2 * a)) + " i";should be
    return "" + (-b/(2*a)) + " " + (-Math.sqrt(-getDescriminent())/(2 * a)) + " i";
    to get correct answers... 1/2 * (-1-sqrt(3)) i (or approximately -1.36602540 i) is not a solution of x^2 + x + 1 = 0. Also, if a is small, it's better to use the formula x = 2*c / (-b +/- sqrt(b^2 - 4ac))

  • Need Sql for this problem

    Hi Gurus
    I have below situtation which need to be sorted out by SQL (10g version)
    Below is the sample data.
    Date     Amt1     Amt2     Amt3     Totl
    201009     10     10     10     30
    201010     20     20     20     90
    201011     30     20     10     150
    Totl is the calculation field and remaining data is available in DB table say tab1. If you see logic of identifying Totl --> addition of Amt1,Amt2,Amt3 with Totl of prev month. For 201010 it is 20+20+20 =60 and this 60 will need to added to 201009 totl 30 and hence final sum is 90.
    Please provide to resolve this.

    You need to do cumulative sum.
    with t
    as
    select 201009 dt, 10 a1, 10 a2, 10 a3 from dual union all
    select 201010, 20, 20, 20 from dual union all
    select 201011, 30, 20, 10 from dual
    select dt, a1, a2, a3, sum(a1+a2+a3) over(order by dt) tot
      from t

  • Need to solve this Problem

    i try to read the whole text that i'm getting from the inputStream,but the text contains "\n" it means that if i use readLine to read the text, i only get the first line, If i use while (readLine() != null) i can read the whole text that i want, but the program still loop, i cannot break the application..
    How can i solve this?
    thanks guys you're the best...

    The output that i want to get is like this
    /$****************************************************************]** YOU ARE NOW WORKING ON SYSTEM -A- LIVE **]****************************************************************]
    A-IN AM/HM FQX * GA RES FQX *
    ^|
    the problem is, if i use
    int c;
    while ((c = in.read()) != -1)
    i can see i got something,but not finish to the end of text...
    if i use :
    while (bfr.readLine() != null)
    i get the whole text but my program wont end, it means the loop is still around...am i right? correct me if i'm wrong....
    The text that i want to get is contains (Carriage return)...
    Help....thanks

Maybe you are looking for

  • How to share music/itunes folder between 2 imacs on a network?

    I  have a mac network.(my imac, 2 ipads and 2 iphones 4s. My wife just bought a Imac i5 that we added to our network. Now we want to move out Music/tunes folder from my home directory to an external drive so we can access from either mac. How do I se

  • IMessage not working like it should!

    I have a problem that I'm sure other people have as well. The problem in a few words is that iMessage is not capable of fast switching between Wi-Fi and cellular network. Example 1: When I am texting with my girlfriend and I'm inside my house, but a

  • Itunes 11.1.5 not recognizing ipod classic 160gb

    After updating itunes my ipod classic 160 gb is not recognized by itunes and now simply crashed...  any help please?

  • How to sync my mac iCal to iPhone 4s?

    Is there any instruction on how to sync ical to iphone 4S?

  • MacBook Pro stopped reading discs, ejects them

    I bought this MacBook Pro in December of '08 (referbished, but from the apple website) and shortly after had a problem with the drive not reading discs and making odd noises. Took it in and they replaced it under the 90 day warranty. I haven't used t