bluej-logo BlueJ
Search the BlueJ site

 
 
home
about BlueJ
download
documentation
extensions
help & Info
resources

The Tip of the Week Archive

Tip 1: Changing the interface language
Tip 2: Using auto-indent in the text editor
Tip 3: Using a local copy of the Java documentation
Tip 4: Configuring BlueJ
Tip 5: Using Custom Class Libraries
Tip 6: Using Objects from Standard Library Classes
Tip 7: Creating (executable) Jar files
Tip 8: TABs in Java source files: hard or soft?
Tip 9: Passing "command line" arguments to main
Tip 10: Accessing resources in a safe way (or: "Why can't BlueJ find my file?")
Tip 11: Extending the Help menu
Tip 12: Configuration on MacOS X
Tip 13: Top-of-screen menubar on MacOS X
Tip 14: Changing the default class template
Tip 15: Changing class templates on the fly
Tip 16: Stand-out comments
Tip 17: Clearing the terminal
Tip 18: Saving Objects
Tip 19: Operations on a group of classes
Tip 20: Making the editor open in "interface" view by default
Tip 21: Debugging an Applet
Tip 22: Using BlueJ to develop BlueJ extensions
Tip 23: Easily send BlueJ projects via e-mail
Tip 24: Running BlueJ from a USB (thumb) drive
Tip 25: Adding Google search of Java API to BlueJ help menu
Tip 26: Modifying installation options (including Windows Silent Installation)


Tip 1: Changing the interface language

Updated 2007-02-08: Many new languages available.

The BlueJ interface (that is: menus, texts on button, dialogues) is, by default, in English. If you are, like me, not a native English speaker, then you might prefer a different interface language.

Changing the language in BlueJ is relatively simple. Currently, language settings exist for Afrikaans, Catalan, Chinese, Czech, Dutch, French, German, Greek, Italian, Japanese, Korean, Portugese, Spanish and Swedish (as well as the default English). As part of this tip, I will discuss two things: Firstly, how to change the language to another existing setting, and secondly, how to make a setting for another language.

 

Using an existing setting

If you want to change the interface to one of the languages listed above, you're lucky. Settings for these languages exist. It is just a matter of "switching them on". You can switch the language by editing the BlueJ definitions file.

The BlueJ definitions file is at

    <bluej_dir>/lib/bluej.defs

That is: It is a file called bluej.defs inside the directory lib inside the BlueJ installation directory. You can edit this file with any normal text editor.

The BlueJ definitions file contains properties in the form

    property_name=value

Find the property named "bluej.language" and set the value to the name of the language you want. For example:

    bluej.language=german

That's it. Restart BlueJ, enjoy!

 

Making a new language setting

For other languages, it is not that easy. All labels, menus and dialogues have to be translated. We are looking for volunteers to do that. Here is how:

In the lib directory, you will find subdirectories named "english", "german" and "swedish". These contain all the language dependent texts. Create a new directory for the language you want. Let's say you want to make a language setting for Islandic. In that case, make a directory named "islandic". Then copy all the files out of one of the other language directories into your new language directory. They are all text files.

Edit each of those files and translate all the texts in them to Islandic (keeping the format of the files as it is). Once you have done that, you can switch the Islandic language setting on as described above, using the property setting

    bluej.language=islandic

If you do this, we would be very grateful if you would send us your language files for inclusion into the BlueJ distribution. Someone out there might just be looking for an Islandic language setting... Thanks!

 

Tip 2: Using auto-indent in the text editor

Note: this tip is out-of-date. Auto-indentation in the editor is now enabled by default.

Many people like auto-indentation in their text editor. The BlueJ editor, simple as it is, can do something like this.

Note that the auto-indentation that it will do is not a Java specific, sytax directed indentation - it simply indents every line as the line above.

So, here is how:

The BlueJ editor provides a list of editor functions with flexible key bindings. Select the "Key Bindings..." item from the "Options" menu to see the list.

Have a look at the functions in the "Edit Functions" category. You will see that there are, amongst others, the following functions and key bindings:

    KEY          FUNCTION
    ------------------------------------
    Tab:         insert-tab
    Enter:       insert-break
    Shift-Tab:   indent
    Shift-Enter: insert-break-and-indent

Using indent and insert-break-and-indent instead of insert-tab and insert-break basically provides auto-indentation functionality. That means that using Shift-Enter at the end of the line and Shift-Tab to indent will give you auto-indentation.

You can now change your key bindings to make this the default behaviour. Use the Key Bindings dialogue to change the bindings so that Enter is bound to insert-break-and-indent and Tab is bound to indent. You can bind insert-tab and insert-break to Shift-Enter and Shift-Tab. This should give you simple auto-indent behaviour.

 

Tip 3: Using a local copy of the Java documentation

BlueJ has a menu item named "Java Class Libraries..." in the Help menu. Selecting this function opens a web browser and displays the API for the standard Java classes - an essential tool for writing Java applications.

By default, the web address points to Sun Microsystem's web site, where the online version of this documentation lives.

It may be a good idea to install a local copy of the documentation on a local machine. This will speed things up, reduce network traffic and, if it is on your own machine, allow you to browse the documentation while you are offline.

To use a local copy of the documentation do the following:

  1. Download the documentation in HTML format from Sun. You can find the download at http://java.sun.com/j2se/1.3/docs.html. Unpack it on a disk on your machine or a local network.
  2. In BlueJ, select "Preferences..." from the Tools menu. You will see a field labelled "JDK documentation URL". Here, you need to put the URL of your local copy of the documentation. The easiest way to do this is to start your web browser, open the local documentation (by choosing "Open File...", typing the URL or something similar) and then copy and paste the URL from the browser into the BlueJ preferences field.

You're done. That's it. From now on, the documentation will be loded from your local copy.

 

Tip 4: Configuring BlueJ

Updated 2008-01-08: Mention bluej.properties file

Some of BlueJ's appearance and behavior can be configured. There are two sets of configurations: those that are intended to be done by an individual user can be done through the Tools - Preferences menu option.

More interesting are the settings intended to be done by the administrator. These configurations are done by editing a configuration text file.

The configuration file is

<bluej_home>/lib/bluej.defs

(Or, under Mac OS X, see tip 12). Search for this file and open it in any text editor. Read through it. You will find a list of properties with comments. You can change these properties for your needs. Some of the settings defined in this file are

  • the interface language
  • the location of the documentation
  • the default web browser
  • fonts
  • colours

If you are on a multi-user system and you want to change any of these setting for an individual user only, you can do that. Each user has a directory/folder which contains a file called "bluej.properties" which contains individual settings. This directory is normally in the user's home directory and is named "bluej" on Windows, and ".bluej" on Unix (if you want to know the precise location, check the "About" dialog from within BlueJ. The folder containing the debug log also contains the bluej.properties file).

Any of the properties from the "bluej.defs" file can be copied into the "bluej.properties" file - it will then override the setting from the "bluej.defs" file. Also, settings in the "bluej.properties" file will not be lost when you upgrade to a newer version of BlueJ.

 

Tip 5: Using Custom Class Libraries

Sometimes, you may want to make your own libraries generally available in the same style as the Java standard libraries. For example, you may have your own package called "simpleIO" that you want to use. Then you may want to be able to write

import simpleIO.*;

without the need to copy all the simpleIO classes into every project.

There are actually three ways of doing this in BlueJ.

The first way is via the "Preferences" dialog. Open the "Preferences" dialogue and select the "Libraries" tab. Then add the location where your classes are as a library path. Restart BlueJ - done. The selected libraries will now be available in all projects that you open.

One small thing to look out for: if the classes are in a jar file, select the jar file itself as the library. If your classes are in a named package directory structure (for example in a directory named "simpleIO"), choose the directory that contains simpleIO (not the simpleIO directory itself) as the library!

The second way is via the "userlib" directory, found at <bluej-dir>/lib/userlib (that is, inside the "lib" folder which is itself found inside the folder in which BlueJ was installed). Any libraries placed in this directory will be loaded by BlueJ. This is intended to be a "system wide" method to use custom class libraries as it will apply to all users using the same installed copy of BlueJ, so it can be used for instance in a lab environment to make the libraries available to all students. These libraries must be .zip or .jar archives.

Naturally, to put a library in a "userlib" directory, a person must have write access to the directory.

Libraries loaded via this second method are listed in the "Libraries" tab of the "Preferences" dialog also, but libraries cannot be added to or removed from the userlib directory via the dialog. These libraries will be available in all projects.

The third way is via the "+libs" directory. If a directory called "+libs" is found inside a project when it is opened by BlueJ, then all the class libraries inside it will be on the classpath (and therefore available for use in the project). This is a convenient way to allow libraries to be loaded on a project-by-project basis. This comes in handy if you want to distribute a project with any libraries that might be needed for it to function. You can simply zip up the project directory and distribute the project.

So in summary there are three ways that custom class libraries can be made available inside BlueJ. For system level access (all users and all projects) you can use the "userlib" directory. For user level access (all projects for a single user) you can use the Preferences Dialogue to add a library, and for accessibility from a single project you can create or add an archive to a project's "+libs" directory.

This information is also available in the BlueJ Reference Manual in Section 8: Configuration.

 

Tip 6: Using Objects from Standard Library Classes

It can be very useful for educational or testing purposes to instantiate library classes. For example: Do you want to play around with a String object? Do you want to see how java.awt.Point behaves? In BlueJ, you can do this.

Select "Use Library Class..." from the tools menu. Then type in (or select from the popup menu) the full class name of the class you want to instantiate. Hit enter, and you will see a list of all constructors and static methods. Select one - and you're done!

You can, in the same way, call static methods of library classes. For example, select java.lang.Math, double-click the "random()" method and - voila - you got a random number!

 

Tip 7: Creating (executable) Jar files

You can create jar files directly from BlueJ. Jar files include all files of a given project in a single file. This presents a convenient way to transfer a project from one location to another, for example if you want to send it as an attachment in an email. You can also make jar files executable, effectively crating an application that can be started by double-clicking.

In BlueJ, you can create a Jar file by choosing the "Export" function from the "Project" menu. You will see a dialogue similar to thie one shown here.

To create a Jar file, choose "Store as jar file". If you want the jar file to be executable (so that, for example, a double-click in Windows will start it) select the "main class" from the popup menu. The main class must contain a standard main method which will be executed to start the application.

With the last checkbox, you can choose to include the source into the jar file. If you are creating a jar file as an executable application, you may choose not to include the source. If you, on the other hand, create the file for the pupose of submitting your project to your teacher for marking, you would probably want to include the sources.

Once you click "Continue", you will be prompted for a file name for the jar file. That's all - you're done!

 

 

Tip 8: TABs in Java source files: hard or soft?

Indentation in Java source files is important - we all know that. But how do you do it?

Some people like TAB characters - moving to the next TAB stop with just one character - others hate them. What is the problem?

Tab width

First, there is the issue of tab width. One question people will never agree on is: how far should one TAB indent? A TAB stop has traditionally been set every eight characters. Many programmers find this too wide. Some people prefer two character indentation, others prefer three. BlueJ, by default, uses a very lovely four characters.

In BlueJ, you can define your preferred tab width by setting the "bluej.editor.tabsize" attribute in the bluej.defs file. (If unsure how to do this, read Tip 4 in the tips archive.)

If you use only BlueJ, the problem ends here. If, however, you use BlueJ and other editors for the same files, you may have some more problems.

Soft vs hard

Some editors do not give you the option of adjusting the tab width. As a result, files are then displayed with a different tab width then the one they were written for. This often gets very messy, especially if TAB characters were mixed with spaces. A solution to overcome this problem is to avoid TAB characters altogether and to use only spaces for indentation. This is known as "soft" tabs.

BlueJ, as of version 1.1.4, has an editor function "insert-tab" and another one "insert-spaced-tab". The first inserts a hard TAB character, the second inserts spaces up to the next TAB stop (a soft tab). You can choose hard or soft tabs by binding either of those functions to the TAB key on your keyboard.

In BlueJ (starting with version 1.1.4), the default is to insert soft TABs. If you have custom key bindings from earlier versions, however, these will not be changed and you may need to make the change manually (via the "Key Bindings" menu item).

Automatic conversion

It does not usually make sense to mix soft and hard tabs. Consequently, if you use soft tabs in a file in BlueJ, the editor will automatically convert all TABs in the file to spaces (making the whole file soft-tabbed). One of the nice effects of this is that the BlueJ templates (which are written with hard TABs) automatically convert to your preferred TAB width, even if you use soft tabs (because as soon as you edit the template, all hard tabs are converted using your defined tab width).

 

Tip 9: Passing "command line" arguments to main

This tip is actually the answer to a frequently asked question. The question is:

When you call a Java application from a command line, you can pass in command line parameters - how can you do the same from BlueJ?

The answer: Command line arguments are passed into the java main method as an array of strings.

In BlueJ, when you call a main method from a class, you will see a parameter entry field that prompts you for this array of stings.

By default, the parameter is

{ }

(an empty array, no parameters). If you want to pass, say, three parameters, from a command line you would write

java MyClass one two three

In BlueJ, you use the following parameter for "main":

{ "one", "two", "three" }

This passes an array of the three strings, just as the command shell does.

 

Tip 10: Accessing resources in a safe way (or: "Why can't BlueJ find my file?")

Note 2008-04-02: This tip is out-of-date. When run in BlueJ a project's "current directory" is now the project directory. However, it is still unwise to make this assumption.

Here is a common problem: You want to access a file on disk (maybe an image, maybe a text file, or anything else for that matter), and you need to specify the name. You write some code similar to this:

Image image = new ImageIcon("myImage.gif").getImage();

or

FileInputStream stream = new FileInputStream("myFile.txt");

Then you discover that it doesn't work. (Or, as some people wrote to us, it "works when I run it from xxx, but not from BlueJ".)

So why is that?

Most people put their image or text file into the project directory, and then want it to be found. The problem is that this depends on the system's "current directory". This is not a BlueJ-specific problem, but a general Java problem. Only, you may discover it for the first time when you use BlueJ.

The current directory is the directory you used when you start Java. When you use BlueJ, the current directory is the directory where you started BlueJ. If you started BlueJ from a DOS window, it is that current directory of that DOS window. If you started BlueJ, say, with a shortcut from the desktop, then it is the desktop.

This means that the above code fragments will probably not find the files when you run them in BlueJ. On the other hand, if you run Java from the DOS window, as below, it may work:

C:\> cd myProject
C:\myProject\> java MyClass

So is BlueJ wrong? No, because you should never assume that you know what the current directory is when your code runs. Consider the following way to start your Java class through the DOS window, which is an equally valid way to start your application:

C:\> java myProject\MyClass

This command will also start your class, but your code trying to load the file will fail, because now the current directory is different.

In other words: Writing code that relies on the current directory is usually a bad idea, and it is prone to break at any moment.

That leaves the question: what should I do instead? The answer is: Use the "getResource" method from java.lang.ClassLoader. This method will find a file anywhere in the current classpath. And the BlueJ project directory is always in the classpath, so it will always find a file there, no matter what the current directory is.

Here is a code example using this method to load an image:

public Image getImage(String fileName) {
    URL imageURL = getClass().getClassLoader().getResource(fileName);
    if(imageURL == null)
        return null;
    return new ImageIcon(imageURL).getImage();
}

Here is a code example reading a text file using getResource:

public InputStream openFile(String fileName)
    throws IOException
{
    URL url = getClass().getClassLoader().getResource(fileName);
    if(url == null)
        throw new IOException("File not found: " + fileName);
    return url.openStream();
}

The "getClass()" method is defined in class Object, so it is available in every object. Class URL is in the package java.net. Using this code, your program should work independently of how it was started.

 

Tip 11: Extending the Help menu

Many teachers of university or college courses supply their own information for work with BlueJ. There might be documentation for a custom library, a coding style guide, general course information or a web based discussion group.

The BlueJ help menu can now (starting with BlueJ version 1.1.6) be configured to include entries that link to this additional information. Here is how.

The configuration is made in the bluej.defs file (see tip 4 in the tips archive if unsure about this).

Each entry in the help menu will open, when selected, a web browser with a given URL.

Assume we want three additional entries in our Help menu:

CS141 Course Info
Coding Style Guide
Discussion Group

Each of these entries will be linked to a URL, for example:

CS141 Course Info --> http://www.someinstitution.edu/courses/cs141
Coding Style Guide --> http://www.someinstitution.edu/courses/cs141/style.html
Discussion Group --> http://www.someinstitution.edu/discussion/discuss.cgi

Here are the configuration entries for bluej.defs necessary to create this configuration:

bluej.help.items=courseInfo styleGuide discussion

bluej.help.courseInfo.label=CS141 Course Info
bluej.help.courseInfo.url=http://www.someinstitution.edu/courses/cs141

bluej.help.styleGuide.label=Coding Style Guide
bluej.help.styleGuide.url=http://www.someinstitution.edu/courses/cs141/style.html

bluej.help.discussion.label=Discussion Group
bluej.help.discussion.url=http://www.someinstitution.edu/discussion/discuss.cgi

In detail:

  • The "bluej.help.items" property is a list if identifiers with one entry for each menu entry. The actual names of the identifiers can be freely chosen.
  • For each identifier in given in this list, there should be two properties of the form
      bluej.help.<identifier>.label
    and
      bluej.help.<identifier>.url

That's all. Start BlueJ and off you go.

 

Tip 12: Configuration on MacOS X

For many configurations in BlueJ you need to find BlueJ's 'lib' directory (Tip 4, for instance, talks about it when discussing how various BlueJ settings can be configured). On MacOS, there is no 'lib' directory - so where's are the configuration directories and files?

On a Mac, the role of the 'lib' directory is taken by a 'Java' directory deep inside the BlueJ application bundle. To find it, Ctrl-click the BlueJ application and select 'Show Package Contents'. Then navigate your way down the folders Contents/Resources/Java. Here, you will see the file 'bluej.defs' (and all other BlueJ configuration files and directories). You can edit the bluej.defs file using the TextEdit application.

 

Tip 13: Top-of-screen menubar on MacOS X

Note 2008-04-02: This tip is out-of-date. The top-of-screen menubar is now on by default.

Macintosh applications usually have their menubar at the top of the screen, rather than the top of each window. Java usually uses top-of-window menu bars.

BlueJ can do either one. Since BlueJ on MacOS uses a Mac look-and-feel, it might be preferrable to use a screen menu bar to fit in with Mac conventions.

BlueJ, by default, uses a per-window menu bar because of a bug in Apple's Java implementation with Java and a screen menu bar. Using a screen menu bar could crash BlueJ on some MacOS systems (while other users reported no problems). This problem may have been fixed in a recent Java update.

If you would like to change the menu bar settings to try our a top-of-screen menubar, you can easily do that:

  •  open 'bluej.defs' (see tip 12 for instructions how to do this)
  •  find the bluej.macos.screenmenubar property
  •  set the value to true

Tip 14: Changing the default class template

When a new class is created in BlueJ, the source file is set to a default template. This template is user definable - you can adapt it to your own coding style. There are several templates: for standard classes, interfaces, applets, etc. Each template is a simple text file and can be edited in any text editor.

You find the templates in the folder

<bluej_home>/lib/<language>/templates/newclass/

where <bluej_home> is the folder where you installed BlueJ, and <language> is a folder for your current interface language, for example "english".

 

Tip 15: Changing class templates on the fly

This is a tip for teachers who work with labs of machines. You may know that you can edit the default class template for new classes (see Tip 14). If you want your own class templates, you would typically edit one BlueJ installation to suit your preferences, and then copy it through the whole lab.

But what if you like the templates to change in the middle of the semester? Maybe you want different text in the template, or maybe you want additional templates altogether. Often, universities do not allow installations to be changed during term.

To do this, you can configure you initial installation to use a shared template directory. This is done using the bluej.templatePath property. You can set this path to a shared location, and templates will be read from this directory. For example:

bluej.templatePath = F:\\shared\\bluej\\templates

If you edit the templates, or create new template files in this directory at any time, these templates will be available at the next start of BlueJ.

 

Tip 16: Stand-out comments

Sometimes it is useful to make a location in your source code stand out. For example, if you are a teacher, and you want to give students a half-implemented class and mark the places where they should enter code, you want them to find those places easily. Or you want to leave notes for yourself marking sections of unfinished work.

You can use stand-out comments for this. Stand out comments start with the symbols /*# (that is: a normal comment symbol followed by a hash sign), for example:

   public int getTotal()
   {
      /*# insert your code here */
   }

The only difference between normal comments and stand-out comments is that they are displayed in a different colour (pink) in BlueJ's editor. The actual colour can be changed by editing the file 'moe.defs'.

 

Tip 17: Clearing the terminal

A frequently asked question is whether you can automatically clear the terminal in BlueJ. There are, in fact, two different ways.

You can get BlueJ to automatically clear the terminal before every interactive method call. To do this, activate the 'Clear screen at method call' option in the 'Options' menu of the terminal.

You can also clear the terminal programmatically from within your program. Printing a formfeed character (unicode 000C) clears the BlueJ terminal. For example, like this:

   private void clearScreen()
   {
      System.out.print('\u000C');
   }

This is specific to the BlueJ terminal (and maybe some other terminals, but clearly not all).

While it may be useful to use this, it is also a good place to discuss OS specific behaviour (and why to avoid it). Different terminals react differently to control codes (that is: printing of characters with ASCII values below 0x20). Some terminals may honour things like backspace, bell, formfeed, others may not. Everyone honours CR and LF in some form, but that's almost all that's agreed on.

 

Tip 18: Saving objects

When BlueJ exits, classes (the diagram and their sources) are saved. Objects are not.

Many people over time have asked whether objects could be saved as well. Since BlueJ 1.3, there is a solution to this.

Objects are still not automatically saved, but by making use of a part of the unit testing functionality, you can essentially save and recreate a set of objects.

The unit testing classes offer two main parts of functionality: defining and running tests, and saving so-called "fixtures" - a set of objects used as a basis for tests. We can make use of the text fixtures to save objects - even if we have no intention to use anything else of the testing functionality.

You do not need to have the unit testing tools enabled. (This can be done in the preferences.) This trick works without the unit testing tools being available.

Now, here is what you can do:

  • Create a new class (using the New Class button), name it (for example) ObjectSaver, and select Unit Test as the class type. The class ObjectSaver will appear in your class diagram.

  • You can now use the functions in your ObjectSaver class's popup menu to save and restore the object bench. Use 'Object Bench to Test Fixture' to save the bench's state, and 'Text Fixture to Object Bench' to recreate the saved state.

For example, if you are in the middle of work and you need to quit BlueJ, use 'Object Bench to Text Fixture' to save the objects first. When you restart BlueJ, use 'Text Fixture to Object Bench' to recreate your objects. You can recreate the saved object state multiple times, at any time you like.

 

Tip 19: Operations on a group of classes

Since BlueJ version 1.3.5, it's been possible to select multiple items (classes, packages, etc.) in the class diagram. You can do this by clicking and dragging out a marquee (a box shaped area); when the mouse button is released, all the items in the box will be added to the selection.

When you have selected multiple items, you can move them around as a group by dragging one of the items in the usual way. It's also possible to compile the selected items ("tools" menu, "compile selected") or remove them all ("edit" menu, "remove").

Another way of selected multiple items is by holding the SHIFT or CTRL key (SHIFT or META on the Mac), and clicking individual items to add them to the selection.

You can remove individual items from the selection by holding SHIFT (or CTRL/META) and clicking them. (That is, holding SHIFT and clicking an item toggles its selection state between "selected" and "not selected").

Clicking on a single item (while not holding SHIFT, CTRL or META) will de-select all other items.


Tip 20: Making the editor open in "interface" view by default

Sometimes it might be desirable that when a student opens a class for the first time, they are present with the "interface" view - that is, the class documentation - rather than the source code. This could be particularly useful for classes which the student is not supposed to modify.

(You can change the view between "implementation" and "interface" using the drop-down list box in the editor.)

BlueJ saves the state of the view (interface or implementation) of each class with the project. So, to have classes appear in interface view by default, you just need to set the class to the interface view when you are preparing the project (making sure that it's still in interface view before you close the project!). The next time the project is opened, the class will show the interface view when it's opened in the editor.

Naturally, the view can still be changed back to the "implementation" view so that the students can see the source code, should they so desire.

 

Tip 21: Debugging an Applet

Sometimes, when developing a program, the debugger can provide useful help: you can single-step through your code, you can inspect variables, and so on.

Unfortunately, when you are writing an applet, this is not as easy.

BlueJ's debugger can only work when the code is executed within BlueJ. When you run an applet (using the 'Run Applet' function) the applet is executed either in the applet viewer or in a web browser.

Both of these - viewer and browser - are separate applications, independent from BlueJ. Thus, debugging does not work with them.

If you set a breakpoint in your source code in BlueJ, and then execute your applet in a web browser, the breakpoint will have no effect, since the applet runs in a completely separate environment.

So, that brings us to our question: What can you do to debug applets?

Luckily, there is a solution: Michael Trigoboff has written a class called AppletWindow, which allows you to execute an applet within the BlueJ environment. (The AppletWindow essentially simulates the behaviour of the web browser or applet viewer inside the BlueJ environment.)

Using the AppletWindow, your applet will execute within BlueJ, and thus breakpoints and other debugging tools will work.

The AppletWindow class is available from our resource section.

 

Tip 22: Using BlueJ to develop BlueJ extensions

It's easy to use BlueJ itself to develop BlueJ extensions. Here's how.

First, add the bluejext.jar library to the list of libraries your BlueJ projects can use. On the Libraries tab of the Tools/Preferences panel, click Add and browse to the folder BlueJ is installed in. Select the folder lib and then the file bluejext.jar. Click OK. You'll have to close and re-start BlueJ for this change to take effect.

Now you can create your extension as a normal BlueJ project. As with all extensions, one of your classes will need to extend the class bluej.extensions.Extension.

When you are ready to try out your extension, select Project/Create Jar File .... Select as the Main Class the class in your extension which extends bluej.extensions.Extension. You don't need to tick the boxes to include user libraries, source, or BlueJ project files.

Now you will see a dialog box asking you where you want to put the Jar file you are about to create. This should be the in the lib/extensions folder of you BlueJ installation, or the extensions folder of your personal BlueJ settings folder -- see the note on Installing extensions on the extensions home page. You can choose any name you like for your extension's Jar file (providing it ends in .jar!)

You will now need to quit and re-start BlueJ so that it will pick up your new (or revised) Jar file. When you re-start BlueJ, your extension should be listed in the Help/Installed Extensions dialog.

 

Tip 23: Easily send BlueJ projects via e-mail

Sometimes it can be useful to send a project via email, either to send it to a friend or to submit it as a course assignment. Here is how you can do it.

You can use BlueJ's Create Jar File function (use the options to include the source and BlueJ files). This will create a jar file that contains your whole project in a single file. This file can easily be attached to mail messages.

When receiving this file, you can easily open it using BlueJ's Open Non-BlueJ function to open the jar- file directly. BlueJ will expand the jar file for you (thus re-creating the project) and store the project in the same place where the file is.

If you want to include other documents, they can be placed into the project folder. BlueJ will include all files that are stored in the project folder when building the jar file.

 

Tip 24: Running BlueJ from a USB (thumb) drive

If you often find yourself wanting to show people some interesting feature of BlueJ (I know I do!), but don't have your own machine with you, here's how to load Java and BlueJ onto a USB drive and run them on any Windows machine without installing anything. Note: I'm not sure about the strict legality of this with respect to the JDK license.

  1. Copy the lib, bin and jre folders of an installed JDK onto the USB drive, i.e. from C:\Program Files\Java\jdk1.5.0_10 to E:\jdk1.5.0_10
  2. Copy the lib folder of your BlueJ installation onto the USB drive, i.e. from C:\BlueJ to E:\BlueJ
    Create a file bluej.bat in the root of your USB drive, containing:
    start jdk1.5.0_10\bin\javaw -jar BlueJ\lib\bluej.jar -bluej.userHome=home
    The last bit forces the user's BlueJ home to be on the USB drive in the folder "home", which will be created if necessary.
  3. If you want running BlueJ to be offered as part of the USB drive's autorun options, create a file called autorun.inf in the root of the containing the following:
    [autorun]     
    open=bluej.bat   
    icon=bluej.ico
    ACTION = Launch BlueJ-on-a-Stick
    You can get a copy of bluej.ico (the BlueJ icon as a Windows icon file) from http://www.bluej.org/bluej-icons/

 

Tip 25: Adding Google search of Java API to BlueJ help menu

  1. Open your %BLUEJHOME%/lib/bluej.defs file. Or just open your %USERHOME%\BlueJ\bluej.properties file,
    which overrides bluej.defs. The order of lines in this file may be scrambled, so in a text editor like TextPad that can sort lines, select the second to last lines and sort them in ascending order so you can find your way around.

  2. Find the lines beginning with "bluej.help." which configure the Help menu.

  3. Add these TWO lines (quotes added to indicate the extent of a single line, which may be wrapped in your browser):

    "bluej.help.searchJavaApi.label=Search Java API"
    "bluej.help.searchJavaApi.url=http\://www.google.com.au/search?hl=en&rlz=1B2GGGL_en___AU202&q=
    %22index.html%3Foverview-summary.html%22+site%3Ajava.sun.com%2Fjavase%2F6%2Fdocs%2Fapi%2F&btnG=
    Search&meta="

    These lines implement the menu option label and the behaviour.

  4. Find the line beginning with "bluej.help.items=". This line makes the menu options appear on the help menu in the order specified.

  5. Add "searchJavaApi" to this line in the menu position convenient for you, making sure that it is separated from the preceding and following items by space characters.

  6. Relaunch BlueJ so that the new preferences are read in.

  7. If the "Search Java API" item does not appear on the Help menu, it is possible that there is an error in the bluej.properties file in your home directory. Please repeat the steps carefully until the item appears.

  8. Choose Help > Search Java API and your browser will open the Google page with a single link to the Overview page of the Javadoc.

  9. Edit the search string in the Google search box but leave the "site:*" parameter as it is.

Now you can search for arcane stuff like "+cmyk +rgb +convert site:*" or whatever!
(Tip written by Hedley Finger.)

Next page >

 
 

Discussion Group

bluej-discuss

Announcements

For notificaton of new releases, subscribe to: BlueJ-announce

 
Bug Parade
View or submit bugs
maintained by
Michael Kölling
.
supported by Oracle logo