Inspired by swing (LWUIT)

Discussion in 'Java' started by focode, Sep 7, 2009.

  1. focode

    focode Guest

    i present here the source code of my program that when executed will
    display four icons with two commands 1 ok 2exit

    i have to show next displayble "form" upon click of "ok" soft button ,
    anuone told me to use getFocus() to get the current selected image ,
    but i don't know how to use it ... just help me out


    import com.sun.lwuit.Command;
    import com.sun.lwuit.Component;
    import com.sun.lwuit.Display;
    import com.sun.lwuit.Form;
    import com.sun.lwuit.Image;
    import com.sun.lwuit.Label;
    import com.sun.lwuit.events.ActionEvent;
    import com.sun.lwuit.events.ActionListener;
    import com.sun.lwuit.layouts.GridLayout;
    import java.io.IOException;
    import javax.microedition.midlet.MIDlet;


    public class ImageListner extends MIDlet implements ActionListener{
    Form f1;
    public void startApp() {
    Display.init(this);
    getForm();
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }
    public Form getForm()
    {
    try {

    f1 = new Form("Text");

    f1.setLayout(new GridLayout(2,2));
    Image i1 = Image.createImage("/res/girl2-32.png");
    Label l1 = new Label(i1);
    l1.setText("Hello");
    l1.setTextPosition(Component.BOTTOM);
    l1.setAlignment(Component.CENTER);
    l1.setAlignment(Component.CENTER);
    l1.getStyle().setMargin(10, 10, 10, 10);
    Command ok = new Command("Ok");
    f1.addCommand(ok);
    Command exit = new Command("Exit");
    f1.addCommand(exit);
    f1.addComponent(l1);

    Label l2 = new Label(i1);
    l2.setText("Hello");
    l2.setTextPosition(Component.BOTTOM);
    l2.setAlignment(Component.CENTER);
    l2.setAlignment(Component.CENTER);
    l2.getStyle().setMargin(10, 10, 10, 10);
    f1.addComponent(l2);

    Label l3 = new Label(i1);
    l3.setText("Hello");
    l3.setTextPosition(Component.BOTTOM);
    l3.setAlignment(Component.CENTER);
    l3.setAlignment(Component.CENTER);
    l3.getStyle().setMargin(10, 10, 10, 10);
    f1.addComponent(l3);

    Label l4 = new Label(i1);
    l4.setText("Hello");
    l4.setTextPosition(Component.BOTTOM);
    l4.setAlignment(Component.CENTER);
    l4.setAlignment(Component.CENTER);
    l4.getStyle().setMargin(10, 10, 10, 10);
    f1.addComponent(l4);
    f1.setCommandListener(this);
    }
    catch (IOException ex) {
    ex.printStackTrace();
    }
    f1.show();
    return f1;
    }


    public void actionPerformed(ActionEvent ae) {
    Form current = Display.getInstance().getCurrent();
    if(current == f1)
    {


    }

    }
    private Component getFocused() {
    throw new UnsupportedOperationException("Not yet
    implemented");
    }
    }
    focode, Sep 7, 2009
    #1
    1. Advertising

  2. focode

    guptan Guest

    On Sep 7, 1:48 pm, focode <> wrote:
    > i present here the source code of my program that when executed will
    > display four icons with two commands 1 ok 2 exit
    >
    > i have to show next displayble "form" upon click of "ok" soft button (?LSK?) ,
    > anuone (?SOMEONE?) told me to use getFocus() to get the current selected image ,
    > but i don't know how to use it ... just help me out
    >
    > import com.sun.lwuit.Command;
    > import com.sun.lwuit.Component;
    > import com.sun.lwuit.Display;
    > import com.sun.lwuit.Form;
    > import com.sun.lwuit.Image;
    > import com.sun.lwuit.Label;
    > import com.sun.lwuit.events.ActionEvent;
    > import com.sun.lwuit.events.ActionListener;
    > import com.sun.lwuit.layouts.GridLayout;
    > import java.io.IOException;
    > import javax.microedition.midlet.MIDlet;
    >
    > public class ImageListner extends MIDlet implements ActionListener{
    >     Form f1;
    >     public void startApp() {
    >          Display.init(this);
    >     getForm();
    >     }
    >
    >     public void pauseApp() {
    >     }
    >
    >     public void destroyApp(boolean unconditional) {
    >     }
    >     public Form getForm()
    >     {
    >         try {
    >

    ////////////////////A CONTAINER
    >             f1 = new Form("Text");
    >

    ///////////////USES A CERTAIN LAYOUT ALGORITHM
    >             f1.setLayout(new GridLayout(2,2));


    >             Image i1 = Image.createImage("/res/girl2-32.png");

    /////////////COMPONENT
    >             Label l1 = new Label(i1);
    >             l1.setText("Hello");
    >             l1.setTextPosition(Component.BOTTOM);
    >             l1.setAlignment(Component.CENTER);
    >             l1.setAlignment(Component.CENTER);
    >             l1.getStyle().setMargin(10, 10, 10, 10);

    /////////////COMPONENT
    >             Command ok = new Command("Ok");
    >             f1.addCommand(ok);

    /////////////COMPONENT
    >             Command exit = new Command("Exit");
    >             f1.addCommand(exit);
    >             f1.addComponent(l1);

    /////////////COMPONENT
    > >             Label l2 = new Label(i1);

    >             l2.setText("Hello");
    >             l2.setTextPosition(Component.BOTTOM);
    >             l2.setAlignment(Component.CENTER);
    >             l2.setAlignment(Component.CENTER);
    >             l2.getStyle().setMargin(10, 10, 10, 10);
    >             f1.addComponent(l2);

    /////////////COMPONENT
    > >             Label l3 = new Label(i1);

    >             l3.setText("Hello");
    >             l3.setTextPosition(Component.BOTTOM);
    >             l3.setAlignment(Component.CENTER);
    >             l3.setAlignment(Component.CENTER);
    >             l3.getStyle().setMargin(10, 10, 10, 10);
    >             f1.addComponent(l3);

    /////////////COMPONENT
    >             Label l4 = new Label(i1);
    >             l4.setText("Hello");
    >             l4.setTextPosition(Component.BOTTOM);
    >             l4.setAlignment(Component.CENTER);
    >             l4.setAlignment(Component.CENTER);
    >             l4.getStyle().setMargin(10, 10, 10, 10);
    >             f1.addComponent(l4);

    /////////////COMPONENT
    ///REGISTER A LISTENER FOR EVENTS; MESSAGES WILL COME THROUGH THE
    INTERFACE
    >             f1.setCommandListener(this);
    >         }
    >          catch (IOException ex) {
    >         ex.printStackTrace();
    >         }

    ///////////////NOW SAFE TO BE RENDERED
    >             f1.show();
    >         return f1;
    >     }



    > ////EVENTS WILL COME HERE AS PER THE CONTRACT
    >     public void actionPerformed(ActionEvent ae) {

    /////////GET THE CURRENT CONTAINER
    >         Form current = Display.getInstance().getCurrent();

    /////
    >         if(current == f1)
    >         {
    >
    >         }
    >
    >     }
    >     private Component getFocused() {
    >         throw new UnsupportedOperationException("Not yet
    > implemented");
    >     }
    >
    > }
    >
    >


    first you study AWT programs and test some of them, they are easily
    available.
    then you will understand how to use action listeners for the
    components.

    Don't forget to cover up the concepts and design patterns and event
    sequences takes place in any UI Framework.

    "
    told me to use getFocus() to get the current selected image ,
    > but i don't know how to use it ... just help me out

    "
    You have formed a grid layout here. So naturally using navigation keys
    one can switch from one component to another. when input focus comes
    on a component rememember which one. this can be done using a
    reference or an integer as you have only four components. " Where is
    your commandAction();"
    Implement that. for LSK add the loaded image into your currently
    selected component, which is being rendered\in focus.

    Hope you have got some idea.
    guptan, Sep 7, 2009
    #2
    1. Advertising

  3. focode

    Roedy Green Guest

    On Mon, 7 Sep 2009 01:48:27 -0700 (PDT), focode
    <> wrote, quoted or indirectly quoted someone
    who said :

    >anuone told me to use getFocus() to get the current selected image ,


    I am not quite sure what you are trying to do, but probably want
    buttons, radio buttons, CheckBoxGroups -- things designed to be
    clicked.

    See http://mindprod.com/jgloss/jbutton.html
    http://mindprod.com/jgloss/jcheckbox.html
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com

    "I mean, source code in files; how quaint, how seventies!"
    ~ Kent Beck (born: 1961 age: 48), evangelist for extreme programming.
    Roedy Green, Sep 7, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    15
    Views:
    569
    Peter Hansen
    Jan 4, 2006
  2. Brian L. Troutwine
    Replies:
    5
    Views:
    276
    Nick Craig-Wood
    Jun 4, 2007
  3. focode
    Replies:
    1
    Views:
    1,821
    John B. Matthews
    Sep 8, 2009
  4. focode

    LWUIT and J2ME

    focode, Sep 10, 2009, in forum: Java
    Replies:
    0
    Views:
    369
    focode
    Sep 10, 2009
  5. Tom Metge
    Replies:
    1
    Views:
    90
Loading...

Share This Page