Code not working, anyone know why?

I'm making a simple pong game, and it's important to me that I use JAVA as efficient as possible (that is, use object orientated stuff, mostly). So, for drawing the ball and the players, I had thought up the following steps:
- the applet has an array list that contains drawables*
- if the ball and players need to be drawn, the applet uses a for-each loop, wich will call the draw(Graphics g) of all the drawables in the array list.
* interface, guarantees that the method public void draw(Graphics g) is pressent.
This is how I programmed it:
http://willhostforfood.com/access.php?fileid=32821
Only problem is, it doesn't work. The method paint() of the applet should result in "Hello World" being drawn on the screen (I know this seems like an eleborate method, but using seperate objects will help organise things once I have like, 20 - 30 balls on screen), but it doesn't.
Does anyone know why it is not working?

Here ya go, this is something I did quite a while ago, knock yourself out:
package RandomColor;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.Image;
import java.awt.image.MemoryImageSource;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.Point;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.util.Random;
public class RandomColor extends JFrame implements MouseListener, MouseMotionListener, MouseWheelListener{
  private BufferedImage myImage = null;
  private Canvas myCanvas = null;
  private Color bgColor = Color.BLACK;
  public RandomColor() throws java.lang.Exception {
    super();
    setUndecorated(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setBackground(bgColor);
    Dimension myDimension = Toolkit.getDefaultToolkit().getScreenSize();
    setSize(myDimension);
    setMinimumSize(myDimension);
    JPanel myJP = new JPanel();
    myJP.setBackground(bgColor);
    Dimension dImage = new Dimension(this.getAccessibleContext().getAccessibleComponent().getSize());
    myCanvas = new Canvas();
    myCanvas.addMouseListener(this);
    myCanvas.addMouseMotionListener(this);
    myCanvas.addMouseWheelListener(this);
    myCanvas.setSize(dImage.width, dImage.height);
    myJP.add(myCanvas);
    add(myJP);
// start of code to hide the cursor   
    int[] pixels = new int[16 * 16];
    Image image = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(16, 16, pixels, 0, 16));
    Cursor transparentCursor = Toolkit.getDefaultToolkit().createCustomCursor(image, new Point(0, 0), "invisiblecursor");
    getContentPane().setCursor(transparentCursor);
// end of code to hide cursor   
    pack();
    setVisible(true);
    Random myR = new Random();
    myImage = new BufferedImage((int) (dImage.getWidth()+0.99), (int) (dImage.getHeight()+0.99), BufferedImage.TYPE_INT_RGB);
    int i = myImage.getWidth();
    int j = myImage.getHeight();
    Ball[] myBall = {new Ball(), new Ball(), new Ball()};
    for (int k=0; k<myBall.length; k++){
      myBall[k].setBackGroundColor(Color.BLACK);
      myBall[k].setBounds(0, i, 0, j);
      myBall[k].setRandomColor(true);
      myBall[k].setLocation(myR.nextInt(i), myR.nextInt(j));
      myBall[k].setMoveRate(32, 32, 1, 1, true);
      myBall[k].setSize( 289, 167);
    Graphics g = myImage.getGraphics();
    while(true) {
      for (int k=0; k<myBall.length; k++){
        g.setColor(myBall[k].fgColor);
        g.fillOval(myBall[k].x, myBall[k].y, myBall[k].width, myBall[k].height);
      invalidate();
      paint(getGraphics());
      for (int k=0; k<myBall.length; k++){
        g.setColor(myBall[k].bgColor);
        g.fillOval(myBall[k].x, myBall[k].y, myBall[k].width, myBall[k].height);
        myBall[k].move();
  public void mouseClicked(MouseEvent e){
    exit();
  public void mouseDragged(MouseEvent e){
//    exit();
  public void mouseEntered(MouseEvent e){
//    exit();
  public void mouseExited(MouseEvent e){
//    exit();
  public void mouseMoved(MouseEvent e){
//    exit();
  public void mousePressed(MouseEvent e){
    exit();
  public void mouseReleased(MouseEvent e){
    exit();
  public void mouseWheelMoved(MouseWheelEvent e){
    exit();
  private void exit(){
    System.exit(0);
  public void paint(Graphics g){
    super.paint(g);
    myCanvas.getGraphics().drawImage(myImage, 0, 0, null);
  public static void main(String[] args) throws java.lang.Exception {
    new RandomColor();
    System.out.println("Done -- RandomColor");
}Ball Class:
package RandomColor;
import java.awt.Color;
import java.util.Random;
public class Ball {
  private int iLeft      = 0;
  private int iRight     = 0;
  private int iTop       = 0;
  private int iBottom    = 0;
  private int moveX      = 1;
  private int moveY      = 1;
  private int xScale     = moveX;
  private int yScale     = moveY;
  private int xDirection = 1;
  private int yDirection = 1;
  private boolean moveRandom = false;
  private boolean colorRandom = false;
  private Random myRand = null;
  public Color fgColor = Color.BLACK;
  public Color bgColor = Color.BLACK;
  public int x = 0;
  public int y = 0; 
  public int width  = 1;
  public int height = 1;
  public Ball(){
    myRand = new Random();
    setRandomColor(colorRandom);
  public void move(){
    x = 5 + x + (xScale*xDirection);
    y = 5 + y + (yScale*yDirection);
    if(x<=iLeft){
      x = 0;
      if(moveRandom) xScale = myRand.nextInt(moveX);else xScale = moveX;
      xDirection *= (-1);
      if(colorRandom) setRandomColor(colorRandom);
    if(x>=iRight-width){
      x = iRight-width;
      if(moveRandom) xScale = myRand.nextInt(moveX);else xScale = moveX;
      xDirection *= (-1);
      if(colorRandom) setRandomColor(colorRandom);
    if(y<=iTop){
      y = 0;
      if(moveRandom) yScale = myRand.nextInt(moveY);else xScale = moveY;
      yDirection *= (-1);
      if(colorRandom) setRandomColor(colorRandom);
    if(y>=iBottom-height){
      y = iBottom-height;
      if(moveRandom) yScale = myRand.nextInt(moveY);else xScale = moveY;
      yDirection *= (-1);
      if(colorRandom) setRandomColor(colorRandom);
  public void setColor(Color c){
    fgColor = c;
  public void setBackGroundColor(Color c){
    bgColor = c;
  public void setBounds(int Left, int Right, int Top, int Bottom){
    iLeft   = Left;
    iRight  = Right;
    iTop    = Top;
    iBottom = Bottom;
  public void setLocation(int x, int y){
    this.x = x;
    this.y = y;
  public void setMoveRate(int xMove, int yMove, int xDir, int yDir, boolean randMove){
    moveX       = xMove;
    moveY       = yMove;
    moveRandom  = randMove;
    xDirection  = xDir;
    yDirection  = yDir;
  public void setRandomColor(boolean random){
    colorRandom = random;
    switch (myRand.nextInt(3)+1){
      case 1:  fgColor = Color.BLUE;
               break;
      case 2:  fgColor = Color.GREEN;
               break;
      case 3:  fgColor = Color.RED;
               break;
      default: fgColor = Color.BLACK;
               break;
  public void setSize(int width, int height){
    this.width  = width;
    this.height = height;
}

Similar Messages

  • I recently bought an iphone 5s on kijii but my rogers nanno does not work, anyone know why?

    Why doenst my iphone work?

    Assuming the seller wasn't lying, contact Rogers to try a new Nano SIM.

  • HT201210 trying to download an instal ios 7 on my iphone 4s, after half an hour into the download it came up with a message saying failed and everytime i try again the download doesnt start. tried downloading from itunes aswel but not working. anyone know

    trying to download an instal ios 7 on my iphone 4s, after half an hour into the download it came up with a message saying failed and everytime i try again the download doesnt start. tried downloading from itunes aswel but not working. anyone know why?

    The servers are overloaded. There are a hundred million people all trying to download iOS 7 at one time. Try again later

  • I am having trouble sending pictures in text messages to anyone whether its a iphone user or not. Anyone know why? It just keeps saying not delievered

    I am having trouble sending pictures in text messages to anyone whether its a iphone user or not. Anyone know why? It just keeps saying not delievered

    Had the same problem a while ago. Call your mobile operator and they should guide you. It is some numbers that varies from each phone operator...

  • HT4906 Wanted to choose Photo Stream in iCloud but it is greyed out and not available - anyone know why?

    Hi there - wanted to choose photo stream in iCloud but it is greyed out - anyone know why?

    Wrong version of software?
    You really need to give more information  since we only know waht you tell us
    see http://www.apple.com/support/icloud/ for more informaiton
    LN

  • HT3702 Why can I not purchase lollipop?  I am able to purchase other boosters but not this anyone know why?

    Why can I not purchase lollipop?  I am able to purchase other boosters but not this one.  Any suggestions??

    What happens when you try to buy it, does the 'buy' button not work, do you get any error messages ... ?
    If you are getting a message to contact iTunes Support then you can do so via this link and ask them for help (we are fellow users, we won't know why the message is appearing) : 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 a different problem ... ?

  • SSRS 2008 Work order Report , when added item descriotion , somehow costgroup id is not working , donot know why, ( need help)

    SSRS 2008 Production orders created report, when I added item description some how cost group id is not working ,
    my costgroup id did not break into labor , only Mat Cost showed in the total,
    my query is as below,  did I link the wrong field,   I want to show Labor total also
    can some one suggest what I did wrong .
    any advise will be great
    SELECT        PRODTABLE.PRODID, PRODCALCTRANS.COSTGROUPID, PRODTABLE.QTYCALC, PRODTABLE.PRODSTATUS, PRODCALCTRANS.COSTAMOUNT,
                             PRODCALCTRANS.COSTMARKUP, PRODCALCTRANS.REALCOSTAMOUNT, PRODCALCTRANS.CALCTYPE, PRODTABLE.DATAAREAID, PRODCALCTRANS.KEY3,
                             PRODCALCTRANS.CONSUMPVARIABLE, PRODCALCTRANS.REALCONSUMP, PRODTABLE.ITEMID, PRODTABLE.SCHEDDATE, PRODTABLE.FINISHEDDATE,
                             PRODCALCTRANS.KEY1, PRODCALCTRANS.TRANSDATE, PRODCALCTRANS.QTY, PRODCALCTRANS.KEY2, PRODCALCTRANS.COLLECTREFLEVEL,
                             PRODCALCTRANS.LINENUM, INVENTTABLE.ITEMNAME, INVENTTABLE.ITEMID AS Expr1, PRODTABLE.INVENTTRANSID
    FROM            PRODTABLE INNER JOIN
                             PRODCALCTRANS ON PRODTABLE.PRODID = PRODCALCTRANS.PRODID AND PRODTABLE.DATAAREAID = PRODCALCTRANS.DATAAREAID INNER
    JOIN
                             INVENTTABLE ON PRODCALCTRANS.DATAAREAID = INVENTTABLE.DATAAREAID AND PRODCALCTRANS.KEY1 = INVENTTABLE.ITEMID
    WHERE        (PRODTABLE.PRODSTATUS = 7) AND (PRODTABLE.DATAAREAID = N'AR1') AND (PRODTABLE.ITEMID = @itemid) AND
                             (PRODTABLE.FINISHEDDATE >= @Paramfromdate) AND (PRODTABLE.FINISHEDDATE <= @Paramtodate) AND (PRODCALCTRANS.COLLECTREFLEVEL
    = 1) AND
                             (PRODCALCTRANS.CALCTYPE >= 0)

    Hi Bitia,
    As per my understanding, after you add Item field to the report, it does not calculate total of matl group, right? If that is the case, please refer to the following steps to troubleshoot the problem:
    Modify the dataset used to retrieve data, delete the fields will not be used in the report.
    Run the query in SQL Server Management Studio (SSMS) to make sure that there is data for matl cost group.
    Make sure that row group and totals are correctly added.
    In addition, do you want to add Finished date to page header? If that is the case, we can use ReportItem to achieve the goal. Please refer to the following steps:
    In design surface, right-click the report and click Insert, then click Page Header.
    Drag Text Box from Toolbox to page header.
    Right-click inside of Text Box, then click Expression.
    In the expression text box, type the code like below:
    =ReportItems!FinishedDate.Value
    If the problem remain unresolved, please provide the screenshot of the report in design view, the following screenshot is for your reference:
    Reference:
    ReportItems Collection References
    Adding Grouping and Totals
    Thanks,
    Wendy Fu

  • Im trying to listen to a book and it keeps telling me I need to enter my audible account username and password.  I used my apple id and it is not working anyone know what to do?

    Im trying to listen to a book we downloaded from amazon.  When we click on it it says we need to enter out audible username and password.  I used my apple id username and password and it says it is not correct.  I reset this and used it again and it still does not work.  Any ideas?

    Launch iTunes. From the menu bar click Store / View My Account then click Edit Payment Information.
    Make sure the Security Code for you credit card is available and the expiration date is correct, then click Done.

  • My home button does not work, anyone know how to fix the problem?

    My home screen bottom does not work the only way I can get back to home screen is to bookmark and save to home page then the ho
    E menu appears total pain kinda mad cause phone us new???

    i have had that one with my ipad2
    still do not know if it is the button or if it is a software issue.
    you might try this one.
    push and hold the top power  button until the switch off slide appears.
    after it appears let go of the power button, push and hold the home button until the slider disappears.
    ofcourse this is tricky because the button needs to react
    if it does not work the first time try again and the hold the homebutton and move your finger around the sides of the button(eg if the contact is bad this might force it to make contact somewhere)
    i will wait for ios5 and see if it will fix my ipad2
    i kow other people who did send back their devices but i only want to do that if i am 100% sure it is a hw issue

  • After sefvlet include rest of page does not include anyone know why

        <h1>JSP Page</h1>
    this text shows
        <jsp:include page="/IncludeHandler" flush="true"/>   //myservlet
    this text does not show
        </body>
    </html>

    Not sure what was happening
    Inittially did not work under
    public class HelloWorld extends HttpServlet {
      public void process(HttpServletRequest request,
                        HttpServletResponse response)
          throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        out.println("Hello World");
    }but it work underpublic class HelloWorld extends HttpServlet {
      public void doGet(HttpServletRequest request,
                        HttpServletResponse response)
          throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        out.println("Hello World");
    }Thanks to you all for your help

  • Help, Substring not working, dont know why...

    I need to load some xml file and extract some data from it.
    I have this code.
    I thing that this have to work but havent...it prints input error...
    Any suggestion?
    file is opened by this code it works
    if (e.getSource() == openButton) {
    int returnVal = fc.showOpenDialog(FileChooserDemo.this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
    file = fc.getSelectedFile();
    /// this doesnt work
    try {
    String f;
    FileInputStream fstream = new FileInputStream(file);
    BufferedReader in = new BufferedReader(new inputStreamReader(fstream));
    while ((f = in.readLine()) != null)
    System.out.println(in.readLine());
    String document = in.readLine().toString();
    String startTag = "<Text>";
    String endTag = "</Text>";
    int start = document.indexOf(startTag) + startTag.length();
    int end = document.indexOf(endTag) + 1;
    String result = document.substring(start,end);
    System.err.println(result);
    in.close();

    also what are you trying to accomplish with:
    String document = in.readLine().toString();
    whats with ".toString()"? it obviously already returns a String
    seeing as how youve already assigned the previous readLine() to
    a String variable named "f".
    Are you trying to create a copy? If so you want "new String(String)"

  • Help! The Apps Do not work, anyone know what to do?

    Ok, i download the Myspace and the AIM App. As soon as I click on one of them it quickly takes me right back to the menu. Anyone else having this problem/ know what to do?

    Just try restarting. I went through the same panic attack when some of mine didn't work, but for me, if I open 15 apps then all others opened crash (the number of apps seems to vary for different people), and after I restarted the one I wanted to try worked just fine. I'd have to assume this'll get fixed in the future however.

  • Slight skip before many songs - if not all - anyone know why?

    When I am using Pod and press back - say to replay or restart a song - I often get a quick burst - maybe 1 second's worth, before the song starts. Has anyone else had this?

    I did, and still do sometimes. But with me it only happens with songs whose start time I changed. When you sync the iPod, you can select a song, then "get info" for it. You then have the option to select another start point or end point for your song. I do this when I want to skip a long song intro. I guess it "freaks" the iPod out a bit when you then press play. Normally, this kind of skipping is due to the hard drive's head searching for the info, say, from a song located on one part of the HD's platter to a different song located elsewhere on the platter (ie not adjacent). I don't think it's a major problem, but if you're worried about it, reformat your iPod and resync it.
    A.

  • Mirror Door not working, dont know why??

    Hi, i turned my mac on and got the normal apple chime, but it did not boot up it just went to a blank blue screen so i waited for a while and unpluged it from the mains power, i waited then pluged it back in turned it on and nothing it wouldnt even switch on... ?? can anyone give me any ideas of what to do? Thanks.

    Hello! For starters try resetting the PMU since it was unhooked from the wall. press the button once with all external cables (a/c, monitor, usb, firewire etc.) unhooked and then try restarting. If you still get the blue screen try starting from the install disc for Tiger and run the disk repair function. Tom
    PMU location
    [IMG]http://img470.imageshack.us/img470/1623/mddlogicbd4ga.jpg[/IMG]

  • Help-iPhone 5 is making the sound/vibrations as if I was receiving/sending txt-but I am not.  Anyone know why?

    All of a sudden my iPhone 5 has been making my text sound and vibration when I am not even near my phone. I go and look at my ohone and it is in the locked screen still with no new text.  It also makes the sound (Swoosh) like it is sending a text when the phone hasn't been touched in a while.  I havent dropped it or anything for it to be doing this.  Could it have been hacked into?

    Never mind. I've did a hard reboot no matter how hard I pressed the power button. Thank goodness!!!

Maybe you are looking for

  • Issue with Adobe and Fonts

    I type my papers for university out in Pages, and then export them to PDF using the free Adobe. It ALWAYS changes my font from Times New Roman to Helvetica. Every time. This is really bad because graduate applications need the font to be TNR. I despe

  • Included JSPs gives comilation error, even in the JBuilder plugin

    Dears, I'm making a web application, it contains a header, and footer JSPs. These two JSPs are included in every JSP in the site, and I use the <%@ include The problem in this is that I define variables in every parent JSP including these two JSPs, b

  • Complete hard drive failure.  Advice?

    I was having hard drive issues last month that I thought were resolved, but now I'm pretty sure my internal hard drive in my iBook is totally dead. My internal hard drive started making really bad grinding noises during start up, so I booted my iBook

  • Synching my iPad with iTunes : 399 parts can not be synchronized?

    When I sync my iPad (or my iPhone) with iTunes I get a message on the start screen of my iPad: "iTunes-synchr. 339 parts cannot be synchronised. See iTunes for more information" I looked everywhere in iTunes, but I cannot find what parts and why they

  • Crashing issue with dual cards not in SLI mode

    Running CS6 on a HPZ820 with 64GB RAM and TWO Nividia Quadro4000s... having some crashing issues - DisplaySurface.dll error. I am NOT running cards in SLI mode. Any ideas? I have some NewBlueFX plug-ins that I disabled the GPU - that helped. But now