Over a million developers have joined DZone.

NetBeans External Execution of ZX Spectrum Emulator on Ubuntu

· Java Zone

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

A very good day for me yesterday. I discovered this link:

http://www.64bitjungle.com/ubuntu/sinclair-zx-spectrum-48k-on-ubuntu-64-bit/

It turns out that a simple "sudo apt-get" gets you a ZX Spectrum emulator! With a world of games. Hello "Chuckie Egg"! Hello "Daley Thompson's Decathlon"! Old friends. Old, old friends!

Before I knew it, I had some very simple integration with the NetBeans Platform, such that I could launch the command line tool. Then I had access to the emulator, as well as the keyboard while working in NetBeans IDE:

And see? I was also able to load my games, from the IDE's Output window. (Not the ideal user interface, of course, but fun anyway.) Then I ended up being back at school, playing "Skool Daze" and getting punished for sitting on the floor, punching my fellow students, and skipping class:

It was, above everything else, a chance to try out a new NetBeans API that will be part of the next release, the External Execution API, which its author, Petr Hejl, has blogged about very well here and here.

FYI, here's the code of my integration, i.e., a simple action that invokes my ZX Spectrum emulator and lets me type in the Output window:

package org.zx.spectrum;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import org.netbeans.api.extexecution.ExecutionDescriptor;
import org.netbeans.api.extexecution.ExecutionService;
import org.netbeans.api.extexecution.ExternalProcessBuilder;
import org.netbeans.api.options.OptionsDisplayer;
import org.openide.util.Exceptions;
import org.openide.util.RequestProcessor;

public final class ZXSpectrumAction implements ActionListener, Runnable {

    @Override
    public void actionPerformed(ActionEvent e) {
        RequestProcessor.getDefault().post(this);
    }

    public Integer execute() {
        try {
            ExecutionDescriptor descriptor = new ExecutionDescriptor().
                    optionsPath(OptionsDisplayer.ADVANCED + "/org-zx-spectrum-ZXSpectrumGamesAdvancedOption").
                    inputVisible(true).
                    controllable(true);
            ExecutionService executionService = ExecutionService.newService(new ExternalProcessBuilder("xspect"), descriptor, "xspect command");
            Future<Integer> task = executionService.run();
            return task.get();
        } catch (InterruptedException ex) {
            Exceptions.printStackTrace(ex);
        } catch (ExecutionException ex) {
            Exceptions.printStackTrace(ex);
        }
        return null;
    }

    @Override
    public void run() {
        execute();
    }
    
}

Maybe not the best code, but good enough for me to play my favorite games with. Would be awesome of course if I could grab those dialogs and integrate them as TopComponents into the IDE. But I doubt that that is possible, I certainly spent some time trying to find a way of doing so.

 

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
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.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}