Whoa. Time-out! I just looked through the code, and there’s some serious optimizing that can be done:
-
Replace the three parameter constructors of Color (i.e. new Color(240, 160, 0)) with the Hex equivalents (e.g. new Color(0xF0A000)).
-
Move as many of those static entries into the main method as possible! You don’t pay extra for method variables (they’re all on the stack), but you do pay for fields and methods!
-
Get rid of unnecessary class references. Being able to use “Point” is nice, but for what it costs, you should stick to a 2D array.
-
Nice fonts are, well, nice, but configuring them costs some serious class space. Ditch 'em and use whatever the default is.
-
Move all that INT data to a file. I know you think you’re saving space by using an embedded array, but what you’re actually doing is generating a constant pool entry plus a stack push operation for each array item! If you want to embed the data, encode it as a string and decode it at runtime.
-
This:
JPanel panel = (JPanel) container.getContentPane();
panel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
panel.setLayout(null);
// setup our canvas size and put it into the content of the frame
setBounds(0, 0, WIDTH, HEIGHT);
panel.add(this);
// Tell AWT not to bother repainting our canvas since we're
// going to do that our self in accelerated mode
setIgnoreRepaint(true);
// finally make the window visible
container.pack();
container.setResizable(false);
container.setVisible(true);
Can be more succinctly stated as:
JPanel panel = (JPanel) container.getContentPane();
// setup our canvas size and put it into the content of the frame
setBounds(0, 0, WIDTH, HEIGHT);
panel.add(this);
// Tell AWT not to bother repainting our canvas since we're
// going to do that our self in accelerated mode
setIgnoreRepaint(true);
// finally make the window visible
container.setResizable(false);
container.setVisible(true);
- Inline those methods!
In short, you’ve got a lots of opportunities to fit this in 4K.