HTML Formatting

I wrote a little groovy app a while ago to help me format code snips for my blog and it was ok. This morning I was reading another blog that linked to mine and asked a familiar question, “How do you embed code in your blog?” Now I get to searching for some of the Java components referenced on that blog and I see something that promises to be better. Running it against Groovy-Invaders source the results look like this:

package com.craig.groovyinvaders

import javax.swing.*
import java.awt.Canvas
import java.awt.Color
import java.awt.Dimension

public class Game extends Canvas
    def strategy
    def lastLoopTime = System.currentTimeMillis()
    def gameRunning = true
    def entities = []
    def ship
    def alienCount = 0
    def GAME_DELAY = 10

    public Game()
        def container = new groovy.swing.SwingBuilder().frame(title:"Groovy Space Invaders",
        def panel = container.getContentPane()
        panel.setPreferredSize new Dimension(800, 600)
        panel.setLayout null
        setBounds 0, 0, 800, 600

        setIgnoreRepaint true
        container.setResizable false
        container.setVisible true

        createBufferStrategy 2
        strategy = getBufferStrategy()

    private void initEntities()
        // create the player ship and place it roughly in the center of the screen
        ship = new ShipEntity(this,"sprites/ship.gif",370,550)

        def game = this
        // create a block of aliens (5 rows, by 12 aliens, spaced evenly)
        5.times { row ->
            12.times { col ->
                Entity alien = new AlienEntity(game,

	public Game gameLoop()
	        def elapsedTime = calculateElapsedTime()
	        display( moveSprites(elapsedTime,draw()) )

	    return this

	def calculateElapsedTime()
	    try{ return System.currentTimeMillis() - lastLoopTime }
	    finally { lastLoopTime = System.currentTimeMillis() }

	def processInput() {}

	def moveSprites(def elapsedTime, def g)
	    entities.each { it.move(elapsedTime) }
	    entities.each { it.draw(g) }
	    return g

	def draw()
	    def g = strategy.getDrawGraphics()
	    g.fillRect 0, 0, 800, 600
	    return g

	def display(def graphics)

	def delay()
	    try { Thread.sleep GAME_DELAY }
	    catch(Exception e) { println e.getMessage() }

	public static void main(String[] args)
	    def g = new Game()

No different from what I have been using. The problem here is wordpress. They remove style attributes from the posted HTML and it’s more annoying than what I care for. I read recently they offered a theme that gives you complete control over CSS. I installed it but couldn’t find the customization option. Maybe I’ll give it a go again later.

3 thoughts on “HTML Formatting

  1. I am also using an old version (1.2.1) of wordpress – I have therefore modified
    my index.php to include the style defined by jHighlight and it works fine … while waiting for my provider to upgrade WordPress 😉

  2. I don’t get it. All I want is for my code to be formatted appropriately. Few of the provided styles work well with source code. Also, it’s become apparent that coloring is removed along with many other HTML attributes on a post. I feel limited in what I can do. Overall it’s a good place to host a blog but formatting is very limiting.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s