<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: class code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 03:11:35 GMT</pubDate>
    <description>DZone Snippets: class code</description>
    <item>
      <title>How to call a base class method</title>
      <link>http://snippets.dzone.com/posts/show/5082</link>
      <description>This Ruby example demonstrates using the keyword super to call the superclass method.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class Claw&lt;br /&gt;  def grab(item)&lt;br /&gt;    puts item + ' grabbed'&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;class Hand &lt; Claw&lt;br /&gt;  def grab(item)&lt;br /&gt;    super(item)&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;h = Hand.new&lt;br /&gt;h.grab('apple')&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;output &lt;br /&gt;&lt;code&gt;&lt;br /&gt;apple grabbed&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;for more information: http://www.google.com/search?q=ruby+keyword+super</description>
      <pubDate>Sat, 02 Feb 2008 00:51:59 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5082</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>before? and after? - Ruby Time class mixin</title>
      <link>http://snippets.dzone.com/posts/show/5022</link>
      <description>The mixin below allows comparison between two Time objects using the more intuitive and natural-sounding before? and after? methods.&lt;br /&gt;&lt;br /&gt;Some examples (using Rails' ActiveSupport Time extensions or (preferred) the 'units' gem):&lt;br /&gt;&lt;br /&gt;&lt;code&gt;2.minutes.ago.after? Time.now # =&gt; false&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;Time.now.before? 2.hours.from_now # =&gt; true&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;module BeforeAndAfter&lt;br /&gt;&lt;br /&gt;  LEFT_SIDE_LATER  = 1&lt;br /&gt;  RIGHT_SIDE_LATER = -1&lt;br /&gt;  &lt;br /&gt;  def before?(input_time)&lt;br /&gt;    (self &lt;=&gt; input_time) == RIGHT_SIDE_LATER&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  def after?(input_time)&lt;br /&gt;    (self &lt;=&gt; input_time) == LEFT_SIDE_LATER&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;Time.send :include , BeforeAndAfter&lt;/code&gt;</description>
      <pubDate>Mon, 21 Jan 2008 21:57:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5022</guid>
      <author>JimCropcho (Jim Cropcho)</author>
    </item>
    <item>
      <title>Get all classes within a package</title>
      <link>http://snippets.dzone.com/posts/show/4831</link>
      <description>The code below gets all classes within a given package. Notice that it should only work for classes found locally, getting really ALL classes is impossible.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;    /**&lt;br /&gt;     * Scans all classes accessible from the context class loader which belong to the given package and subpackages.&lt;br /&gt;     *&lt;br /&gt;     * @param packageName The base package&lt;br /&gt;     * @return The classes&lt;br /&gt;     * @throws ClassNotFoundException&lt;br /&gt;     * @throws IOException&lt;br /&gt;     */&lt;br /&gt;    private static Class[] getClasses(String packageName)&lt;br /&gt;            throws ClassNotFoundException, IOException {&lt;br /&gt;        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();&lt;br /&gt;        assert classLoader != null;&lt;br /&gt;        String path = packageName.replace('.', '/');&lt;br /&gt;        Enumeration&lt;URL&gt; resources = classLoader.getResources(path);&lt;br /&gt;        List&lt;File&gt; dirs = new ArrayList&lt;File&gt;();&lt;br /&gt;        while (resources.hasMoreElements()) {&lt;br /&gt;            URL resource = resources.nextElement();&lt;br /&gt;            dirs.add(new File(resource.getFile()));&lt;br /&gt;        }&lt;br /&gt;        ArrayList&lt;Class&gt; classes = new ArrayList&lt;Class&gt;();&lt;br /&gt;        for (File directory : dirs) {&lt;br /&gt;            classes.addAll(findClasses(directory, packageName));&lt;br /&gt;        }&lt;br /&gt;        return classes.toArray(new Class[classes.size()]);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    /**&lt;br /&gt;     * Recursive method used to find all classes in a given directory and subdirs.&lt;br /&gt;     *&lt;br /&gt;     * @param directory   The base directory&lt;br /&gt;     * @param packageName The package name for classes found inside the base directory&lt;br /&gt;     * @return The classes&lt;br /&gt;     * @throws ClassNotFoundException&lt;br /&gt;     */&lt;br /&gt;    private static List&lt;Class&gt; findClasses(File directory, String packageName) throws ClassNotFoundException {&lt;br /&gt;        List&lt;Class&gt; classes = new ArrayList&lt;Class&gt;();&lt;br /&gt;        if (!directory.exists()) {&lt;br /&gt;            return classes;&lt;br /&gt;        }&lt;br /&gt;        File[] files = directory.listFiles();&lt;br /&gt;        for (File file : files) {&lt;br /&gt;            if (file.isDirectory()) {&lt;br /&gt;                assert !file.getName().contains(".");&lt;br /&gt;                classes.addAll(findClasses(file, packageName + "." + file.getName()));&lt;br /&gt;            } else if (file.getName().endsWith(".class")) {&lt;br /&gt;                classes.add(Class.forName(packageName + '.' + file.getName().substring(0, file.getName().length() - 6)));&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        return classes;&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 30 Nov 2007 15:28:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4831</guid>
      <author>vtatai (Victor Tatai)</author>
    </item>
    <item>
      <title>Simple camera class in FTS - lookAt function.</title>
      <link>http://snippets.dzone.com/posts/show/4628</link>
      <description>// Camera class for FTS&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;/// Makes the camera look at a certain point.&lt;br /&gt;/** This function makes the camera look at a certain point. If that point is the same as its&lt;br /&gt; *  current position, the camera moves back the (current) distance |camera-target|.&lt;br /&gt; *&lt;br /&gt; * \param in_vTgt The position where the camera should look at.&lt;br /&gt; *&lt;br /&gt; * \return If successfull: ERR_OK&lt;br /&gt; * \return If failed:      An error code &lt; 0&lt;br /&gt; *&lt;br /&gt; * \author Pompei2&lt;br /&gt; */&lt;br /&gt;CFTSCamera *CFTSCamera::lookAt(const CFTSVector &amp; in_vTgt)&lt;br /&gt;{&lt;br /&gt;    // Calculate the new front vector that points to the target.&lt;br /&gt;    CFTSVector vNewFront = (in_vTgt - m_vPos).normalize();&lt;br /&gt;&lt;br /&gt;    // The two vectors are in one plane. This gives us the cosine of the angle between&lt;br /&gt;    // these two vectors.&lt;br /&gt;    float fDotProd = vNewFront.dot(m_vFront);&lt;br /&gt;    if(fDotProd &gt; 1.0f || fDotProd &lt; -1.0f)&lt;br /&gt;        return this;&lt;br /&gt;&lt;br /&gt;    // By getting the arc cosine of this, we get the angle in radians between the two&lt;br /&gt;    // vectors. But we only get an angle between 0 and pi, that will be a problem.&lt;br /&gt;    float fAlpha = acosf(fDotProd);&lt;br /&gt;&lt;br /&gt;    // Here we get the normal to these two vectors, we will need to rotate our front&lt;br /&gt;    // vector around this normal.&lt;br /&gt;    CFTSVector vNormal = vNewFront.cross(m_vFront).normalize();&lt;br /&gt;&lt;br /&gt;    // As I said, we have a problem: as we only get an angle between 0 and pi,&lt;br /&gt;    // we don't know if we need to rotate clockwise or counterclockwise ...&lt;br /&gt;    // We solve this problem by just trying it out.&lt;br /&gt;    CFTSVector vFrontTest = m_vFront.rotate(vNormal, fAlpha);&lt;br /&gt;&lt;br /&gt;    // If the dot product is near to one, it means we were right. with our guess&lt;br /&gt;    // rotating counterclockwise.&lt;br /&gt;    // Else, we must rotate clockwise.&lt;br /&gt;    fDotProd = vFrontTest.dot(vNewFront);&lt;br /&gt;    if(fabs(fDotProd) &gt; (1.0f - D_FTS_DELTA)) {&lt;br /&gt;            m_vFront = vFrontTest;&lt;br /&gt;            m_vUp = m_vUp.rotate(vNormal, fAlpha);&lt;br /&gt;            m_vRight = m_vRight.rotate(vNormal, fAlpha);&lt;br /&gt;    } else {&lt;br /&gt;            m_vFront = m_vFront.rotate(vNormal, -fAlpha);&lt;br /&gt;            m_vUp = m_vUp.rotate(vNormal, -fAlpha);&lt;br /&gt;            m_vRight = m_vRight.rotate(vNormal, -fAlpha);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    // If the dot product is near to -1, it means we look the wrong way.&lt;br /&gt;    // To correct this, we just rotate pi radians (a half circle).&lt;br /&gt;    if(fDotProd &lt; -(1.0f - D_FTS_DELTA))&lt;br /&gt;        this-&gt;rotateYRadians(M_PI);&lt;br /&gt;&lt;br /&gt;    return this;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 09 Oct 2007 19:49:43 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4628</guid>
      <author>Pompei2 (Lucas)</author>
    </item>
    <item>
      <title>Printing out the full path of a resource on the classpath</title>
      <link>http://snippets.dzone.com/posts/show/4489</link>
      <description>// displaying the full path of a resource found by the class loader on the classpath, here the log4j.xml file&lt;br /&gt;&lt;code&gt;&lt;br /&gt;String resourceName = "/log4j.xml"; // pay attention to the leading '/' !&lt;br /&gt;URL location = AnyClass.class.getResource(resourceName);&lt;br /&gt;&lt;br /&gt;if (location != null) {&lt;br /&gt;    System.out.println(location.getPath());&lt;br /&gt;} else {&lt;br /&gt;    System.out.println(resourceName + " not found on the classpath");&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 04 Sep 2007 09:59:44 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4489</guid>
      <author>Archanciel (Jean-Pierre Schnyder)</author>
    </item>
    <item>
      <title>Simple camera class in FTS</title>
      <link>http://snippets.dzone.com/posts/show/4313</link>
      <description>// Simple camera class in FTS&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;/**&lt;br /&gt; * \file camera.cpp&lt;br /&gt; * \author Pompei2&lt;br /&gt; * \date 15 July 2006&lt;br /&gt; * \brief This file contains the camera class implementation.&lt;br /&gt; **/&lt;br /&gt;&lt;br /&gt;#include "3d/camera.h"&lt;br /&gt;&lt;br /&gt;#include &lt;GL/gl.h&gt;&lt;br /&gt;&lt;br /&gt;#ifdef DEBUG&lt;br /&gt;#  define new new(__FILE__,__LINE__)&lt;br /&gt;#endif&lt;br /&gt;&lt;br /&gt;/// Constructor&lt;br /&gt;CFTSCamera::CFTSCamera( void )&lt;br /&gt;{&lt;br /&gt;    m_vRight = CFTSVector(1.0f,0.0f,0.0f);&lt;br /&gt;    m_vUp    = CFTSVector(0.0f,1.0f,0.0f);&lt;br /&gt;    m_vFront = CFTSVector(0.0f,0.0f,-1.0f);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/// Destructor&lt;br /&gt;CFTSCamera::~CFTSCamera( void )&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/// Places the camera at a certain point.&lt;br /&gt;/** This function places the camera at a certain point in space.&lt;br /&gt; *&lt;br /&gt; * \param in_vPos The new position of the camera.&lt;br /&gt; *&lt;br /&gt; * \return If successfull: ERR_OK&lt;br /&gt; * \return If failed:      An error code &lt; 0&lt;br /&gt; *&lt;br /&gt; * \author Pompei2&lt;br /&gt; */&lt;br /&gt;CFTSCamera *CFTSCamera::pos(const CFTSVector &amp; in_vPos)&lt;br /&gt;{&lt;br /&gt;    m_vPos = in_vPos;&lt;br /&gt;    return this;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/// Moves the camera to the right.&lt;br /&gt;/** This moves the camera to the right. The right is relative to the&lt;br /&gt; *  camera's orientation ! To move to the left, put a negative value here.&lt;br /&gt; *&lt;br /&gt; * \param in_fAmount The amount of units to move to the right.&lt;br /&gt; *&lt;br /&gt; * \author Pompei2&lt;br /&gt; */&lt;br /&gt;CFTSCamera *CFTSCamera::moveRight(float in_fAmount)&lt;br /&gt;{&lt;br /&gt;    // We have a vector pointing to the right,&lt;br /&gt;    // so moving to the right is an easy thing:&lt;br /&gt;    // Just add a multiple of this vector to the current position.&lt;br /&gt;    m_vPos = m_vPos + m_vRight.scalar(in_fAmount);&lt;br /&gt;&lt;br /&gt;    return this;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/// Moves the camera to the front.&lt;br /&gt;/** This moves the camera to the front. The right is relative to the&lt;br /&gt; *  camera's orientation and to be exact, it is where the camera looks at.&lt;br /&gt; *  Moving to the front is a bit like zooming in.&lt;br /&gt; *  To move back (like zoom out), put a negative value here.&lt;br /&gt; *&lt;br /&gt; * \param in_fAmount The amount of units to move to the front.&lt;br /&gt; *&lt;br /&gt; * \author Pompei2&lt;br /&gt; */&lt;br /&gt;CFTSCamera *CFTSCamera::moveFront(float in_fAmount)&lt;br /&gt;{&lt;br /&gt;    // Same as for moveRight.&lt;br /&gt;    m_vPos = m_vPos + m_vFront.scalar(in_fAmount);&lt;br /&gt;&lt;br /&gt;    return this;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/// Moves the camera upwards.&lt;br /&gt;/** This moves the camera upwards. Upwards is the direction that is perpendicular&lt;br /&gt; *  To your right and to your front, and shows up :) It is like the top of your head.&lt;br /&gt; *  To move downwards (to your feets), put a negative value here.&lt;br /&gt; *&lt;br /&gt; * \param in_fAmount The amount of units to move up.&lt;br /&gt; *&lt;br /&gt; * \author Pompei2&lt;br /&gt; */&lt;br /&gt;CFTSCamera *CFTSCamera::moveUp(float in_fAmount)&lt;br /&gt;{&lt;br /&gt;    // Same as for moveRight.&lt;br /&gt;    m_vPos = m_vPos + m_vUp.scalar(in_fAmount);&lt;br /&gt;&lt;br /&gt;    return this;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/// Rotates the camera around ITS x axis.&lt;br /&gt;/** This rotates the camera around THE CAMERA's x axis.&lt;br /&gt; *  This basically means it looks up or down. As seen from the right,&lt;br /&gt; *  a positive value rotates counterclockwise (look up) and a negative&lt;br /&gt; *  value rotates clockwise (look down).&lt;br /&gt; *&lt;br /&gt; * \param in_fAmount The amount of degrees to rotate.&lt;br /&gt; *&lt;br /&gt; * \author Pompei2&lt;br /&gt; */&lt;br /&gt;CFTSCamera *CFTSCamera::rotateX(float in_fAmount)&lt;br /&gt;{&lt;br /&gt;    Lib3dsMatrix mRotation;&lt;br /&gt;    Lib3dsQuat qRotation;&lt;br /&gt;&lt;br /&gt;    // First, clean the matrix.&lt;br /&gt;    lib3ds_matrix_identity(mRotation);&lt;br /&gt;&lt;br /&gt;    // Create the quaternion to rotate, we need the angle in radians.&lt;br /&gt;    lib3ds_quat_axis_angle(qRotation, m_vRight.lib3ds(), -RADIANS(in_fAmount));&lt;br /&gt;&lt;br /&gt;    // Apply the rotation to the identity matrix, creating a transformation matrix.&lt;br /&gt;    lib3ds_matrix_rotate(mRotation, qRotation);&lt;br /&gt;&lt;br /&gt;    // Rotate our front and up vectors, this makes the camera rotate.&lt;br /&gt;    m_vFront = m_vFront.transform(mRotation).normalize();&lt;br /&gt;    m_vUp = m_vUp.transform(mRotation).normalize();&lt;br /&gt;&lt;br /&gt;    return this;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/// Rotates the camera around ITS y axis.&lt;br /&gt;/** This rotates the camera around THE CAMERA's y axis.&lt;br /&gt; *  This basically means it looks left or right. As seen from the top,&lt;br /&gt; *  a positive value rotates counterclockwise (look left) and a negative&lt;br /&gt; *  value rotates clockwise (look right).&lt;br /&gt; *&lt;br /&gt; * \param in_fAmount The amount of degrees to rotate.&lt;br /&gt; *&lt;br /&gt; * \author Pompei2&lt;br /&gt; */&lt;br /&gt;CFTSCamera *CFTSCamera::rotateY(float in_fAmount)&lt;br /&gt;{&lt;br /&gt;    Lib3dsMatrix mRotation;&lt;br /&gt;    Lib3dsQuat qRotation;&lt;br /&gt;&lt;br /&gt;    // First, clean the matrix.&lt;br /&gt;    lib3ds_matrix_identity(mRotation);&lt;br /&gt;&lt;br /&gt;    // Create the quaternion to rotate, we need the angle in radians.&lt;br /&gt;    lib3ds_quat_axis_angle(qRotation, m_vUp.lib3ds(), -RADIANS(in_fAmount));&lt;br /&gt;&lt;br /&gt;    // Apply the rotation to the identity matrix, creating a transformation matrix.&lt;br /&gt;    lib3ds_matrix_rotate(mRotation, qRotation);&lt;br /&gt;&lt;br /&gt;    // Rotate our front and up vectors, this makes the camera rotate.&lt;br /&gt;    m_vFront = m_vFront.transform(mRotation).normalize();&lt;br /&gt;    m_vRight = m_vRight.transform(mRotation).normalize();&lt;br /&gt;&lt;br /&gt;    return this;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/// Rotates the camera around ITS z axis.&lt;br /&gt;/** This rotates the camera around THE CAMERA's z axis.&lt;br /&gt; *  This is the same effect as if you rotate your head to bring an ear&lt;br /&gt; *  close to the shoulder. A positive value rotates counterclockwise (left shoulder)&lt;br /&gt; *  and a negative value rotates clockwise (right shoulder).&lt;br /&gt; *&lt;br /&gt; * \param in_fAmount The amount of degrees to rotate.&lt;br /&gt; *&lt;br /&gt; * \author Pompei2&lt;br /&gt; */&lt;br /&gt;CFTSCamera *CFTSCamera::rotateZ(float in_fAmount)&lt;br /&gt;{&lt;br /&gt;    Lib3dsMatrix mRotation;&lt;br /&gt;    Lib3dsQuat qRotation;&lt;br /&gt;&lt;br /&gt;    // First, clean the matrix.&lt;br /&gt;    lib3ds_matrix_identity(mRotation);&lt;br /&gt;&lt;br /&gt;    // Create the quaternion to rotate, we need the angle in radians.&lt;br /&gt;    lib3ds_quat_axis_angle(qRotation, m_vFront.lib3ds(), -RADIANS(in_fAmount));&lt;br /&gt;&lt;br /&gt;    // Apply the rotation to the identity matrix, creating a transformation matrix.&lt;br /&gt;    lib3ds_matrix_rotate(mRotation, qRotation);&lt;br /&gt;&lt;br /&gt;    // Rotate our front and up vectors, this makes the camera rotate.&lt;br /&gt;    m_vUp = m_vUp.transform(mRotation).normalize();&lt;br /&gt;    m_vRight = m_vRight.transform(mRotation).normalize();&lt;br /&gt;&lt;br /&gt;    return this;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/// Renders the camera.&lt;br /&gt;/** This function applies all transformations to the current matrix&lt;br /&gt; *  that are needed to place the camera.&lt;br /&gt; *&lt;br /&gt; * \author Pompei2&lt;br /&gt; */&lt;br /&gt;CFTSCamera *CFTSCamera::render(void)&lt;br /&gt;{&lt;br /&gt;    // gluLookAt wants a point in space to look at, not just a direction.&lt;br /&gt;    // Calculate this point.&lt;br /&gt;    CFTSVector vLookAt = m_vPos + m_vFront;&lt;br /&gt;&lt;br /&gt;    // Let gluLookAt do all the matrix calculation stuff.&lt;br /&gt;    gluLookAt(m_vPos.x(), m_vPos.y(), m_vPos.z(),&lt;br /&gt;              vLookAt.x(), vLookAt.y(), vLookAt.z(),&lt;br /&gt;              m_vUp.x(), m_vUp.y(), m_vUp.z());&lt;br /&gt;&lt;br /&gt;    return this;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 17 Jul 2007 22:32:58 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4313</guid>
      <author>Pompei2 (Lucas)</author>
    </item>
    <item>
      <title>Add a jar file to Java load path at run time</title>
      <link>http://snippets.dzone.com/posts/show/3574</link>
      <description>Sometimes it is necessary to amend the class load path at run time. For example, dynamically adding jar files containing user-configurable JDBC data sources. The way this is done is truly monstrous -- the URL Path format was only revealed when a colleague looked into the Java library sources.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import java.net.URL;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.net.URLClassLoader;&lt;br /&gt;import java.net.MalformedURLException;&lt;br /&gt;&lt;br /&gt;public class JarFileLoader extends URLClassLoader&lt;br /&gt;{&lt;br /&gt;    public JarFileLoader (URL[] urls)&lt;br /&gt;    {&lt;br /&gt;        super (urls);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void addFile (String path) throws MalformedURLException&lt;br /&gt;    {&lt;br /&gt;        String urlPath = "jar:file://" + path + "!/";&lt;br /&gt;        addURL (new URL (urlPath));&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public static void main (String args [])&lt;br /&gt;    {&lt;br /&gt;        try&lt;br /&gt;        {&lt;br /&gt;            System.out.println ("First attempt...");&lt;br /&gt;            Class.forName ("org.gjt.mm.mysql.Driver");&lt;br /&gt;        }&lt;br /&gt;        catch (Exception ex)&lt;br /&gt;        {&lt;br /&gt;            System.out.println ("Failed.");&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        try&lt;br /&gt;        {&lt;br /&gt;            URL urls [] = {};&lt;br /&gt;&lt;br /&gt;            JarFileLoader cl = new JarFileLoader (urls);&lt;br /&gt;            cl.addFile ("/opt/mysql-connector-java-5.0.4/mysql-connector-java-5.0.4-bin.jar");&lt;br /&gt;            System.out.println ("Second attempt...");&lt;br /&gt;            cl.loadClass ("org.gjt.mm.mysql.Driver");&lt;br /&gt;            System.out.println ("Success!");&lt;br /&gt;        }&lt;br /&gt;        catch (Exception ex)&lt;br /&gt;        {&lt;br /&gt;            System.out.println ("Failed.");&lt;br /&gt;            ex.printStackTrace ();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 23 Feb 2007 15:24:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3574</guid>
      <author>mikewilsonuk (Mike Wilson)</author>
    </item>
    <item>
      <title>Actionscript _Text Class</title>
      <link>http://snippets.dzone.com/posts/show/3517</link>
      <description>Useful functions for adding dynamic text fields.  Don't forget, you have to add the font of choice into the main movie Library for this to work (Library Panel Menu &gt; New Font).  The name you give the font is the string that you pass to the getTextFormat function for the "font" parameter.  Setup your font styles with getTextFormat, setup your dynamic text box with getTextField, and then add text to the text box with appendTextField.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;dynamic class _Text {&lt;br /&gt;	static function getTextFormat(font:String,size:Number,color:Number,leading:Number,url:String,target:String){&lt;br /&gt;		var fmt:TextFormat = new TextFormat();&lt;br /&gt;		fmt.font = font;&lt;br /&gt;		fmt.kerning = true;&lt;br /&gt;		fmt.leading = (leading != undefined &amp;&amp; leading != null) ? leading : 0;&lt;br /&gt;		fmt.bold = false;&lt;br /&gt;		fmt.size = (size != undefined &amp;&amp; size != null) ? size : 11;&lt;br /&gt;		fmt.color = (color != undefined &amp;&amp; color != null) ? color : 0x000000;&lt;br /&gt;&lt;br /&gt;		if (url != undefined &amp;&amp; url != null) {&lt;br /&gt;			fmt.url = url;&lt;br /&gt;			fmt.target = (target != undefined &amp;&amp; target != null) ? target : "_self";&lt;br /&gt;		}&lt;br /&gt;		return (fmt);&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	static function getTextField(targetMC,targetDepth,txtFieldName,x,y,w,h,txtObj){&lt;br /&gt;		var targetDepth = (targetDepth != undefined &amp;&amp; targetDepth != null) ? targetDepth : targetMC.getNextHighestDepth();&lt;br /&gt;		var txtfld = targetMC.createTextField(txtFieldName, targetDepth, x, y, w, h);&lt;br /&gt;		txtfld.antiAliasType = (txtObj.antiAliasType) ? txtObj.antiAliasType : "advanced";&lt;br /&gt;		txtfld.sharpness = (txtObj.sharpness) ? txtObj.sharpness : -60;&lt;br /&gt;		txtfld.thickness = (txtObj.thickness) ? txtObj.thickness : -100;&lt;br /&gt;		txtfld.embedFonts = (txtObj.embedFonts) ? txtObj.embedFonts : true;&lt;br /&gt;		txtfld.selectable = (txtObj.selectable) ? txtObj.selectable : false;&lt;br /&gt;		txtfld.html = (txtObj.html) ? txtObj.html : true;&lt;br /&gt;		txtfld.multiline = (txtObj.multiline) ? txtObj.multiline : true;&lt;br /&gt;		txtfld.autoSize = (txtObj.autoSize) ? txtObj.autoSize : "left";&lt;br /&gt;		&lt;br /&gt;		if (txtObj.htmlText) txtfld.htmlText = txtObj.htmlText;&lt;br /&gt;		if (txtObj.txtFormat) txtfld.setTextFormat(txtObj.txtFormat);&lt;br /&gt;		&lt;br /&gt;		if (txtObj.wordWrap == undefined || txtObj.wordWrap == null) txtfld._width = txtfld.textWidth + 10;&lt;br /&gt;		else txtfld.wordWrap = txtObj.wordWrap;&lt;br /&gt;		return txtfld;&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	static function appendTextField(txtfld,txtfrmt,txt){&lt;br /&gt;		var beginIndex:Number = txtfld.htmlText.length;&lt;br /&gt;		txtfld.setNewTextFormat(txtfrmt);&lt;br /&gt;		txtfld.replaceText(beginIndex,beginIndex,txt);&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 13 Feb 2007 20:17:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3517</guid>
      <author>bgidge (Bryan Gidge)</author>
    </item>
    <item>
      <title>Actionscript _Draw Class</title>
      <link>http://snippets.dzone.com/posts/show/3515</link>
      <description>These still need tweaking, but essentially I just wanted a repeatable way to draw boxes via script.  This includes the ability to add rounded corners, gradients, and drop shadows (could it really be any other way? :)  The Balloon function was to fulfill a specific goal, obviously, but since these things are more and more popular I figured it would be a good idea to have it somewhat configurable for future usage.  Right now, for drop shadows you just have to make two boxes, one blurry, one not.  Perhaps it would be better to consolidate the balloon script into the box script, but for now, this works.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import flash.filters.BlurFilter;&lt;br /&gt;dynamic class _Draw {&lt;br /&gt;	&lt;br /&gt;	static function box(targetMC,targetDepth,w,h,c,r,gradientType){&lt;br /&gt;		var targetDepth = (targetDepth != undefined &amp;&amp; targetDepth != null) ? targetDepth : targetMC.getNextHighestDepth();&lt;br /&gt;		var newBox:MovieClip = targetMC.createEmptyMovieClip("newBox", targetDepth);&lt;br /&gt;		var g:Object = new Object();&lt;br /&gt;		&lt;br /&gt;		if (c.length != undefined){&lt;br /&gt;			g = getGradientObject(w,h,gradientType);&lt;br /&gt;			newBox.beginGradientFill(g.fillType, c, g.alphas, g.ratios, g.matrix, g.spreadMethod, g.interpolationMethod, g.focalPointRatio);&lt;br /&gt;		} else {&lt;br /&gt;			newBox.beginFill(c);&lt;br /&gt;		}&lt;br /&gt;		&lt;br /&gt;		if (r == undefined) var r = 0;&lt;br /&gt;		&lt;br /&gt;		with (newBox){&lt;br /&gt;			lineStyle(0,0x000000,0);&lt;br /&gt;			moveTo(r, 0);&lt;br /&gt;			lineTo(w-r, 0);&lt;br /&gt;			curveTo(w,0,w,r);&lt;br /&gt;			lineTo(w, h-r);&lt;br /&gt;			curveTo(w,h,w-r,h);			&lt;br /&gt;			lineTo(r, h);&lt;br /&gt;			curveTo(0,h,0,h-r);&lt;br /&gt;			lineTo(0, r);&lt;br /&gt;			curveTo(0,0,r,0);&lt;br /&gt;			endFill();&lt;br /&gt;		}&lt;br /&gt;		&lt;br /&gt;		return newBox;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	static function balloon(targetMC,targetDepth,w,h,c,r,gradientType,arrowBaseOffset,arrowBaseWidth,arrowLength,arrowPointOffset){&lt;br /&gt;		var targetDepth = (targetDepth != undefined &amp;&amp; targetDepth != null) ? targetDepth : targetMC.getNextHighestDepth();&lt;br /&gt;		var newBalloon:MovieClip = targetMC.createEmptyMovieClip("newBalloon", targetDepth);&lt;br /&gt;		var g:Object = new Object();&lt;br /&gt;		&lt;br /&gt;		if (c.length != undefined){&lt;br /&gt;			g = getGradientObject(w,h,gradientType);&lt;br /&gt;			newBalloon.beginGradientFill(g.fillType, c, g.alphas, g.ratios, g.matrix, g.spreadMethod, g.interpolationMethod, g.focalPointRatio);&lt;br /&gt;		} else {&lt;br /&gt;			newBalloon.beginFill(c);&lt;br /&gt;		}&lt;br /&gt;		&lt;br /&gt;		if (r == undefined) var r = 0;&lt;br /&gt;		&lt;br /&gt;		with (newBalloon){&lt;br /&gt;			lineStyle(0,0x000000,0);&lt;br /&gt;			moveTo(r, 0);&lt;br /&gt;			lineTo(w-r, 0);&lt;br /&gt;			curveTo(w,0,w,r);&lt;br /&gt;			lineTo(w, h-r);&lt;br /&gt;			curveTo(w,h,w-r,h);&lt;br /&gt;			&lt;br /&gt;			// start arrow			&lt;br /&gt;			lineTo(r + arrowBaseOffset + arrowBaseWidth, h);&lt;br /&gt;			lineTo(r + arrowBaseOffset + (arrowBaseWidth/2) + arrowPointOffset, h + arrowLength);&lt;br /&gt;			lineTo(r + arrowBaseOffset, h);&lt;br /&gt;			// end arrow&lt;br /&gt;			&lt;br /&gt;			lineTo(r, h);&lt;br /&gt;			curveTo(0,h,0,h-r);&lt;br /&gt;			lineTo(0, r);&lt;br /&gt;			curveTo(0,0,r,0);&lt;br /&gt;			endFill();&lt;br /&gt;		}&lt;br /&gt;		&lt;br /&gt;		return newBalloon;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	static function getGradientObject(w,h,gradientType){&lt;br /&gt;		var gradientObj:Object = new Object();&lt;br /&gt;		&lt;br /&gt;		gradientObj.fillType = "linear"&lt;br /&gt;		gradientObj.alphas = [100, 100];&lt;br /&gt;		gradientObj.ratios = [0, 0xFF];&lt;br /&gt;		gradientObj.spreadMethod = "pad";&lt;br /&gt;		gradientObj.interpolationMethod = "RGB";&lt;br /&gt;		gradientObj.focalPointRatio = 1;&lt;br /&gt;		&lt;br /&gt;		if (gradientType == "vGradient") {&lt;br /&gt;			gradientObj.matrix = {a:0, b:w, c:0, d:-h, e:0, f:0, g:0,h:h/2, i:1};&lt;br /&gt;		} else {&lt;br /&gt;			gradientObj.matrix = {a:w, b:0, c:0, d:0, e:w, f:0, g:w/2, h:0, i:1};&lt;br /&gt;		}&lt;br /&gt;		&lt;br /&gt;		return gradientObj;&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	static function blur(mc,blurAmount,blurOpacity){&lt;br /&gt;		blurAmount = (blurAmount == undefined) ? 10 : blurAmount;&lt;br /&gt;		blurOpacity = (blurOpacity == undefined) ? 100 : blurOpacity;&lt;br /&gt;		var filter:BlurFilter = new BlurFilter(blurAmount, blurAmount, 2);&lt;br /&gt;		var filterArray:Array = new Array();&lt;br /&gt;		filterArray.push(filter);&lt;br /&gt;		mc.filters = filterArray;&lt;br /&gt;		mc._alpha = blurOpacity&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 13 Feb 2007 19:57:44 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3515</guid>
      <author>bgidge (Bryan Gidge)</author>
    </item>
    <item>
      <title>Actionscript _Animate Class</title>
      <link>http://snippets.dzone.com/posts/show/3514</link>
      <description>This is basically a way to set up an animation queue to utilize scripted tweening.  You would have to create external functions which carry forth the animation actions then store the function objects in the _Animate.queue Array in the sequence you wish to play them out.  Ideally, these functions would return a Tween object for the sake of utilizing "onMotionStopped".  Returning False (bool) will simply allow the next function in the queue to fire without checking for the onMotionStopped call.  When you are ready to start the animation sequence, just call launch();&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import _String;&lt;br /&gt;&lt;br /&gt;dynamic class _Animate {&lt;br /&gt;	var queue:Array;&lt;br /&gt;	&lt;br /&gt;	function _Animate() {&lt;br /&gt;		queue = null;&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	public function caller(qNum){&lt;br /&gt;		var gA = this;&lt;br /&gt;		var callback = queue[qNum].func.apply(this, _String.toArray(queue[qNum].params)); qNum++;&lt;br /&gt;		if (qNum &lt; queue.length &amp;&amp; callback) callback.onMotionStopped = function() { gA.caller(qNum); }&lt;br /&gt;		else if (qNum &lt; queue.length &amp;&amp; !callback) gA.caller(qNum);&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	public function launch(){ caller(0); }&lt;br /&gt;	&lt;br /&gt;	&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Sample Usage&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;var zoomIn = new _Animate();&lt;br /&gt;&lt;br /&gt;zoomIn.queue = [&lt;br /&gt;	{func:aniSidebar, params:"hide,6"},&lt;br /&gt;	{func:aniMapMidFade, params:"hide,6"}&lt;br /&gt;];&lt;br /&gt;&lt;br /&gt;zoomIn.launch();&lt;br /&gt;&lt;br /&gt;function aniSidebar(action, time){&lt;br /&gt;	var leftBeginX = (action == "hide") ? 0 : 0 - sidebarLeftBg._width;&lt;br /&gt;	var leftEndX = (action == "hide") ? 0 - sidebarLeftBg._width : 0;&lt;br /&gt;	var rightBeginX = (action == "hide") ? Stage.width - sidebarRightBg._width : Stage.width;&lt;br /&gt;	var rightEndX = (action == "hide") ? Stage.width : Stage.width - sidebarRightBg._width;&lt;br /&gt;	var transition = mx.transitions.easing.Regular.easeInOut;&lt;br /&gt;	var leftAni = new mx.transitions.Tween(sidebarLeftBg, "_x", transition, leftBeginX, leftEndX, time);&lt;br /&gt;	var rightAni = new mx.transitions.Tween(sidebarRightBg, "_x", transition, rightBeginX, rightEndX, time);&lt;br /&gt;	return rightAni;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function aniMapMidFade(action, time){&lt;br /&gt;	var begin = (action == "hide") ? 100 : 0;&lt;br /&gt;	var end = (action == "hide") ? 0 : 100;&lt;br /&gt;	var transition = mx.transitions.easing.Regular.easeOut;&lt;br /&gt;	var mapMidAni = new mx.transitions.Tween(mapMid, "_alpha", transition, begin, end, time);&lt;br /&gt;	return mapMidAni;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 13 Feb 2007 19:47:43 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3514</guid>
      <author>bgidge (Bryan Gidge)</author>
    </item>
  </channel>
</rss>
