Buttons and controls for our arcade cabinet

29 08 2008

And there let be buttons… :mrgreen:

Like I already said in my previous post, I ordered all the buttons, joysticks and electronics at Ultimarc.

The buttons and joysticks are controlled by an IPAC interface, that we can connect to a PS/2 or USB port of our motherboard:

I am going to use some spare parts I have from my old desktop PC to build the CPU.

This is the motherboard (MSI K8N Diamond Plus), with RAM (2GB Crucial Ballistix) and processor (AMD X2 4200) already mounted:

The hard disk drive. Segate Barracuda, 320 GB for loads of ROMs!! :D

The video card. I think this NVIDIA Geforce 7900GT is enough for my purposes:

Some wires and connectors to setup the IPAC and the buttons:

The joysticks. I have chosen the E-Stick model because it’s easier to mount:

This little thing is the switch itself. It is mounted in the base of every button. We use the connectors shown below to plug it to the IPAC:

I am pretty sure you know what are this buttons for… ;)

Well, now begins the hard part: designing and building the cabinet itself from wood panels…




Netbeans file templates

28 08 2008

You may have seen that when you create a new class, interface or something with Netbeans, the IDE automatically generates some code for you.

It is possible to customize this code using the Netbeans File Templates.

Under the “Tools” menu there is an option called “Templates”. This dialog let you create and edit every template used in the IDE. Just click on the “Open on Editor” button to edit the desired template inside Netbeans.

Let’s see how the Java/Class template looks like:

<#assign licenseFirst = "/*">
<#assign licensePrefix = " * ">
<#assign licenseLast = " */">
<#include "../Licenses/license-${project.license}.txt">

<#if package?? && package != "">
package ${package};

</#if>
/**
*
* @author ${user}
*/
public class ${name} {

}

If you edit this file and save it, the IDE will be using your new template for every new Java class you create.

Since Netbeans 6.0 you can use the FreeMarker template language in your file templates. This way you can add logic to the templates via directives such as if/elseif/else and loop constructs.

You can also use some predefined variables:

  • ${date} — Inserts the current date, in this format: Feb 16, 2008
  • ${encoding} — Inserts the default encoding, such as: UTF-8
  • ${name} — Inserts the name of the file.
  • ${nameAndExt} — Inserts the name of the file, together with its extension.
  • ${package} — Inserts the name of the package where the file is created.
  • ${time} — Inserts the current time, in this format: 7:37:58 PM
  • ${user} — Inserts the user name.

This is an example of a modified file template for Java classes:

////////////////////////////////////////////////
/// File: ${nameAndExt}
/// Created: ${date}  ${time}
/// Encoding: ${encoding}
////////////////////////////////////////////////

<#assign licenseFirst = "/*">
<#assign licensePrefix = " * ">
<#assign licenseLast = " */">
<#include "../Licenses/license-${project.license}.txt">

<#if package?? && != "">
package ${package};

</#if>
/**
*
* @author ${user}
*/
public class ${name} {

}



Java & Netbeans: Overriding paint to customize GUI components

26 08 2008

I found that it’s somewhat tricky to override GUI components methods with Netbeans, because the IDE automatically generates the code needed for the component, and that code cannot be edited (it’s grayed out).

But there is a property, in the “Code” tab of the component properties called “Custom Creation Code”, that let us insert the creation code we need for that component.

For example. Create a new desktop application project and, using the design view, drop a new JPanel inside the main panel. If you inspect the source code that Netbeans has generated, you can see the declaration:

private javax.swing.JPanel jPanel1;

And the initialization for that JPanel:

jPanel1 = new javax.swing.JPanel();

Note that the code after the “=” is called “Creation Code”.

Now, open the properties menu of the JPanel you have just dropped before and click on the “code” tab. Click on the “Custom Creation Code” property.

This property allow us to insert whatever code we need for the creation of the component.

Today we just want to override paint() so we insert this code:

new javax.swing.JPanel()
{
    public void paint(Graphics g)
    {
        super.paint(g);
        ourCustomPaintingMethod(g);
    }
};

If you check the generated code again you can see that Netbeans has changed the creation code:

jPanel1 = new javax.swing.JPanel()
{
    public void paint(Graphics g)
    {
        super.paint(g);
        ourCustomPaintingMethod(g);
    }
};

This way we can override any GUI component method we want ;)