Next Generation BS Development Framework - Echo Tutorial (5)

zhaozj2021-02-11  170

Next Generation B / S Development Framework - Echo Tutorial (5)

Editable drop-down list

We know that the drop-down list on the HTML page is invisible. Echo can make us easily achieve. Let's take a look at this ComboBox how to use:

// drop-down list data string [] member = new string [] {"steeven", "stella"}; selectfieldmodel model = new defaultselectfieldModel (Member); // can be reused: ComboBOX Combo = New ComboBox ("default text" , SelectFieldModel;

Simple? Let's take a look at the specific implementation:

/ ************ComboBOX.java***********

* Editable drop-down list

* /

Import nextApp.echo. *;

Import nextapp.echo.event. *;

Public class comboBOX EXTENDS Panel Implements ActionListener {

Private textfield input = new textfield (); // input box

Private selectfield select = new selectfield (); // pull-down box

Private checkbox check = new checkbox (); // switch button

Public ComboBox (String text, selectfieldmodel model) {

Select.SetModel (Model); // Set the content of the drop-down list

Settext; // Set the default text

Select.setVisible (false); // Default

Add (Input);

Add (SELECT);

Add (CHECK);

Check.addactionListener (this); // Listening to switching action

}

Public void setText (string text) {

this.input.settext (text); // Set text box text

/ / Set the drop-down frame selected value

This.select.getmodel (). setSelectedItem (Text);

}

Public string gettext () {

Return check.isselected ()? select.getSelectedItem (). Tostring (): Input.getText ();

}

Public Void ActionPerformed (ActionEvent E) {

Input.setvisible (! check.isselected ());

Select.setvisible (Check.isSelected ());

//Synchronous Data

Check.isselected ())

Select.getmodel (). setSelectedItem (Input.getText ());

Else

INPUT.SETTEXT (Select.getSelectedItem (). TOSTRING ());

}

}

The principle is simple:

Simultaneously construct the input box and drop-down box, alternately appear according to the state of the check box. Synchronize the data in the switch, according to the value of the drop-down box, or copy the selected value in the drop-down box to the input box. GetText () and getText () methods similar to TextField are provided.

Is it a full desktop programming style? No HTML and scripts are written.

This implemented ComboBox needs to interact with the server, slightly insufficient speed. Such interaction can be used to completely complete it on the browser. Don't worry, Echo allows you to write your own controls to achieve special needs, later chapters will have an introduction .

转载请注明原文地址:https://www.9cbs.com/read-5840.html

New Post(0)