1
votes

For my main App I would need a custom container for navigation purpose, see here (Stackoverflow).

As the solution posted did not work for me (I tried with simple System.out.println), I began a new Project to understand, how the container embedding works, but it does not work the way I expected.

So the new App is the Hi World application with the orange color.

I created a new blank container in the GUI designer and added 3 Buttons.

  1. I created a new blank container in the GUI designer and added 3 Buttons.
  2. I added an actionListener to them within the container
  3. I added the container to the form

My StateMachine looked like this:

@Override
protected void onButtonCont_ButtonAction(Component c, ActionEvent event) {

System.out.println("button1 clicked");
}

@Override
protected void onButtonCont_Button1Action(Component c, ActionEvent event) {

    System.out.println("button2 clicked");
}

@Override
protected void onButtonCont_Button2Action(Component c, ActionEvent event) {

    System.out.println("button3 clicked");
}

(The container I created was named ButtonCont..) Nothing else modified in StateMachine or elsewhere!

Now I started the app and clicked the buttons - but nothing happened.

So I

  1. Opened the GUI Builder
  2. Selected MainForm
  3. selected the three Buttons one after another
  4. added ActionListeners to each one

Now my StateMachine looks like this:

@Override
protected void onMain_Button2Action(Component c, ActionEvent event) {

    System.out.println("button3 -now- clicked");
}

@Override
protected void onMain_Button1Action(Component c, ActionEvent event) {

    System.out.println("button2 -now- clicked");
}

@Override
protected void onMain_ButtonAction(Component c, ActionEvent event) {

    System.out.println("button1 -now- clicked");
}

(in addition to the previous onButtonCont- methods)

Starting the app and clicking the buttons results in this output:

button1 -now- clicked
button3 -now- clicked
button2 -now- clicked

What am I doing wrong?

1

1 Answers

1
votes

I found the answer myself.

Instead of adding the container to the Form under the section "user defined", you simply need to add an embedded container and select "embedded | [null]" to your own container