Subsections


6.5 Object manipulation and better Java Widgets

In this section we will address some issues on how to control objects from the Applet.

[REALLY under construction]


6.5.1 My first slider applet

The first Java applet Daniel ever wrote was the next one, so we leave it here, despite the fact that it uses depreciated Java 1.0x technology. You can change the sizes and position of a nice green ball.

Example 6.5.1   Ball Grow

Contents: getEventIn, Java: sliders
HTML page: eai/ballgrow/ball-grow.html
JAVA code: eai/ballgrow/BallGrow.java
Directory: (dir)

You will not learn any new EAI technology, but you can see how to program a simple use of sliders with Java 1.0x. In order to set up the layout we use Panels and GridLayouts. GridLayOuts allow you to simply put Widgets into a Grid and their size will be adjusted to the size of the largest elements. Code on the EAI side should be familiar now:


public void init () {
  ......
  // Get the reference to the set_scale event
  set_scale = (EventInSFVec3f) root.getEventIn("scale");

  // Get the reference to the set_translation event
  set_translation = (EventInSFVec3f) root.getEventIn("translation");
  .......
 }

public boolean handleEvent (Event event) {

  if (event.target instanceof Scrollbar) {
  ......
  val[0] = ((float) transx.getValue()) / 10.0f;
  val[1] = ((float) transy.getValue()) / 10.0f;
  val[2] = ((float) transz.getValue()) / 10.0f;
  .........           
  set_scale.setValue(val);
  .....
  set_translation.setValue(val);
}

In the same directory you will find more sophisticated versions of this applet, illustrating some more features and also politically better Java programming.


D.K.S. - 1999-04-28