×

SliderDemo

SliderDemo demonstrates how to create a slider using slider component of LWUIT.

Design

The MIDlet has a form showing a slider and options to control the slider. The slider changes according to the options selected.

The MIDlet is tested on Nokia Asha SDK 1.0.

Implementation

Initialisng LWUIT Display:

Display.init(this); // initialise LWUIT Display

Initialising and displaying Form:

form = new Form("Slider Demo");
form.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
slider = new Slider();
slider.setEditable(true);
slider.setRenderValueOnTop(true);
form.addComponent(new Label("Slider Demo"));
form.addComponent(slider);
form.setBackCommand(backCommand);
form.addCommandListener(this);
addroperties();
form.show();

Adding components to Form:

private void addProperty(String field, int id, Form form) {        
    switch (id) {            
        case 0:
        isEditable = new CheckBox(field);
        isEditable.setSelected(true);
        isEditable.addActionListener(this);
        form.addComponent(isEditable);
        break;
        case 1:
        rendervalueonTop = new CheckBox(field);
        rendervalueonTop.setSelected(true);
        rendervalueonTop.addActionListener(this);
        form.addComponent(rendervalueonTop);
        break;
        case 2:
        renderpercentageonTop = new CheckBox(field);
        renderpercentageonTop.addActionListener(this);
        form.addComponent(renderpercentageonTop);
        break;

        .........
        .........
        .........
    }       
}

Applying selected option on Slider component through actionPerformed(ActionEvent evt) method:

public void actionPerformed(ActionEvent evt) {        
    if (evt.getSource() == backCommand) {
        notifyDestroyed();
        return;
    }

    if ((evt.getSource() == isEditable)) {
        slider.setEditable(isEditable.isSelected());
        if (isEditable.isSelected()) {
                isInfinite.setEnabled(false);
        } else {
                isInfinite.setEnabled(true);
        }
    }
    .........
    .........
    .........
    .........

    form.invalidate();
    slider.repaint();
    form.repaint();
}

Last updated 24 June 2013

Back to top

×