Common actions and custom code actions are not treated quite the same. Common actions are live both while the application is running and while you are building the application. Custom code actions are live only while the program is running, not while you are building the application. Future versions of Visual Java may support live code actions while building the application.
The exit action is not live while building the
application because it would cause Visual Java to exit
and unsaved changes would be lost.
If you choose the Constant from the menu, you can statically set the value using the provided editors, text fields, and so on.
If you choose Event Arg from the menu, the
event
arg
must be the same type
as the attribute that you have selected. For example,
checkboxes have Boolean event arguments. The
enabled
attribute defined for components is
also a Boolean. Therefore, you can legally choose the
event arg
option for the checkbox as long as
you select the enabled
attribute for the
target component. Defining an action in this way will
cause the checkbox to toggle the component between the
enabled and disabled states.
The code you enter in the Execute Code area is saved in the
.gui
file, and later generated into the
<ProjectName>Ops.java
file.
For a group named MyProg
:
MyProg group;
MyProgRoot gui;
Message msg;
Event evt;
The following is a code segment that shows the window "frame1" when a button is clicked:
gui.frame1.set("visible", Boolean.true);
The following is a code segment that shows or hides the window "frame1" depending on the state of a checkbox:
gui.frame1.set("visible", evt.arg);
import java.net.*; URL url = new URL(gui.urlTF.get("text")); URLConnection connection = url.openConnection();The following code is generated into the <ProjectName>
Ops.java
file.
Note the position of the import statement.
import java.io.net.*; private void handleCallback(int index, Message msg, Event evt) { switch (index) { case 1: { group.exit(); } break; case 2: { URL url = new URL(gui.urlTF.get("text")); URLConnection connection = url.openConnection(); } } }
getBody()
call allows you to access
methods of the classes on which shadow classes are based.
For example, if you want to determine which item is
selected in a ListShadow
object, enter:
String string_selected=((List) listShadow.getBody()).getSelectedItem();In general, it is better to use the shadow class for the
get()
and set()
methods rather
than getBody()
which accesses the AWT
component directly. The shadow class methods
utilize workarounds and optimizations. For example:
String string_selected=listShadow.get("selectedItem");
group
class provides a method for
accessing the applet. For example, if in your operation
you need to access a parameter supplied to the applet (in
this case the blink rate), enter:
Applet ap = getApplet(); String param = ap.getParameter("blinkrate");
See also: