Computer Science Canada

Where to go next?

Author:  Jonny Tight Lips [ Fri Jul 29, 2005 1:28 pm ]
Post subject:  Where to go next?

I'm just starting to try and learn Java and I've read the HelloWolrd the Java way totural and I think I got a general understanding of it but I'm not sure where I should be looking next. In turning I would move on to Input from the user and if statments but I'm not sure. If you could suggest some tutorials I would be very greatful. Thx

Author:  wtd [ Fri Jul 29, 2005 1:42 pm ]
Post subject: 

Read up on methods. Methods are the fundamental means by which executable code is organized.

As part of this, understand the difference between static and non-static methods, and static and non-static contexts in general.

Write the additional code that makes the following make sense and do what you'd expect it to:

Java:
public class HelloWorld
{
   public static void main(String[] args)
   {
      sayHelloWorld();

      HelloWorld hw = new HelloWorld();

      hw.sayHelloTo("Bob");
   }
}

Author:  rizzix [ Fri Jul 29, 2005 1:44 pm ]
Post subject: 

Shoot. I was made aware of this problem before. But back then and now recently, I'm currently occupied working on some tutorials. The problem is the tutorials in the Java section is not designed for a programmer completly new to the Java syntax. It assumes you already know the basics. Such a tutorial about the raw basics is missing.

*sigh* If you'd give me a day or two? I'd probably get a couple of them done. Thanks for reminding me though.

Author:  wtd [ Fri Jul 29, 2005 1:53 pm ]
Post subject: 

I'd like to humbly submit this thread as an example of writing to a newbie audience.

Author:  [Gandalf] [ Fri Jul 29, 2005 2:01 pm ]
Post subject: 

Good luck making yours as thourough (sp?) as wtd's Smile.

Also, wtd: sayHelloWorld() would be static, and sayHelloTo() would be a member function (method) of HelloWorld with a string parameter, right?

Author:  Spartan_117 [ Fri Jul 29, 2005 7:12 pm ]
Post subject: 

Everyones in love with the HelloWorld app which ticks me off. Ya its usefull for very basics, but what about Images. Loading Images in an Applet is so damn difficult.

ANd wen i open my Applet in a Browser it gives me this:

http://us.share.geocities.com/deville_75/IHATETHIS.bmp

pain in arse. I've been trying to make this applet work for at least 6 months.

Author:  wtd [ Fri Jul 29, 2005 7:21 pm ]
Post subject: 

Spartan_117 wrote:
Everyones in love with the HelloWorld app which ticks me off. Ya its usefull for very basics, but what about Images. Loading Images in an Applet is so damn difficult.


Did you ever stop to think... maybe there's a reason for this?

Working with images is more complicated than working with text, and yet... the language and the basic concepts are the same. When you teach the basics, you want to stick to the concepts, without going off on a long tangent about how to manipulate images.

Author:  Spartan_117 [ Sat Jul 30, 2005 10:52 am ]
Post subject: 

Yes thats true, i understand, and the reason for my anger is nothing against HelloWorld, i just took it out on it because im still having a hard time loading images and its been months and i've been on three forums asking for help.

Author:  wtd [ Sat Jul 30, 2005 1:09 pm ]
Post subject: 

Have you tried Google?

Author:  Spartan_117 [ Sat Jul 30, 2005 4:30 pm ]
Post subject: 

Ya i hav, i know the code, but On Firefox my applet jus plays music, and on IE it gives me this X at the top left of the applet. I dunno what to do about this

Author:  wtd [ Sat Jul 30, 2005 4:58 pm ]
Post subject: 

Spartan_117 wrote:
Ya i hav, i know the code, but On Firefox my applet jus plays music, and on IE it gives me this X at the top left of the applet. I dunno what to do about this


Perhaps the applet is trying to load an image from the user's hard drive, but that image is not there?

Author:  Spartan_117 [ Sat Jul 30, 2005 7:48 pm ]
Post subject: 

thats definitely not the case
i just realized that it doesnt even set the background to black. When i put g.fillRect (...) it doesnt work. THe browser still gives me that X at the top left. of the applet.

Author:  rizzix [ Sun Jul 31, 2005 10:25 am ]
Post subject: 

well thats because ur applet is not loading in your browser.

Author:  Spartan_117 [ Sun Jul 31, 2005 6:33 pm ]
Post subject: 

So the applet's not loading? why nott? the class and java files are right there. It doesnt make sense cuz the correct music is playing... very odd indeed. So its loading part of the applet?

Author:  rizzix [ Mon Aug 01, 2005 1:51 pm ]
Post subject: 

eh? your are playing music through the applet?... well if thats the case.. then ur applet is loading... its wierd. well how about a screenshot?

Author:  Spartan_117 [ Mon Aug 01, 2005 9:27 pm ]
Post subject: 

ya the music is being played through the applet, so the applet must be loading. I hav an attachement which is the screenshot of what i get when opening the applet in the IE Browser. In Firefox the applet just stays grey.

Author:  [Gandalf] [ Mon Aug 01, 2005 9:51 pm ]
Post subject: 

THat used to always happen to me. Make sure you have ALL the files, and that you have them pointing to an archive or whatever you are holding all your files in. Also, make sure you have the proper version of JRE installed for your browser. If you want, show us the html file with your applet.

Author:  Hikaru79 [ Tue Aug 02, 2005 12:03 am ]
Post subject: 

Right-click on the dead applet, click on "Open Java Console" and paste whats in there. That should help us solve your problem Smile

Author:  Spartan_117 [ Tue Aug 02, 2005 12:36 pm ]
Post subject: 

This is what it says in Java Console:

Java Plug-in 1.5.0_04
Using JRE version 1.5.0_04 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\seguin4


----------------------------------------------------
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.security.AccessControlException: access denied (java.io.FilePermission turtle1.gif read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at sun.awt.SunToolkit.getImageFromHash(Unknown Source)
at sun.awt.SunToolkit.getImage(Unknown Source)
at BadGuy.<init>(BadGuy.java:53)
at MarioBros.init(MarioBros.java:86)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception in thread "thread applet-MarioBros.class" java.lang.NullPointerException
at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
at sun.plugin.AppletViewer.showAppletException(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Does anyone understand thiS???

I'll also upload the applet with all the files soon so u guys can take a look at that too.

Author:  rizzix [ Tue Aug 02, 2005 1:56 pm ]
Post subject: 

yea... apparently you are trying to access a file from the client's computer.. this is not allowed.. you can only access stuff from the server it self.

Author:  Hikaru79 [ Tue Aug 02, 2005 2:54 pm ]
Post subject: 

Rizzix is right, and I'm sure you can very easily see why you cannot access files on a client's computer through an applet that is automatically downloaded and executed on a remote computer. Java would be a script kiddie paradise if this were possible Very Happy

Here's an FAQ that addresses the security limitations placed on Applets: http://javaboutique.internet.com/community/faq/faq4.html

Oh, and learn to read stack traces, they are VERY useful for debugging. For example, you have not provided any source code, and yet I can tell you this: On line 35 of your file named BadGuy.java (which was called by a constructor of the MarioBros class on line 86), you try to load an image, turtle1.gif . I haven't even seen the source, but I could thoroughly debug it just from the stack trace. So try reading and understanding them whenever you get one Smile It'll make your life easier in the long run.

Author:  Spartan_117 [ Tue Aug 02, 2005 4:15 pm ]
Post subject: 

Hikaru are u using some kind of witchcraft? lol jk Laughing

Quote:
yea... apparently you are trying to access a file from the client's computer.. this is not allowed.. you can only access stuff from the server it self.


What do u mean by client's computer? All the files are in the same folder (pictures, class folder, html file, source code), in my account on Windows XP.

I dont exactly understand what this means. And if u guys still want i can post this applet up if u guys need to check.

Author:  [Gandalf] [ Tue Aug 02, 2005 4:55 pm ]
Post subject: 

You should archive all the files you need for the project (include .class files) except for the main class file. Then upload both. Then, when you make your html file for the applet it should look somethign like this:

code:
<applet code=Mario.class archive=Mario.zip width=500 height=300>
 </applet>

Author:  Spartan_117 [ Wed Aug 03, 2005 9:39 am ]
Post subject: 

Quote:
You should archive all the files you need for the project (include .class files) except for the main class file. Then upload both. Then, when you make your html file for the applet it should look somethign like this:

Code:
<applet code=Mario.class archive=Mario.zip width=500 height=300>
</applet>


Maybe im stupid, but i think im misunderstanding you. This is what i did. I put all the files (every single file needed) in one folder and zipped the folder. Then i copied the original (unarchived) main class file(MarioBros.class) into the same directory as the zipped folder. Then in that same directory i made an HTML file with this code:

code:
<html>
  <head>
    <title>
       The MarioBros applet
    </title>
  </head>
  <body>
    <h2>
      Here is the MarioBros applet
    </h2>
    <hr>
    <applet code="MarioBros.class" archive="TheMarioGame.zip"width="399" height="300">
    </applet>
    <hr>
  </body>
</html>


Is this what im supposed to do? cuz i still get a very long list of errors and the applet still doesnt load.

Author:  rizzix [ Wed Aug 03, 2005 10:46 am ]
Post subject: 

And, refer to the image file in your code by its "name" only . Do not use the entire c:\Docuements and.. bla path.

Author:  Spartan_117 [ Wed Aug 03, 2005 1:52 pm ]
Post subject: 

Quote:
And, refer to the image file in your code by its "name" only . Do not use the entire c:\Docuements and.. bla path.


no im already referring it by name (eg. "turtle1.gif")

But i think i'm misunderstanding what Gandalf was trying to tell me:

Quote:

You should archive all the files you need for the project (include .class files) except for the main class file. Then upload both. Then, when you make your html file for the applet it should look somethign like this:

Code:
<applet code=Mario.class archive=Mario.zip width=500 height=300>
</applet>

Author:  [Gandalf] [ Wed Aug 03, 2005 2:37 pm ]
Post subject: 

I don't know, it seems like you are doing it correctly...

Without more experience I can't tell you much more, but I know there is a pretty simple solution.

Here's my last little bit of input (watch this work heh):
*In the applet html code (what I showed you) try taking out the "" quotes. It's the only difference I can see, and I know that my applet works.

So, instead, use this code:
HTML:
<html>
  <head>
    <title>
       The MarioBros applet
    </title>
  </head>
  <body>
    <h2>
      Here is the MarioBros applet
    </h2>
    <hr>
    <applet code=MarioBros.class archive=TheMarioGame.zip width=399 height=300>
    </applet>
    <hr>
  </body>
</html>

Exactly that.

Author:  Hikaru79 [ Wed Aug 03, 2005 5:36 pm ]
Post subject: 

Spartan_117 wrote:
What do u mean by client's computer? All the files are in the same folder (pictures, class folder, html file, source code), in my account on Windows XP.

I dont exactly understand what this means. And if u guys still want i can post this applet up if u guys need to check.

Okay, in a network (like the internet), the most common type of relationship is called "Server-Client", and it consists of one computer that serves web pages/applets/files/etc, (called the server), and one of them that recieves what the server is sending (this is called the client). So the computer hosting the applet is a server, and the computer running the applet (viewing it) is called the client. In your case, I assume you are running both from the same computer, so it is both a server and a client. Depending on how the Applet security measures are implemented, this may be the problem -- Java only lets you access the server, not the client, but since you are both, it may choose to not let you access anything. However, the more likely cause of this is that you are keeping the files spread out in the same directory. On a server, this won't work. You need to archive them all together, in a .jar for example, and write a proper Manifest file for it. Then, do as Gandalf instructed, and specify where the archive is in the HTML code. If this doesn't solve anything, then do this again, but upload them to a remote server instead. Unless there are other errors in your code as well, I am 95% confident that this will solve your problem.

Author:  Spartan_117 [ Thu Aug 04, 2005 11:43 am ]
Post subject: 

well this is what i did. I archived all the images and music files in a folder and uploaded to my server (geocities.com). Then i took all the classes (MarioBros.class, BadGuy.class, GoodGuy.class) and put them in the same directory as the archive folder with all the images (im using .zip). THen i create an HTML document with the same code Gandalf stated. It seems like its working cuz im getting no errors. But it never loads. It says its loading but it never finishes. It seems its take years to load! Try it yourself: http://www.geocities.com/deville_75/MarioBros.html
Could it be my code?

Image Arena = getImage(getDocumentBase(), "Arena.jpg")

whats the difference between getCodeBase and getDocumentBase?

Author:  rizzix [ Thu Aug 04, 2005 1:31 pm ]
Post subject: 

post us ur code.. all of itt,, the entire folder.. just archive it and post it..

Author:  [Gandalf] [ Thu Aug 04, 2005 2:50 pm ]
Post subject: 

You are probably not archiving/compressing it properly so it doesn't read the files inside.

Author:  Spartan_117 [ Thu Aug 04, 2005 6:13 pm ]
Post subject: 

hmm, why would not compress it properly??? do u think i should make a .zip .rar or a .jar file?

Heres an archive with all the files: classes, images, music, html

Author:  Hikaru79 [ Thu Aug 04, 2005 6:40 pm ]
Post subject: 

Spartan_117 wrote:
hmm, why would not compress it properly??? do u think i should make a .zip .rar or a .jar file?

I think it might have to be a .jar with a proper manifest file. Rizzix, can you confirm or debunk this? Confused

Author:  rizzix [ Thu Aug 04, 2005 7:30 pm ]
Post subject: 

Oh dear Spartan_117,

FORGET! the stupid archive file Evil or Very Mad i mean to think you could actually let me see such horrifying code!! Evil or Very Mad what.. is that gibberish!!

*sigh* but i try.. i mean i try.. i try not to comment on SUB-AVERAGE CODE!!.. but seriously.. ugh...

Your code has some _serious_ problem(s). I can tell you this because i ran it on my own webserver, and guess what? It did not run.

I ran it directly from the folder (screw the archive file). Nope. It did not run.

I noticed you loop-played an audio file in the init() code. So i commented it out, yet, guess what? It did not run.

(I mean to loop in the init(), what are you thinking! This is not the way you go about playing music in the background in any program. You are preventing it from further execution! Naughty Create a thread, and loop within that thread.)

Aside of all this, it does not run either way. There's something terrible wrong within your code. It simply will not initialise. (*hint*) Hand

I dont think i have the time to try and debug it. Nor would I like to try. It is simply far too horribly, ugh, messy, but since I'm such a nice guy I "will try" nevertheless.

*sigh* I'll try, but no guarantees. Just do your self a favour.. LEARN TO CODE! Evil or Very Mad We can't help you if you can't do it right..

Author:  [Gandalf] [ Thu Aug 04, 2005 8:10 pm ]
Post subject: 

Well...
Spartan_117 wrote:
I've been trying to make this applet work for at least 6 months.

Sad
What you have to do is, after practically every change you make, test the code out! Compiling doesn't take that long and it saves a lot of trouble.

I ran across threads too, what are they? Seems to me like they are some kind of Java 'process'. Also, I often see this.something, what does that mean?

code:
String url = "http://www.geocities.com/deville_75/applets/images/";

Didn't you say that you had made everything so that it could lead to the same folder? I may be wrong, but this should probably just be images/.

Lastly, oh dear, how do I get rid of that music! I like the Mario song but I can't stop it!! Confused

*edit* It's still running!

Author:  rizzix [ Thu Aug 04, 2005 8:47 pm ]
Post subject: 

Ctrl+Alt+Del and kill firefox or whatever browser u were running it through

It runs in that loop because, his applet never gets to completing its initialization.. It loops during the init-phase.. hence it: #1) does not load, #2) hangs the browser.

Author:  wtd [ Thu Aug 04, 2005 8:49 pm ]
Post subject: 

[Gandalf] wrote:
Also, I often see this.something, what does that mean?


Keep an eye on my Java Tutorial for an answer to that question.

Author:  [Gandalf] [ Thu Aug 04, 2005 8:56 pm ]
Post subject: 

rizzix wrote:
Ctrl+Alt+Del and kill firefox or whatever browser u were running it through

But... but, what about my 50+ open tabs? Laughing
Yeah, I'm crazy.

Alright wtd, I can't wait Smile.

Gandalf wrote:
I ran across threads too, what are they? Seems to me like they are some kind of Java 'process'.

Am I right?

Author:  wtd [ Thu Aug 04, 2005 9:05 pm ]
Post subject: 

[Gandalf] wrote:
Gandalf wrote:
I ran across threads too, what are they? Seems to me like they are some kind of Java 'process'.

Am I right?


With the notable exception that they work.

Threads are available from many different programming languages.

Author:  Spartan_117 [ Fri Aug 05, 2005 8:48 am ]
Post subject: 

how come theres no cry emoticon here???
cuz all i can do is cry!!! I should hav just used swing. I was so damn inexperienced with applets. The graphics kill me; or wait, is it more than jus the graphics that i suck at??? Thanks rizzix for taking the time to try to debug it, but if it takes too much time forget it. I think the problem is that i used RTP. FOR YOUR OWN SAKE DO NOT USE RTP!!!!! I HATE IT!! It's horrible, it teaches ppl how to become the worst programmers!!!! I would not have such a horribly coded game if it werent for this horrible IDE!!

Why you asK?? well you kno how you say my code is junk and that it needs major debugging!? well the reason i didnt kno this is because RTP actually compiled and made it work. I was using RTP and dont think i never compiled and tested it. Of course i did. In RTP everything ran fine, everything worked, the graphics loaded up, the music played, and it responded to the keyboard, except the screen flickkered (I ran it direct from RTP (not a browser) supposedly RTP has its own appletviewer). But who gives a rats ass if it works on RTP!! no one uses it! It needs to work on the browser. I thought if it ran on RTP it should prob work when i put it online. NOOOOOO!! I THOUGHT WRONG!!! I started learning Java on RTP and it was the biggest mistake! Somehow RTP forces it to run (someone mentioned it used Jikes compiler or somethign). I dunno, whatever it uses RTP is the worst IDE, especially if you start out learning Java on it! I ADVISE EVERYONE NOT TO USE THIS USELESS SOFTWARE WHICH COSTS MONEY!

Im so frustrated .... Sad Confused Mad Evil or Very Mad Exclamation Exclamation Exclamation

Author:  rizzix [ Fri Aug 05, 2005 1:12 pm ]
Post subject: 

oh yea we have been condemning RTP from the start.. anyways,, try and get it to run as a standalone swing application.. forget creating an applet for now..

Author:  [Gandalf] [ Fri Aug 05, 2005 3:33 pm ]
Post subject: 

You missed it: Crying or Very sad

Anyways, I have been meaning to ask. Is it easy to switch to an applet once you have a program done as a standalone application? It seems to me like it would be easier to make an application first...

Author:  rizzix [ Fri Aug 05, 2005 7:21 pm ]
Post subject: 

Yes it is.

Now I did some research on SWING applet programming, and its a little more complex than i expected. Specially with SWING.

I would not recommed creating an applet (specially if you are using images) if you are just new to Java. It is best you create a SWING app instead.

Author:  Spartan_117 [ Sat Aug 06, 2005 11:43 am ]
Post subject: 

Ya, im thinking of making it a standalone with Swing, but wont it be hard to switch from applet to Swing now? I dont know where to start...

Author:  wtd [ Sat Aug 06, 2005 2:31 pm ]
Post subject: 

Spartan_117 wrote:
Ya, im thinking of making it a standalone with Swing, but wont it be hard to switch from applet to Swing now? I dont know where to start...


Start with the Swing tutorial at http://java.sun.com.


: