Visual Assertions
Here's a simple way to do conditional connections in the VCE, though not the most "normal"... hey, I'm weird, what can I say...
Define a "conditional" method to choose whether or not we want to do something. For example: "is the sky blue."
public void assertSkyBlue() {
if (!skyBlue)
throw new RuntimeException("");
}
Note that this doesn't do anything except throw an exception if the sky isn't blue.
If you use this approach, do not call the method isSkyBlue() -- that implies it's a boolean property of a JavaBean...
VisualAge thinks of this as
sky isn't blue == exceptionOccurred sky is blue == normal result
So we can bastardize this into making a conditional connection. To try it:
- create a new Frame or Applet bean
- edit it in the VCE
- drop a Button and a TextField on the frame/applet
- connect actionPerformed from the Button to an event-to-script method (outside of the applet/frame)
- choose testSkyBlue as your script.
- define the following in your class (edit the source...)
public void testSkyBlue() {
if (!skyBlue)
throw new RuntimeException("");
skyBlue = !skyBlue;
} - create a connection from "normal result" of the last connection to setText of the TextField
- set the parameter of the connection to some constant string
When you run this, you'll see that it takes two button presses to set the text.
This example isn't terribly interesting, but it shows that it works.
However, exceptions are somewhat expensive -- make sure the "normal" behavior you expect is the one that does not throw the exception. Then again, in a GUI app it's not really noticeable.