invokeMethods Example: Draw a Line in a Text Field

To draw a line in a multiline text field, you need to access a graphics object inside the text field by calling the following methods in Java:
  TextField multiLine = ...; // get reference to multiline text field
  Graphics graphObj = multiLine.getGraphics();
  graphObj.drawLine(10, 10, 20, 20);
However, you cannot call the above sequence of methods from 4Test because Graphics is not 4Test-compatible. Instead, you can insert the invokeMethods prototype in the TextField class declaration, then add invokeMethods by hand to your test script to draw a line in the Graphics object nested inside the multiline text field, as shown in this 4Test function:
MyDialog.Invoke() // Invoke Java dialog that contains the text field
MyDialog.TheTextField.invokeMethods ({"getGraphics", "drawLine"}, {{}, {10, 10, 20, 20}})

In this code, the following methods are called in Java:

  • getGraphics is invoked on the multiline text field TheTextField with an empty argument list, returning a Graphics object.
  • drawLine is invoked on the Graphics object, to draw a line starting from (x,y) coordinates (10,10) and continuing to (x,y) coordinates (20,20).