MaxStocker.com   MaxStocker.com    
   
Home About Blog Stuff Contact
 
   
 

May 2008

Facebook busted?
Posted : Sat May 31st

Applet Code Tip
Posted : Thu May 29th

The hidden costs of bad data
Posted : Wed May 28th

Deciphering TCO
Posted : Tue May 27th

Buffers are better
Posted : Thu May 22nd

Feelings nothing more than feelings
Posted : Mon May 19th

A Sense of Scale
Posted : Thu May 15th

More Fun...
Posted : Tue May 13th

No push please
Posted : Sun May 11th

Open wireless network hazards
Posted : Thu May 8th

Caveat emptor
Posted : Wed May 7th

Have Fun
Posted : Tue May 6th

Font Preview Tool
Posted : Fri May 2nd

XML is not a database
Posted : Thu May 1st

Recent Comments

Max in Whose blog is it anyway?
on Mon May 10th

Rob in Whose blog is it anyway?
on Fri May 7th

Anonymous in SEO and the magic beans
on Thu April 8th

Max in SEO and the magic beans
on Thu April 8th

n.o. in SEO and the magic beans
on Thu April 8th

silky in Right way, wrong way
on Fri February 19th

Categories

Technical
69 Entries

Java
23 Entries

Security
18 Entries

Privacy
6 Entries

Database
11 Entries

Internet
58 Entries

Business
31 Entries

Site Updates
19 Entries

Personal
86 Entries

RSS Feed RSS Feed

Tag Cloud

Applet Code Tip
Posted : Thursday May 29th, 2008

For today I have a simple coding tip to keep in mind when writing applets and it is this:

As much as possible do not use methods of the Applet (JApplet) class.

This seems at first glance to be an odd thing to suggest but actually it isn't. With the exception of life-cycle related events like bootstraping via init() you can avoid using Applet methods in general and your code will become portable to non-applet applications because of it.

As an example of what to avoid, there are a number of Applet and AppletContext specific methods like getImage and getStream which are easily replaced using techniques available to any Java program, stand-alone or applet.

So instead of using

InputStream in = getAppletContext().getStream(key);

use

InputStream in = getClass().getClassLoader().getResourceAsStream(key);

It seems to me that one of the main advantages of applets is that you can re-use code from them to stand-alone applications and vice-versa, so while there are a number of these "convenience" methods in Applet why not just simply use methods that will work both inside and out of an Applet?

Tags

applet  code  programming  tips 

Categories

Technical  Internet 

Comments

 
   
  Follow me on Twitter   My Facebook Profile   My LinkedIn Profile   RSS feed of my blog Home   |   About   |   Blog   |   Stuff   |   Contact   |   Privacy Policy  
   
  © 2008 Max Stocker