How do you debug Java Applets?

Aside from the obvious use of the Java console and the applet viewer, starting from Java 6 update 7, you can use the VisualVM that comes with the JDK (JDK_HOME/bin/visualvm). It allows you to view the stack traces of each thread and even view all object instances. AppletViewer is very handy, you can do a … Read more

Embed a 3rd-party JApplet in a Swing GUI & pass it parameters

Implement an AppletStub & set it as the stub of the applet instance. E.G. /* <applet code=”ParamApplet” width=”200″ height=”200″> <param name=”param” value=”foo”> </applet> */ import java.applet.*; import javax.swing.*; import java.net.URL; import java.util.HashMap; public class ParamApplet extends JApplet { public void init() { String param = getParameter(“param”); System.out.println(“parameter: ” + param); add(new JLabel(param)); } public static … Read more

How do i align this text correctly?

Here’s a simple example of rotating text. Addendum: You’ll want to adjust the the text’s radial starting point by stringWidth(name[n]). Your program appears to be rotating individual characters in a effort to follow the arc, while the example appears to be drawing the text in a straight line tangent to the arc. The latter approach … Read more

getClassLoader().getResource() returns null

You don’t need the slash at the start when getting a resource from a ClassLoader, because there’s no idea of a “relative” part to start with. You only need it when you’re getting a resource from a Class where relative paths go from the class’s package level. In addition, you don’t want Test.class.getClass() as that … Read more

How to combine two Jar files

Sure, just extract the two jar files and recreate a new one $ mkdir tmp $ (cd tmp; unzip -uo ../jar1.jar) $ (cd tmp; unzip -uo ../jar2.jar) $ jar -cvf combined.jar -C tmp . The stuff with tmp ensures that the two existing jars are extracted into a clean directory and then the new one … Read more

Java applet manifest – Allow all Caller-Allowable-Codebase

My findings are the same: This prevents warnings with Java 7u21 – 7u40: Manifest-Version: 1.0 Trusted-Library: true This exclusivly prevents warnings with Java 7u45: Manifest-Version: 1.0 Application-Library-Allowable-Codebase: * Caller-Allowable-Codebase: * Mixing both won’t work in 7u45. Now what? Did anyone find a way to allow SIGNED applets with “all-permissions” to run without warnings in both … Read more

Embedding Java Applet into .html file

Making applets work across a wide range of browsers is surprisingly hard. The tags weren’t properly standardized in the early days, so Internet Explorer and Mozilla went separate directions. Sun developed a generic JavaScript to handle all the specific browser quirks, so that you don’t have to worry about browser compatibility. Add this to your … Read more

Java ball object doesn’t bounce off of drawn rectangles like it’s supposed to.

I finally found a edge detection system I like… Basically, the magic happens here… // Detect if we collided with any one (collision is the rectangle, bounds is us) if (collision.intersects(bounds)) { // Determine the intersect of the collision… insect = collision.intersection(bounds); // Flags… boolean vertical = false; boolean horizontal = false; boolean isLeft = … Read more