Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  NullPointer Error - HUH?  (Read 3043 times)
0 Members and 1 Guest are viewing this topic.
Space Xscape
Guest
« Posted 2007-08-27 20:14:54 »

When i test run my game i get a applet noninit error. I opened my java console and found the following error:

Quote
Java Plug-in 1.6.0_02
Using JRE version 1.6.0_02 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\Michael Becerra

----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
p:   reload proxy configuration
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------

java.lang.NullPointerException
   at java.applet.Applet.getCodeBase(Unknown Source)
   at GameObject.loadImage(GameObject.java:37)
   at Ball.<init>(Ball.java:10)
   at Hyper_Rush_Pong.init(Hyper_Rush_Pong.java:19)
   at sun.applet.AppletPanel.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
   at java.applet.Applet.getCodeBase(Unknown Source)
   at GameObject.loadImage(GameObject.java:37)
   at Ball.<init>(Ball.java:10)
   at Hyper_Rush_Pong.init(Hyper_Rush_Pong.java:19)
   at sun.applet.AppletPanel.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)

If i have to make an intelligent guess it would have to do with my LoadImage being called by the Ball class at the applets Init method, but what is a NullPointer? Any ideas?

Here is the code:

GameObject.java
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
import java.applet.*;
import java.awt.*;
import java.net.*;

public abstract class GameObject extends Applet {
   
   private int x;
    private int y;
    private int vx;
    private int vy;
   private Image image;

   //member methods
  public void setX(int new_x) {x = new_x;}
   public void setY(int new_y) {y = new_y;}
   public void setVX(int new_vx) {vx = new_vx;}
   public void setVY(int new_vy) {vy = new_vy;}

   //ancestor methods
  public int getX() {return x;}
   public int getY() {return y;}
   public int getVX() {return vx;}
   public int getVY() {return vy;}
   public Image getImage() {return image;}
   public int getImageWidth(){return image.getWidth(this);}
   public int getImageHeight(){return image.getHeight(this);}
   
   //boundry checking code
  public boolean hitTopBountry(){if(getY() < 0) {return true;}else{return false;}}
   public boolean hitLeftBountry(){if(getX() < 0){return true;}else{return false;}}
   public boolean hitBottomBountry(){if(getY() > this.getHeight()){return true;}else{return false;}}
   public boolean hitRightBountry(){if(getX() > this.getWidth()){return true;}else{return false;}}
   
   
   public void loadImage(String filename) {
   // load image file
  image = getImage (getCodeBase(), filename);
   }
   
    public abstract void Draw(Graphics g);

    public abstract void Update();
   
}


Ball.java
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
import java.awt.*;

class Ball extends GameObject{

public Ball(int initial_x, int initial_y, int initial_vx, int initial_vy, String filename) {
   setX(initial_x);
   setY(initial_y);
   setVX(initial_vx);
   setVY(initial_vy);
   loadImage(filename);
}

public void Update() {
Move();
Check_Bounds();
}

public void Check_Bounds() {
   //ball has collided with the left boundry
  if(getX() <= 0) {
   setVX(-getVX());
   }
   
   //ball has collided with the right boundry
  if(getX() >= this.getWidth()) {
   setVX(-getVX());
   }

   //ball has collided with the top boundry
  if(getY() <= 0) {
   setVY(-getVY());
   }
   
   //ball has collided with the bottom boundry
  if(getY() >= this.getHeight()) {
   setVY(-getVY());
   }  
}

public void Move() {
setX(getX() + getVX());
setY(getY() + getVY());
}

public void Draw(Graphics g) {
   g.drawImage(getImage(), getX(), getY(), this);
}

}


Hyper_Rush_Pong.java
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
// import necessary packages
import java.applet.*;
import java.awt.*;

// Inherit the applet class from the class Applet
public class Hyper_Rush_Pong extends Applet implements Runnable
{
   // declare two instance variables for double buffering at the head of the program
  private Image dbImage;
   private Graphics dbg;

   //declare our game objects
  Ball ball;

      // Now you should implement the following methods

      // init - method is called the first time you enter the HTML site with the applet
     public void init() {
         Ball ball = new Ball(250, 200, 1, 1, "Data/Gfx/Ball.png");
         }

      // start - method is called every time you enter the HTML - site with the applet
     public void start() {
         // define a new thread
    Thread th = new Thread (this);
     // start this thread
    th.start ();
         }

      // stop - method is called if you leave the site with the applet
     public void stop() {
         }

      // destroy method is called if you leave the page finally (e. g. closing browser)
     public void destroy() {
         }

    // run method is called everytime to move the objects onscreen
   // define a new thread
 
     public void run() {
               // lower ThreadPriority
     Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

      // run a long while (true) this means in our case "always"
     while (true)
      {
            // repaint the applet
           repaint();

            try
            {
                  // Stop thread for 20 milliseconds
                 Thread.sleep (20);
            }
            catch (InterruptedException ex)
            {
                  // do nothing
           }

            // set ThreadPriority to maximum value
           Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
            }

      }
   
   
/** Update - Method, implements double buffering */
public void update (Graphics g) {

      // initialize buffer
     if (dbImage == null)
      {
            dbImage = createImage (this.getSize().width, this.getSize().height);
            dbg = dbImage.getGraphics ();
      }

      // clear screen in background
     dbg.setColor (getBackground ());
      dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);

      // draw elements in background
     dbg.setColor (getForeground());
      paint (dbg);

      // draw image on the screen
     g.drawImage (dbImage, 0, 0, this);
      }
   
   
      /** paint - method allows you to paint into your applet. This method is called e.g. if you move your browser window or if you call repaint() */
      public void paint (Graphics g) {
         ball.Draw(g);
         }

}
Offline Mr_Light

Senior Member




shiny.


« Reply #1 - Posted 2007-08-27 22:33:19 »

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4070158

tbh I think someone forgot to code defensively.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Space Xscape
Guest
« Reply #2 - Posted 2007-08-28 00:28:05 »

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4070158

tbh I think someone forgot to code defensively.
What do you mean by "code defensively"?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline brackeen

Junior Member





« Reply #3 - Posted 2007-08-28 00:34:01 »

1  
public abstract class GameObject extends Applet {


The GameObject class should not be a subclass of Applet.
Space Xscape
Guest
« Reply #4 - Posted 2007-08-28 01:27:55 »

1  
public abstract class GameObject extends Applet {


The GameObject class should not be a subclass of Applet.

It has to or else i will get errors:

Quote
--------------------Configuration: Hyper Rush Pong - JDK version 1.6.0_02 <Default> - <Default>--------------------
C:\Projects\Java\Hyper Rush Pong\source\GameObject.java:25: getWidth(java.awt.image.ImageObserver) in java.awt.Image cannot be applied to (GameObject)
    public int getImageWidth(){return image.getWidth(this);}
                                           ^
C:\Projects\Java\Hyper Rush Pong\source\GameObject.java:26: getHeight(java.awt.image.ImageObserver) in java.awt.Image cannot be applied to (GameObject)
    public int getImageHeight(){return image.getHeight(this);}
                                            ^
C:\Projects\Java\Hyper Rush Pong\source\GameObject.java:31: cannot find symbol
symbol  : method getHeight()
location: class GameObject
    public boolean hitBottomBountry(){if(getY() > this.getHeight()){return true;}else{return false;}}
                                                      ^
C:\Projects\Java\Hyper Rush Pong\source\GameObject.java:32: cannot find symbol
symbol  : method getWidth()
location: class GameObject
    public boolean hitRightBountry(){if(getX() > this.getWidth()){return true;}else{return false;}}
                                                     ^
C:\Projects\Java\Hyper Rush Pong\source\GameObject.java:37: cannot find symbol
symbol  : method getCodeBase()
location: class GameObject
    image = getImage (getCodeBase(), filename);
                      ^
5 errors

Process completed.

Plus, i don't think thats the problem.
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #5 - Posted 2007-08-28 07:57:22 »

Quote
It has to or else i will get errors:
No it doesn't have to. Just think about it for a second: A GameObject and a Ball are not Applets, so you should not misuse the Applet class just because it has some methods you could use. There are other, better ways to design this.

Quote
Plus, i don't think thats the problem.
It might very well be the problem. What do you think the getCodeBase method should return if you're not using the Applet class how it's supposed to be used?

Offline broumbroum

Junior Member





« Reply #6 - Posted 2007-08-28 16:48:25 »

getCodeBase may return the .jar package that contains the class, it should be used only for classpath operations. you better use the CWD "." instead of that applet meth'. NullPointerException means that your resource isn't found by the URL resource classloader.

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Space Xscape
Guest
« Reply #7 - Posted 2007-08-29 01:06:33 »

getCodeBase may return the .jar package that contains the class, it should be used only for classpath operations. you better use the CWD "." instead of that applet meth'. NullPointerException means that your resource isn't found by the URL resource classloader.

The files excist and the path is correct, maybe because i'm running it locally outside a jar?

Quote
There are other, better ways to design this.

And how would i rewrite the applet based code?
Offline broumbroum

Junior Member





« Reply #8 - Posted 2007-08-29 03:19:01 »

The files excist and the path is correct, maybe because i'm running it locally outside a jar?

And how would i rewrite the applet based code?
What do you mean I quote "locally outside a .jar"?

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #9 - Posted 2007-08-29 10:54:19 »

Quote
And how would i rewrite the applet based code?

Just factor out your dependencies from GameObject to the Applet class to start with.

For example, if you want to get the dimensions of the applet in a GameObject, you could use a reference to the actual applet (the instance of your Hyper_Rush_Pong class).

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Space Xscape
Guest
« Reply #10 - Posted 2007-08-29 15:36:46 »

How do i pass it a reference to my applet?

1  
2  
3  
public Applet getWidth(Applet app){

}


And what about the image code? the image is something thats part of gameobject exclusively, how do i use that?
Offline cylab

JGO Ninja


Medals: 43



« Reply #11 - Posted 2007-08-29 16:56:10 »

How do i pass it a reference to my applet?

He meant the other way around:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
class GameObject
{
  // A reference to the applet
 private Applet applet;

  // either pass the Applet as construction argument
 public GameObject(Applet applet)
  {
    this.applet=applet;
  }
 
  //or provide a setter and call it after construction of the GameObject
 public void setApplet(Applet applet)
  {
    this.applet=applet;
  }
}

 
And what about the image code? the image is something thats part of gameobject exclusively, how do i use that?

Just load your images or other resources from the classpath (e.g. from inside your jar). Google for it.

Mathias - I Know What [you] Did Last Summer!
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #12 - Posted 2007-08-29 17:12:40 »

for example:
1  
2  
                InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
                BufferedImage image = ImageIO.read(is);

Offline broumbroum

Junior Member





« Reply #13 - Posted 2007-08-29 17:49:13 »

1  
2  
3  
4  
5  
   public void loadImage(String filename) {
   // load image file
  image = getImage (getCodeBase(), filename);
   }
   

As a matter of fact the getImage should use the resource classLoader to get the URL. If you had a look to the doc about classLoader.getResource you'd understand that the path is always inclusive the classpath, and precisely for common resource like image whether beginning with slashes or not the base would take place at the root of the .jar if your applet is packaged.

Such an issue must be resolved by instancing a full File instance and a FileInputStream, which can be buffered, and to load the image with the root ImageReader, known as ImageIO.read(filename); add the codeBase to the filename and you'll surely by out of the issue. Cheesy BTW the nio package impl. a RandomAccesFile with channel that can be FileLock'ed to replace the usual File-FileInputStream. That can also avoid wrong file data. Wink

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Offline cylab

JGO Ninja


Medals: 43



« Reply #14 - Posted 2007-08-29 18:11:21 »

Such an issue must be resolved by instancing a full File instance and a FileInputStream, which can be buffered, and to load the image with the root ImageReader, known as ImageIO.read(filename); add the codeBase to the filename and you'll surely by out of the issue. Cheesy

AFAIK the codeBase is the baseUrl from where the applet is loaded, so you can never instanciate a file with it. I believe he wants to load the image directly from the "webserver" (even if not a webserver using the AppletViewer) with a path relative to the applet's jar location, so using a FileInputStream is not an option.

Mathias - I Know What [you] Did Last Summer!
Space Xscape
Guest
« Reply #15 - Posted 2007-08-29 22:09:40 »

I updated GameObject.java and i'm getting new errors:

Quote
--------------------Configuration: Hyper Rush Pong - JDK version 1.6.0_02 <Default> - <Default>--------------------
C:\Projects\Java\Hyper Rush Pong\source\Ball.java:5: cannot find symbol
symbol  : constructor GameObject()
location: class GameObject
public Ball(int initial_x, int initial_y, int initial_vx, int initial_vy, String filename) {
                                                                                           ^
C:\Projects\Java\Hyper Rush Pong\source\Ball.java:25: cannot find symbol
symbol  : method getWidth()
location: class Ball
    if(getX() >= this.getWidth()) {
                     ^
C:\Projects\Java\Hyper Rush Pong\source\Ball.java:35: cannot find symbol
symbol  : method getHeight()
location: class Ball
    if(getY() >= this.getHeight()) {
                     ^
C:\Projects\Java\Hyper Rush Pong\source\Ball.java:46: cannot find symbol
symbol  : method drawImage(java.awt.image.BufferedImage,int,int,Ball)
location: class java.awt.Graphics
    g.drawImage(getImage(), getX(), getY(), this);
     ^
4 errors

Process completed.

Updated Code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
import java.applet.*;
import java.awt.*;
import java.net.*;

public abstract class GameObject {
   // A reference to the applet
    private Applet applet;
     
   private int x;
    private int y;
    private int vx;
    private int vy;
   private BufferedImage image;

  // Pass the Applet as construction argument
 public GameObject(Applet applet)
  {
    this.applet = applet;
  }

   //member methods
  public void setX(int new_x) {x = new_x;}
   public void setY(int new_y) {y = new_y;}
   public void setVX(int new_vx) {vx = new_vx;}
   public void setVY(int new_vy) {vy = new_vy;}

   //ancestor methods
  public int getX() {return x;}
   public int getY() {return y;}
   public int getVX() {return vx;}
   public int getVY() {return vy;}
   public Image getImage() {return image;}
   public int getImageWidth(){return image.getWidth(this);}
   public int getImageHeight(){return image.getHeight(this);}
   
   //boundry checking code
  public boolean hitTopBountry(){if(getY() < 0) {return true;}else{return false;}}
   public boolean hitLeftBountry(){if(getX() < 0){return true;}else{return false;}}
   public boolean hitBottomBountry(){if(getY() > this.getHeight()){return true;}else{return false;}}
   public boolean hitRightBountry(){if(getX() > this.getWidth()){return true;}else{return false;}}
   
   
   public void loadImage(String filename) {
   // load image file
  InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
    image = ImageIO.read(is);
   }
   
    public abstract void Draw(Graphics g);

    public abstract void Update();
   
}


Ball.java
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
import java.awt.*;

class Ball extends GameObject{

public Ball(int initial_x, int initial_y, int initial_vx, int initial_vy, String filename) {
   setX(initial_x);
   setY(initial_y);
   setVX(initial_vx);
   setVY(initial_vy);
   loadImage(filename);
}

public void Update() {
Move();
Check_Bounds();
}

public void Check_Bounds() {
   //ball has collided with the left boundry
  if(getX() <= 0) {
   setVX(-getVX());
   }
   
   //ball has collided with the right boundry
  if(getX() >= this.getWidth()) {
   setVX(-getVX());
   }

   //ball has collided with the top boundry
  if(getY() <= 0) {
   setVY(-getVY());
   }
   
   //ball has collided with the bottom boundry
  if(getY() >= this.getHeight()) {
   setVY(-getVY());
   }  
}

public void Move() {
setX(getX() + getVX());
setY(getY() + getVY());
}

public void Draw(Graphics g) {
   g.drawImage(getImage(), getX(), getY(), this);
}

}
Offline broumbroum

Junior Member





« Reply #16 - Posted 2007-08-29 22:57:33 »

would you try another IDE plz? I can't answer...

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Space Xscape
Guest
« Reply #17 - Posted 2007-08-29 23:06:33 »

would you try another IDE plz? I can't answer...

I can't i've paid $50 for this ide and netbeans was slow as heck for me. I can't figure how to install Eclipse either.  Cry
Offline cylab

JGO Ninja


Medals: 43



« Reply #18 - Posted 2007-08-29 23:09:33 »

Don't be offended, but please try to understand what you do and not just copy some code into yours and hope it will magically work. Shocked Otherwise our answers won't help you...

The applet reference was to eliminate the need to extend from Applet and since you called this.getWidth(), which was inherited from Applet(!), it surely does not work anymore. You now have to call applet.getWidth() to get the width of the Applet. And since you extend Ball from GameObject, you either need to make applet protected (to allow access from a subclass) or provide a protected Applet getApplet(){ return applet; } you can call to get the Applet's reference.

Also you if you extend Ball from GameObject and GameObject does only have a constructor expecting an Applet argument, you have to call this constructor from Ball and have to pass the Applet. So your Ball class also needs a constructor getting an Applet:

1  
2  
3  
4  
5  
6  
7  
8  
public Ball(Applet applet, int initial_x, int initial_y, int initial_vx, int initial_vy, String filename) {
   super(applet); // call the superclass' constructor passing the given applet
  setX(initial_x);
   setY(initial_y);
   setVX(initial_vx);
   setVY(initial_vy);
   loadImage(filename);
}


Having said all that, it is probably not the best idea passing Applet references around, since you will depend your game from being an applet forever. Think of what Informations you need, extract them from applet and set them, where you need them.

The last error ist due to drawImage() does not expect a Ball as 4th argument, but an ImageObserver. Applet implements an ImageObserver, so it worked before, but now Ball alone is no ImageObserver. Either implement the ImageObserver interface on Ball or just pass null

Edit: Applet/GameObject typo

Mathias - I Know What [you] Did Last Summer!
Offline broumbroum

Junior Member





« Reply #19 - Posted 2007-08-29 23:15:44 »

what t f''' is it doing with "cannot find symbol"? don't you have access to code completion for 50 bucks? Smiley I don't wanna be disturbing you with that, but it can be the IDE to reconfigure..

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Space Xscape
Guest
« Reply #20 - Posted 2007-08-30 00:18:16 »

Quote
Don't be offended, but please try to understand what you do and not just copy some code into yours and hope it will magically work. Shocked Otherwise our answers won't help you...
I'm not offended, i went to cittone institue, paramus, nj and took a programming course which includes Java as one of their subjects. However they just talked about the basic stuff you would normally learn from reading any java book, they didn't do anything this advance like passing applet references like i'm doing here. 


Quote
what t f''' is it doing with "cannot find symbol"? don't you have access to code completion for 50 bucks? Smiley I don't wanna be disturbing you with that, but it can be the IDE to reconfigure..

Its not included in my ide? dunno. Itried Eclipse for the very first time and it used half of my memory and ran as slow as h e double hockey sticks.

P.S. They used JCreator as the ide they reccommend you use for your java projects and that what they use to teach you the language. To make matters worse they use the LITE version, which has no code completion at all, its basicly notepad with a button to compile your code  Sad

P.S.S They charged me $15,000 for the entire 7 month course but this is going off-topic
Offline cylab

JGO Ninja


Medals: 43



« Reply #21 - Posted 2007-08-30 02:23:42 »

P.S.S They charged me $15,000 for the entire 7 month course but this is going off-topic
Oh... You got screwed Wink

Passing around objects (like the Applet) is one of the most basic task to do in a programming language, actually. You might better have bought a book Tongue

Mathias - I Know What [you] Did Last Summer!
Offline kaosnkorruption

Senior Newbie





« Reply #22 - Posted 2007-08-30 04:05:12 »

You need to change the constructor for Ball to accept a reference to the Applet, and invoke super(applet).

Use Eclipse.  There is no installation involved with Eclipse.  Just extract the folder, and run eclipse.exe.  Create a workspace, create a project, copy your classes into the folder structure Eclipse has created, refresh the project in Eclipse's Package Explorer.  Eclipse is not hard to use at all.
Offline keldon85

Senior Member


Medals: 1



« Reply #23 - Posted 2007-08-30 06:53:04 »

P.S.S They charged me $15,000 for the entire 7 month course but this is going off-topic
Could I interest you in some organic jelly beans, only $599 each in packs of 10  Cool Expensive for a 7 month course, what's it in? One of those certified web developer courses?

But like people are saying, you would do better for yourself to remove the dependencies from Applet in your game. And as for your IDE, whether you spent $50 or $5,000 on your package, if Eclipse can help you then use it. Just see it as a package you also spent $2,000 on Cheesy

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #24 - Posted 2007-08-30 08:52:40 »

Quote
But like people are saying, you would do better for yourself to remove the dependencies from Applet in your game.

Ultimately, of course that would be best.
However, let's just take it one step at a time. He's still learning and already has difficulties with the concept of passing references. I suppose it's better to at least get something working first, even if it is exclusively an applet (which is not so bad if you don't plan to have it working as an application anyway).

Offline keldon85

Senior Member


Medals: 1



« Reply #25 - Posted 2007-08-30 09:06:52 »

Ultimately, of course that would be best.
However, let's just take it one step at a time. He's still learning and already has difficulties with the concept of passing references. I suppose it's better to at least get something working first, even if it is exclusively an applet (which is not so bad if you don't plan to have it working as an application anyway).
True, I mean some people instinctively break down large systems while others (like myself) instinctively think bottom up. I'm guessing he thinks bottom up, which sucks for Java but is great for learning BASIC and assembler in DOS. I just wish I didn't have so many commitments otherwise I would devote some time to developing tutorial/courses - the burden of writing a dissertation on learning and communication Sad

Well my reminder of the minute is, "a mistake is better than a missed take". Although there is good reason not to learn bad practices as it takes longer to unlearn than it does to learn, it is sometimes much easier to grasp a particular concept when everything else is wrong. Plus you learn a lot from mistakes, such as why they are mistakes, and what you can do to avoid them. At least you've made a mistake.

Looking at code of yesteryear, I can see so many mistakes its unbelievable. Most of them were about maintainability, cohesion (like being your own 'Mr independent' class who doesn't even need to know Applet) was one of them.

Space Xscape
Guest
« Reply #26 - Posted 2007-08-30 16:25:18 »

@keldon85,erikd: If i remove the Applet dependencies how will i load images and sounds, loading through the applet class are the only way that was tought to me.

@keldon85: The java part of the course was only 3 weeks.  Shocked It was Html, Java, CSS, XML, Javascript, VB 6, and asp.

@All: i'm was planning on creating an applet and then use applet-desc and web-start to make it an application. If anyone knows how i can do both without rewritting the whole thing from scratch it would be appreciated.

Thanks All For The Support You Have Given Me  Cheesy
Offline keldon85

Senior Member


Medals: 1



« Reply #27 - Posted 2007-08-30 17:59:27 »

Well I basically had my output class extend Panel, and then created two classes to each load either a Frame or an Applet to place the panel inside. As for loading, you can have both an applet and application reference resources using getResource(""). Store your resources inside of Jar files, and then link to them inside your manifest file's list of class-files.

My project has seamless integration because of this; so my jar files work as a stand alone application, an applet and a web start application - all in one build.

As for your course, I sort of guessed it would have a fair amount of web work because we have the same sort of thing over here. Once you're a certified developer you have the confidence to apply for jobs that are offering $40-$60k, sticking around here at Java Gaming will give you the added boost of having applet development experience.

Space Xscape
Guest
« Reply #28 - Posted 2007-08-31 00:40:24 »

Quote
Well I basically had my output class extend Panel, and then created two classes to each load either a Frame or an Applet to place the panel inside. As for loading, you can have both an applet and application reference resources using getResource(""). Store your resources inside of Jar files, and then link to them inside your manifest file's list of class-files.

Could you please provide some example code? I don't seem to understand what you mean. I normally place both my frame and panel in the same class like my school tought me.
Offline keldon85

Senior Member


Medals: 1



« Reply #29 - Posted 2007-08-31 07:22:42 »

Could you please provide some example code? I don't seem to understand what you mean. I normally place both my frame and panel in the same class like my school tought me.

The school course is there to teach you the Java language and introduce you to the core classes so that you can get code running in an applet or application. You are unlikely to find any short course teaching you more advanced coding practises such as software engineering and the likes, unless they plan on charging you through the roof. Even Universities struggle to create a course that works for everyone, and their courses span a number of years!!!

Code example:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
class ScreenPanel extends Panel {
   public void paint ( Graphics g ) {
      ...
   }
}

class LaunchFrame {
   public static void main ( String argv[] ) {
      Frame frame = new Frame ("doop de doo");
      ScreenPanel screenPanel = new ScreenPanel();

      ...

      frame.add(screenPanel);

      ...

      new Game().start();
   }
}

class LaunchApplet extends JApplet {
   public void init (){
      getContentPane().add(new ScreenPanel());
      setSize ( ... );
   }

   public void start (){
      game = new Game();
      game.start();
   }
}

Pages: [1] 2
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (15 views)
2014-08-28 18:26:30

CopyableCougar4 (25 views)
2014-08-22 19:31:30

atombrot (38 views)
2014-08-19 09:29:53

Tekkerue (33 views)
2014-08-16 06:45:27

Tekkerue (32 views)
2014-08-16 06:22:17

Tekkerue (20 views)
2014-08-16 06:20:21

Tekkerue (29 views)
2014-08-16 06:12:11

Rayexar (66 views)
2014-08-11 02:49:23

BurntPizza (42 views)
2014-08-09 21:09:32

BurntPizza (34 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!