Client side (Applet) and Server side (Servlet) Graphics in Java
Archive - Originally posted on "The Horse's Mouth" - 2009-06-17 08:56:12 - Graham EllisWhat is the current release of Java? Is it Java 1.6, Java 2 (1.6) or Java 6? Yes it is - they're all different names for the same thing!
Java started out as Java 1.0 ... and since code that would run on that Virtual Machine / written in that language will still run on today's version, it's still technically "Java 1". But would you seriously 'buy' a product that's not had a major revision in more than a dozen years? You would think twice ... and so it was that the marketing gurus switched to the "Java 2" name, and then to "Java 5" for 1.5 and "Java 6" for 1.6. And in some ways that makes huge sense beyond the marketing side too, because Java 6 is a very different beast to Java 1.0
Java 1.0's main use was in Applets - code running within a user's browser, sandboxed into an internal frame within a browser window and with carefully limited access beyond that frame. A very close parallel to Flash these days. But things have moved on ... Java has moved from browser / client side through to server side, where it's running complete applications (perhaps under Tomcat through the Servlet / JSP interface, tag libraries, Struts, Spring and the rest!)
From its early days, Java supported graphics through the AWT - Abstract Windowing Toolkit - a useful but low level interface. You call methods to paint with a Graphic object on a Frame object - methods with name like setcolor and drawLine and drawString. If you're working at this level, you'll be using pixel addressing so you'll find that you're providing your own utility methods with names like toXPixel and toYPixel - mapping world to screen coordinates; there's an example of such an applet here.
So is such graphics useful now that most Java runs on the server? It turns out that yes, it is!. As well as working on a Frame within a browser window, Java can work on a psuedoFrame in memory ... and then that frame can be stored as - for example - a .jpg file. We have an example of such a Servlet (for that's what it is) here. Technically, it uses a BufferedImage object, on which you run a createGraphics - it took me a while to work out the first time, but the example I'm pointing you at (link on "here") has all the hard word done for you and produces a graphic of data that the server extracts from MySQL database table. A truly 'put it all together' application!