Results 1 to 4 of 4
  1. #1
    Josep_16's Avatar
    Josep_16 is offline Member
    Join Date
    Mar 2011
    Posts
    40
    Rep Power
    0

    Thumbs down Cannot initialize the applet

    Hello again. I was trying to create an applet that shows the fall down of a ball simply vertically, also using the double-buffering. In my opinion, the code is ok and there are no errors:

    Java Code:
    /**
     * Applet CaidaBola
     *
     * <APPLET CODE="CaidaBola.class" WIDTH="500" HEIGHT="200"></APPLET>
     */
    
    import java.applet.Applet;
    import java.awt.*;
    
    public class CaidaBola extends Applet implements Runnable {
    
      int altura;
      int posicionY, posicionX;
      int ancho, alto; // para el buffer
      Thread hilo = null;
      Image buffer;
      Graphics pantallaVirtual;
    
      public void init() {
    	altura = getBounds().height;
    	posicionY = altura - (altura/100*85);
    	posicionX = 20;
    	buffer = createImage(ancho, alto);
    	pantallaVirtual = buffer.getGraphics();
      }
    
      public void start() {
    	if (hilo == null) {
    		hilo = new Thread(this);
    		hilo.start();
    	}
      }
    
      public void stop() {
    	hilo = null;
      }
    
      public void paint(Graphics g) {
    	g.drawOval(posicionX, posicionY, 20, 30);
      }
    
      public void update(Graphics g){
    	Color colorTemporal = pantallaVirtual.getColor();
    	pantallaVirtual.setColor(Color.white);
    	pantallaVirtual.fillRect(0,0,ancho,alto);
    	pantallaVirtual.setColor(colorTemporal);
    	paint(pantallaVirtual);
    	g.drawImage(buffer,0,0,this);
      }
    
      public void run() {
    	while (hilo!=null && hilo.isAlive()) {
    		posicionY -=1;
    		repaint();
    		try {
    			hilo.sleep(10);
    		}
    		catch (InterruptedException e) {}
    	}
      }
    }

    When I compile it there is no ptoblem , but when I use appletviewer, the appletviewer gets opened and displays the next sentence below (traduced from spanish): "Initiate: Subprogram not initialized."
    Also, the System Symbol of Windows shows me the following:



    As I said, I think everything is OK with the code... What's really wrong?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,410
    Rep Power
    25

    Default

    What code is at line 23?
    If it is
    Java Code:
    buffer = createImage(ancho, alto);
    do the arguments have correct values.
    Add a println to print them out so that you can see what they are.

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

  3. #3
    Josep_16's Avatar
    Josep_16 is offline Member
    Join Date
    Mar 2011
    Posts
    40
    Rep Power
    0

    Default

    Oh thanks, how could I miss the values of that arguments :S
    Java Code:
    alto = getBounds().height;
    	altura = getBounds().height;
    It worked now, although the ball goes up not down; gotta take another look at it.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default

    the ball goes up not down
    The origin [0, 0] is at the top left corner of the screen. x-coordinates increase from left to right, y-coordinates from top to bottom.

    db

Similar Threads

  1. How do initialize these Strings?
    By eLancaster in forum New To Java
    Replies: 1
    Last Post: 03-02-2011, 05:09 PM
  2. Trying to initialize variables
    By random0munky in forum New To Java
    Replies: 2
    Last Post: 10-14-2009, 10:30 PM
  3. ObjectInputStream does not initialize
    By Singing Boyo in forum New To Java
    Replies: 1
    Last Post: 06-03-2009, 08:11 AM
  4. How to initialize an Array
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:47 PM
  5. I do not know how to initialize the two variables
    By Daniel in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 04:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •