Programmers: I conquered Java at last!

I got an Applet/Application combo (all in one source file! --with the help of a few inner classes…) that can load and use external file data. It just made me so happy to figure this out I figured I’d share.

It is a simple homework assignment to display a moving flag and play national anthems. Currently does Canada, China, Denmark, France, Germany, India, Norway, the UK, and the USA. Sorry if your country isn’t there…

If you’re interested in how I did it the full source is listed there also. Compiles on both Win and *nix platforms. Only about 740 lines long (which includes lots of commentary).

Java has some nice features that suck you in as a beginning programmer, but you don’t have to get in too deep to realize you’re in quicksand. In other words, I can’t stand Java. (It’s evil!)

Only about 740 lines long

Why I hate java.

Anyway, congrats!

Try NOT to use one source file - it’s not something to be proud of :wink: (In fact, inner classes are best avoided too).

I knew I’d nailed it when finally interfaces made perfect sense. In fact, when Java really properly clicks you do wonder why anyone ever has any issues with it beyond some of the API design, and the way it handles collections/generics being a bit on the special side.

The verbosity is a tad annoying. Personally I reckon Java with a Python like structure (ie use the indenting syntactically, and less brackets) would be pretty close to my perfect language. Oh, and bin much of the API and start again.

I spend my days writing mainly J2ME, and that’s a real can of worms. To write good J2ME you have to basically abandon all “proper” java practises.

Anyway, good luck with continuing! I remember what it was like - and really I only got it by being made to work on an enormous already working codebase, and having to learn what it was doing.

If you’re not already I strongly recommend you use Eclipse (the IDE ) as it makes life much quicker and easier. Especially for auto-completion and whatnot. Then get into Ant.

It didn’t work in my browser but it did work offline in an Applet launcher. In the browser, it failed with:

java.lang.Error: Do not use Anthem.add() use Anthem.getContentPane().add() instead
at javax.swing.JApplet.createRootPaneException(

I tried changing the add methods I could see and even commenting them out but it didn’t seem to help.

Anyway, it’s good to see you again Duoas, I was wondering where you went. Now I know you’ve been tormenting yourself with learning Java. Like Kid Tripod, I also disliked the verbosity of java but sometimes it helps. For example, in the Windows dll folders, trying to find the one you want can be a real pain because of the 8+3 letters. Auto-completion goes some way to help the verbosity problem.

I remember doing Applets at uni, at the time I thought they were the way forward for animated website content because you could pretty much run any program you make in Java with the exception of the security limitations imposed on them. But the load time is higher than Flash and Flash doesn’t flicker so much. It would be nice if Applets + SVG could take over from Flash.

It’s good for online programs though - at uni, I had to write a basic raytracer and an AES encryption Applet among others. I wonder if this would be a good way to put a front end on a networked rendering server like Respower. In other words, you would load the web page and there would be a render window. You could then choose to load a .blend file and you’d see it render in the browser window. When it’s done, you could download the images to your filesystem.

Hey, thanks for the input everyone.

Yeah, I agree. I only did it for two reasons: to see it work and to reduce the number of files I had to edit…

Inner classes are just another form of data hiding. For example, the DrawCanvas class absolutely requires information about the Anthem_ class --the reason they are separate classes has more to do with the way things are structured in Java than functional disparity.

Whether you use inner classes, or inline classes, etc. or not your browser must make the same number of HTTP requests to get all the class files off of the server. (That’s why people use jar files --one request, one download.)

And yeah, I definitely agree about the API. Too much garbage…

Thanks! Your problem might be a versioning problem. I used the latest and greatest 1.5. It implements some significant modifications to the way things actually work from 1.4. Also, it is possible that your browser is using a different version of Java than you get from the command-line (or appletviewer)…

By verbosity we’re not referring simply to the length of things but to the number of hoops one must jump to do something simple (for example, opening and reading a file…)

The network raytracer sounds like a good idea, but it requires some serious network configuration (and back-door hoop jumping) to create an applet that can read and write files on the client machine. I’m not sure it is possible to do securely… Alas.

Perhaps some combo of PHP and server-side file I/O would work?

Anyway, yeah, I’m back. Hopefully I’ll get some serious blendering time in this month.

A lot of colledges are really pusing Java.

And spelling.

AGH! I closed the flag window I had open with your flag thingy, and now the music won’t go away O_O goes crazy

As long as you have the right signatures on the right pieces of paper like I have, no one can tell you you’re crazy. And the music goes away eventually… :wink:

I didn’t put in any explicit shutdown code to turn off the music sequencer (that’s supposed to automatically happen when the applet is terminated). If you don’t mind my asking, what browser are you using and what version of JRE? Did the music loop (re-playing over and over and over?) or did you just time out before the song did (the anthems are all about a minute long)?

I only tested in FF 2.0 and JRE 1.5 (this is just a homework problem, after all), but I am interested in making it as usable as possible… (the point is that I learn how to make Java work for everyone).