It depends on whether you want a “native” Java button control (Swing JComponent or SWT widget Control, depending on your platform). If you do, then you should use a JGoButton. If not, then you can use any approprate JGoObject (including JGoAreas consisting of whatever you want to include in your button) and implement a mouse click event handler, either as a separate listener or as an override of JGoObject.doMouseClick.
The following code in a view listener handles both kinds of cases:
case JGoViewEvent.CLICKED: { if (e.getObject() instanceof Button) { Button but = (Button)e.getObject(); MessageBox dlg = new MessageBox(myShell, SWT.ICON_INFORMATION | SWT.OK); dlg.setText(“Button Clicked”); dlg.setMessage(“Clicked on a Button”); dlg.open(); } else if (e.getJGoObject() != null) { JGoObject obj = e.getJGoObject().getParentNode(); if (obj instanceof JGoBasicNode) { JGoBasicNode bn = (JGoBasicNode)obj; startTransaction(); bn.setBrush(JGoBrush.makeStockBrush(getRandomColor())); endTransaction(“changed node color”); } } }
When the user clicks on a JGoButton’s Button Control, the JGoViewEvent.getObject() is a Button.
When the user clicks on a JGoObject, JGoViewEvent.getJGoObject() will be non-null. This particular example checks for clicking on a JGoBasicNode [note the call to JGoObject.getParentNode(), since the user is probably clicking on a child object of the node] and changes the brush color or the JGoBasicNode’s drawable shape.