BlueJ 4 brings a bag of new features

splash-v11@2x

After concentrating on Greenfoot for some time, we have now worked on and released a significant new version of BlueJ: BlueJ version 4.0.

The most exciting new feature for me is the addition of Stride. (I will say a few more words about that in a moment.) But independent of Stride, there are a number of other bits of new functionality that are worth mentioning. These include the addition of Git support, support for writing and running JavaFX applications, a rewrite of a large part of the user interface in JavaFX, a tabbed editor, a fundamental redesign of error reporting, support for HiDPI displays and numerous smaller improvements.

While we were at it, we have also removed some bits that – for various reasons – do not seem worth supporting anymore. These are support for CVS, JavaME and Applets. A bit more about this below as well.

Let’s go through the main features in a little more detail, and I can tell you what we have done and why we have done it.

Git support

[Git logo]People have asked us for support for Git for quite some time. This is not surprising: Git has become the most popular version control system for some years now, and even though Subversion is often good enough for educational situations with small projects, publicly available, free Subversion repositories have disappeared quickly over the last few years. Simultaneously, free Git repositories – such as GitHub – are flourishing. So we have now moved with the times: We have removed support for CVS (which was always a bit terrible) and added Git support. We still support Subversion, as before.

Git, however, has a somewhat different model of work. We have not fully exploited that yet. As before with Subversion, we support only a subset of its functionality. Version control systems offer help in two distinct areas: One is, well, version control (which allows version rollback, etc), and the other is teamwork (which allows integrating code from multiple developers). While they are often used together, they each also make sense on their own: A single developer might use version control, or a team might use team integration tools without version rollback.

So far, we have always only supported the team work aspects of the source control systems. With Subversion in BlueJ, you can update and commit, but not branch or roll back to prior version. Currently, our Git implementation mirrors this and supports the same functionality.

Git, however, can be used somewhat differently. Since it is a distributed source control systems, it makes much more sense to want to use Git with a local repository, just for backup and version rollback. We are currently investigating whether we modify and extend our Git support to offer something like this as well.

At the moment, BlueJ offers a nice, simple and functional interface for Git – ideal to start learning about source control – just as it did for Subversion. (If you want to try it, some setup and use information is here.)

Support for JavaFX

Javafx_logo_colorJavaFX is the new Java GUI toolkit. AWT has been out for many years, Swing has thoroughly replaced it long ago and has been the GUI toolkit for everything Java for the last 15 years or so. Yet now, Swing itself is on the way out.

JavaFX has much better support for modern GUI design, from styling over visual effects to animations. It has taken a few years, but JavaFX has now become good enough that it is ready to replace Swing for all modern new development work. Oracle has said that they will no longer develop Swing. The future is FX.

Running JavaFX in BlueJ has been almost impossible, since its invocation differs from normal method calls. (Well, there were some tricks one could use if one knew enough of the internal workings, but it was really not straightforward.)

Now, if you write a JavaFX main class (by inheriting from JavaFX’s Application class), you will automatically get a ‘Run JavaFX Application’ option in your class menu. That’s it – use it, and all is well.

But it gets even better: If you have used JavaFX, you will know that it makes use of CSS files for styling. And you can now create and edit CSS files (which are plain text files) straight from within BlueJ!

BlueJ interfaceInterface rewrite

We did not only support JavaFX for BlueJ users, we also started to rewrite BlueJ’s own user interface in JavaFX. There were a number of reasons for it: Firstly, the Stride editor could not have been written without JavaFX. It has a much more modern, dynamic interface than our old Java editor. Secondly, we were receiving an increasing number of bug reports from users with HiDPI displays. Swing does not always cope well with this. And finally, making use of some of FX’s features, such as the ease of creating animations, allowed us to make some aspects of the interface nicer.

All is not well, though. Not the whole interface has been rewritten yet, and some parts are very difficult to rewrite, for technical reasons. Thus, BlueJ currently uses a mix of Swing and JavaFX for its interface – a fact that itself creates some problems. Incorrect display on HiDPI screens, for example, while reduced, is not completely gone.

We are still working on that. JDK 9, when it comes out later this year, will help, and we are still doing what we can with JDK 8 until then.

The new editor, or: Tabs, finally

The BlueJ editor now has tabs! Some users have asked for this for the last 10 years, while others liked the multi-window model. The world has decisively moved to tabs for most applications, though, and this is now the model that most users are familiar and comfortable with.

Having your code in tabs, instead of windows, has, however, one drawback: You cannot show code side-by-side. To retain that option, we have added functionality, available by right-clicking the tab rider, to move any tab to a different window. This way, code still can be displayed side-by-side, for easy comparison.

Improved error reporting

ErrorsFor many years – in fact, since its creation in 1999 – BlueJ has reported one error at a time: When the Compile button was pressed, BlueJ highlighted the first error and stopped for you to fix it.

This has now changed in three ways: Firstly, all errors are displayed at the same time. Secondly, the errors are marked in the source code with a squiggly red underline (and the error message is displayed near the error when you click on it or the mouse hovers over it), and thirdly, the error checking happens automatically as you type. This way, errors are marked as you make them, for you to come back to at any time of your choosing to fix them.

Stride – A new language

windowThe most substantial new feature in BlueJ 4 is the addition of Stride as a new supported language. Stride was first developed and published as part of Greenfoot, and has been in use there for about a year. It has met with substantial interest since its publication and we received regular requests to include it in BlueJ.

So here it is.

So, what actually is Stride? Stride is a very Java-like language that differs mostly in its frame-based editor. This editor offers new program entry and manipulation interactions that try to get the best out of block-based and text-based editing. Not by displaying the two modes side-by-side, as some other systems do, but at the same time.

I will not talk about it much in this post (but instead introduce it more fully in a future article), but if you are curious, there are some sources where you can have a look: This page briefly describes frame-based editing, and there is a short series of videos demonstrating how to use it. Don’t worry that the videos make use of Greenfoot rather than BlueJ – the language is the same.

The Stride implementation in BlueJ has been significantly improved since publication in Greenfoot. The performance and functionality of the editor is better – progress that will also make it into the next Greenfoot release.

I will write more about Stride in BlueJ later. For now, just note that you can now write in Stride in addition to writing in Java. If you are a teacher, especially at school level, this has the potential to substantially change how you introduce programming.

Spring clean: What’s out

We always try to keep BlueJ small and simple, at least in its appearance, functionality and interface. If we continually add things, this gets very hard. Thus, sometimes things should go out as well.

We have taken the opportunity of this new release to throw out a few things that are getting old and are not much used anymore. These are support for applets, CVS and JavaME. I know that there are still a few people using some of this. Some teachers, for example, use applets as an introductory framework. To those teachers – sorry. But these are dying technologies, and you should move on. JavaFX, for example, provides a much nicer alternative to applets for those who want to start with a graphical framework. CVS – once the most used version control system – has been superseded first by Subversion, and now by Git, and JavaME – well, what is there to say.

Miscellaneous other aspects

A couple of assorted other issues may be worth mentioning:

  • The JDK is now bundled with the BlueJ download on Windows and MacOS. This makes downloading and installing easier (since you don’t need two separate, dependent downloads) and ensures that BlueJ always runs with a Java version that it has been tested on, and we know it works. It will no longer be broken by running with an incompatible JDK.
  • BlueJ 4 does not currently work on the Raspberry Pi. This is because JavaFX is not available on the Pi at the moment. BlueJ 3.1.7 continues to be available in the Raspberry Pi image.

Try it!

So, if this sounds interesting, download BlueJ now and try it out! If you are a teacher, join us in the Blueroom for more discussion about use and pedagogy.

Let me know in the comments what you think of it, what questions you have, and what aspects you would like me to write more about.

You can Save The World

Earlier today I wrote about the new Greenfoot features. I forgot one: Saving the world.

In previous editions of Greenfoot, there was one annoying aspect: every time you had to recompile your classes, your interactively created objects disappeared. (This was not a bug: it is necessary, because the class implementing these objects does not exist anymore.)

This could be overcome by writing an initialiser method in the world class that creates and inserts all the objects you want to have in the world. This solves the problems, since objects get recreated automatically. However, writing these initialiser methods can be tedious.

So we come to the rescue: Saving the World.

You can now insert the objects you initially want in the world interactively, and then save the visible state of the world as the starting state of your program. Let’s look at an example.

Let us assume I want a scenario where the initial objects at the start of the game are a hamburger and three pigs. (Don’t ask). Let us further assume that I have just created the pigs and the hamburger interactively and placed them into my world. Figure 1 shows my world at this stage.

Figure 1: Three pigs and a hamburger

This is all well so far – with the problem that the actors will disappear (and I have to manually recreate them) after every compile.

Enter Save the World.

In Greenfoot 2.0, I can now select Save the World from the world context menu (Figure 2).

Figure 2: Saving the world

When I choose this function, Greenfoot writes the source code for a method called “prepare” into the class of the world object. This method contains code to create and insert objects just as they are in the world, and a call to this method from the world constructor (Figure 3).

Figure 3: The generated 'prepare' method

The effect is that next time, when I recompile my class and the world is re-created, the objects in the world are re-created as well. The status of the world is saved.

There are a few characteristics worth noting about this mechanism:

  • We consciously chose to create source code (rather than, say, serialising the world objects) because it can serve as a good learning instrument. Students can study the generated code and learn from it.
  • The source code of the automatically generated ‘prepare’ method may be freely edited by hand. There is not much special about this method, and you are welcome to adapt it in the editor in any way you feel like.
  • When the world was already saved, and you save it again, the prepare method will be adapted appropriately.
  • The prepare method will include code to recreate exactly what you did to construct the world. For example, if you create and place an object, and then move it, the prepare method will add the object at first at the same position where you first added it, and then move it. This is necessary, because the sequence may have had side effects. If you are only interested in the final position, you can streamline the prepare method manually by editing it (and taking out any unnecessary calls).
  • After the scenario has run, the world cannot be saved anymore.

(All screenshots in this post are produced by the author and are hereby placed in the public domain.)

Greenfoot 2.0 – The new features

Yes! It’s here! It’s out!

Greenfoot 2.0 has just been released. After a lot of hard work, and about a month behind schedule, we finally completed the work on Greenfoot 2.0. Even though it may not be immediately obvious, this is one of the largest updates we have ever produced for Greenfoot. A lot of work has been done internally, and users will discover the effects of many of them over time.

Greenfoot splash screen

The Greenfoot 2.0 splash screen

New features are available in the editor, for processing and recording sound, for editing images, debugging your programs, and more. Here, I will summarise the most interesting changes (at least those that users can directly see – there are many internal improvements to performance and stability that I won’t discuss here).

The first thing users will notice after upgrading is a new splash screen. (Yes, we are now supported by the good folks at Oracle, instead of Sun Microsystems, after Sun was swallowed up by Oracle.)

But after that, it all might look rather underwhelming at first. The Greenfoot main window looks pretty much as it used to look before. “Where’s the new stuff?”, I hear you ask. Sharp-eyed users may notice one small change: the world name, that used to be shown above the world in the main window, is not there anymore.

The name of the world used to serve as a placeholder to represent the world object itself. It had a right-click functionality, that let you access the world object’s context menu to invoke instance methods on the world object itself. The problem was that this functionality was quite hidden, and many users never discovered it. It was bad UI design, since nothing in the name indicated that this was clickable. It had, in fact, almost easter egg-like quality.

We have now removed this name, and instead made the whole world area right-clickable. Right-clicking the world itself (or indeed the grey background behind it) will show the world object context menu and lets you invoke the world methods.

main window

The main window

Right-clicking in the world itself is more natural (more conforming to user expectations and more discoverable) and we expect that users will find this menu more easily now. (By the way, the reason that this was not done like this in the first place is that early versions of Greenfoot had different functionality attached to mouse clicks in the world.)

The next thing many users will discover is the new look of the editor.

The new editor

Greenfoot now incorporates the same editor that is used in BlueJ since the BlueJ 3.0 release earlier this year. The new features include scope highlighting, a new navigation view, better Find and Replace and code completion. (Code completion is activated by pressing Ctrl-Space.) I have described these features in more detail in an earlier blog post, when they came out with BlueJ – read them there if you want to know more..

greenfoot editor

The new Greenfoot editor

We expect that the new editor, especially the availability of code completion for Greenfoot API calls, will be a substantial improvement to the user experience. (I have been using it for a few months now, and I wouldn’t want to work without it anymore!)

Sound recording

sound recorder

The sound recorder

Greenfoot now has a built-in sound recorder. It can be found in the Controls menu, and you can now record your sounds directly from within Greenfoot. The functionality is very simple — just recording and trimming is supported — but this is what you need most of the time. If you want more sophisticated sound editing, you can still use third party applications (such as Audacity). However, the built-in recorder should be sufficient in many cases.

There is unfortunately a Java bug that cases problems with sound recording on some USB connected microphones. It works, however, with most microphones, and we hope that the remaining problems will be fixed in a future Java update.

But sound recording is not all that’s new with sound. You now also have more control over sound playback.

MP3 support

Yes, mp3 support! Greenfoot can now play mp3 files! Really. So go on and write your first MP3 player.

The GreenfootSound class

In previous Greenfoot versions, programmers had little control over how sounds are played. They could be started, but that’s all. Now, Greenfoot has a new class called GreenfootSound. It has method for starting, stopping and pausing sounds, as well as looping. This makes working with sounds much more flexible.

For short, simple sounds (such as sound effects), the Greenfoot.playSound(…) method is still the best to be used. But if you need more sophisticated functionality, create a GreenfootSound object and you can control the sound in more detail.

The debugger

Greenfoot now has a debugger built in. As some of you had discovered before, the code for the debugger has been there under the hood for some time (and there were ways to make it come up), but it was not working well, not supported, not finished, and had no proper interface.

debugger window

The Greenfoot debugger

Now you can open the debugger window from the menu, set breakpoints, stop the execution, single step through your programs and monitor your variable values. Especially for illustrating the working of control structures, this should be a useful help.

Image editing

Creating or editing images is a task that is very often part of developing Greenfoot scenarios. Now you can start creating or editing images directly from within the Greenfoot image dialogue.

image editing

Editing images

The action menu under the image list offers functions to edit, delete or create an image. This will happen in external applications. By default, Greenfoot will open the default application for the chosen file type on any platform. This behaviour can also be configured to select a specific application. (I will write in more detail about some of these new functions in separate posts soon – I’ll discuss how to do this then.)

When images are created, they are automatically placed into the scenario’s images folder, so that they are immediately available for use in Greenfoot.

Unbounded worlds

The last bit of functionality I’ll talk about today are unbounded worlds.

As you know (if you have used Greenfoot in the past), actors cannot leave the world. When they try to move beyond world boundaries they are simply placed at the edge of the world. Breaking out is impossible for them. This has good reason: if actors were to leave the visible world, it can be very hard to get them back. You cannot interact with them anymore, and you don’t really know where they are. In fact, you may not even be aware that they are still there. This has great potential of confusion and difficulty for beginners.

This behaviour remains the default in Greenfoot 2.0 — but you can now configure your world to allow actors to leave the visible area for specific scenarios, should you want to do that. (And we know that some of you do: many of you have asked for this for some time!)

The world is then essentially infinite in all directions, and the visible world in the Greenfoot window is just a viewport into a small part of this eternal universe.

The World superclass now has a second constructor that allows the bounds to be removed:

Constructor Summary
World(int worldWidth, int worldHeight, int cellSize)
Construct a new world.
World(int worldWidth, int worldHeight, int cellSize, boolean bounded)
Construct a new world.

The first constructor is as before. Thus, you old code will work unchanged. For example, a world constructor

public AntWorld()
{
    super(500, 400, 1);
}

will work as before and create the usual bounded world. However, you can now also use

public AntWorld()
{
    super(500, 400, 1, false);
}

In this case, actors will be allowed to leave the visible world and walk as far away as they like. For some type of games this will be very useful. When out of the visible world, they will still act, cause collisions, etc. You just cannot see them.

And so…

So, plenty of new stuff in Greenfoot 2. The last thing to tell you is where to get it. And that is, of course, where it has always been: www.greenfoot.org.

Install it, take it for a spin, and let us know what you think. We’d love to get your feedback. Bug reports, of course, but also things you like. You comments are one of the inputs that drive our future development.

And most of all, as always: Have fun programming!

Update:

I forgot to mention one new feature: Saving the world. I have now described this in a separate blog post.