2. Global Functions and Constants

Java has no global namespace, so it is not possible to have global functions like wxMessageBox() or global constants like wxOK. The org.wxwindows.wx class contains nothing but static methods and members for all the globals. Thus, all globals must be prefixed with wx., for example, wx.wxMessageBox() and wx.wxOK. While this works, it is not completely desirable since there is now a redundant "wx" for all these globals, and the Java code looks less like its C++ counterpart. Thankfully, a trick is employed to hide this issue. The Java wxObject class inherits from wx, so all the static methods and constants may be used directly without scoping. This means that any class that inherits from wxObject, which is nearly every wxWidgets class, may use these methods and members without scoping. For example, if you needed to extend a frame, you are able to do so like this since wxObject is an ancestor of wxFrame:

public class MyFrame extends wxFrame
    public MyFrame(String title)
        super(null, -1, title, wxDefaultPosition, wxDefaultSize,
        // ... do other stuff ...
        // May call methods like wxMesageBox() directly

There are cases when this is not possible, for example when creating interfaces for ID constants, so any global functions must be properly scoped:

import org.wxwindows.wx;

public interface Id
    public static final int CONTROL_ID_1 = wx.wxNewId();
    public static final int CONTROL_ID_2 = wx.wxNewId();
    // .. other IDs ...