Over a million developers have joined DZone.

5 Steps to Lightweight Java Game Library in NetBeans RCP

· Java Zone

Learn more about the advantages of moving from a monolithic to microservices architecture.  Brought to you in partnership with IBM.

Let's get started with LWJGL in a window in a NetBeans Platform application. In the end, we'll have this simple canvas that I found somewhere on-line, in a TopComponent (in real life, the white shape is moving):

  1. Start by setting things up as described here, i.e., in a standard Java SE application in NetBeans IDE. Use those instructions as a simple environment where you can try out things outside the NetBeans Platform.

  2. Create a new NetBeans Platform application.

  3. Create a new module, call it "LWJGLCore", or anything else you like. In the Properties dialog of the module, go to Libraries and then "Wrapped JARs". Now wrap the JARs mentioned in the link in step 1 into your module. Switch to the Files window of the module in NetBeans IDE and the folder "release/modules/ext" should contain the three modules you wrapped. Create a new folder, "lib", and put the native JARs into it, i.e., look below at the screenshot and do not continue with the next step until your module has the folder and file structure that you see below.

  4. Now create this new class in your module. Note that I have no idea whether the code below is correct or optimal, it's simply here to show a simple class you can use to check whether your set up is working:
    public class GameLoop extends AWTGLCanvas {
        float angle = 0;
        public GameLoop() throws LWJGLException {
            Thread redraw = new Thread() {
                public void run() {
                    while (true) {
                        if (isVisible()) {
        protected void paintGL() {
            GL11.glOrtho(0, 640, 0, 480, 1, -1);
            GL11.glTranslatef(320, 240, 0.0f);
            GL11.glRotatef(angle, 0, 0, 1.0f);
            GL11.glVertex2i(-50, -50);
            GL11.glVertex2i(50, -50);
            GL11.glVertex2i(50, 50);
            GL11.glVertex2i(-50, 50);
            angle += 1;
            try {
            } catch (Exception e) {

  5. Add another class that defines the TopComponent and adds the canvas defined above to it:
    import java.awt.BorderLayout;
    import java.awt.Canvas;
    import org.openide.windows.TopComponent;
    @TopComponent.Description(preferredID = "LWJGLWindow")
    @TopComponent.Registration(mode = "editor", openAtStartup = true)
    public class LWJGLWindow extends TopComponent {
        public LWJGLWindow() {
            setLayout(new BorderLayout());
            try {
                Canvas can = new GameLoop();
                can.setSize(getWidth(), getHeight());
            } catch (Exception ex) {

Run the application and you'll see the same as shown in the screenshot with which this article started.


From Idea to Application gives you the architecture to quickly build, manage and run a range of applications (web, mobile, big data, new smart devices, etc.) on an open-standard, cloud-based platform. See why developers are using IBM Bluemix. Brought to you in partnership with IBM.


The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}