开发者

In LWUIT, Component of another Form are not display

开发者 https://www.devze.com 2023-03-16 21:04 出处:网络
I am new on J2me developer using LWUIT library. I am making two forms: one is MainMidlet.java and another is UpgradeApp.java. Problem is that whatever the component add on UpgradeApp.java the componen

I am new on J2me developer using LWUIT library. I am making two forms: one is MainMidlet.java and another is UpgradeApp.java. Problem is that whatever the component add on UpgradeApp.java the component are not displayed. Please help me.

My Code as Follows.

MainMidlet.java

package com.sun.lwuit.jewelvicinity;
import com.sun.lwuit.Button;
import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Dialog;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.FlowLayout;
import com.sun.lwuit.layouts.GridLayout;
import com.sun.lwuit.plaf.UIManager;
import com.sun.lwuit.table.TableLayout.Constraint;
import com.sun.lwuit.util.Resources;
import java.io.IOException;
import javax.microedition.midlet.*;

public class MainMidlet extends MIDlet implements ActionListener
{
    Form frm_Main;
public Button btn_main_Search, btn_main_WishList, btn_main_UpgradeApp, btn_main_Login,                         btn_main_NewUser,btn_main_Help, btn_main_AboutUs, btn_main_ContactUs, btn_main_Feedback, btn_main_Terms,btn_main_Privacy, btn_main_Exit;

public Image img_main_Search, img_main_Wishlist, img_main_UpgradeApp, img_main_Login, img_main_NewUser,img_main_Help, img_main_AboutUs, img_main_ContactUs, img_main_FeedBack, img_main_Terms,img_main_Privacy, img_main_Exit;

public Command cmd_Exit, cmd_Select;

public void startApp()
{
            //--- Use for third soft Button
    //Display.getInstance().setThirdSoftButton(true);
    Display.init(this);

    try
    {
        Resources theme = Resources.open("/LWUITtheme.res");
        UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0]));
    }
    catch (IOException io)
    {
        io.printStackTrace();
        Dialog.show("Theme Exception", io.getMessage(), "Ok", null);
    }

    frm_Main = new Form("Jewel Vicinity");

    try
    {
        img_main_Search = Image.createImage("/res/btn_main_search.png");
        img_main_Wishlist = Image.createImage("/res/btn_main_wishlist.png");
        img_main_UpgradeApp = Image.createImage("/res/btn_main_upgradeapp.png");
        img_main_Login = Image.createImage("/res/btn_main_login.png");
        img_main_NewUser = Image.createImage("/res/btn_main_newuser.png");
        img_main_Help = Image.createImage("/res/btn_main_help.png");
        img_main_AboutUs = Image.createImage("/res/btn_main_aboutus.png");
        img_main_ContactUs = Image.createImage("/res/btn_main_contactus.png");
        img_main_FeedBack = Image.createImage("/res/btn_main_feedback.png");
        img_main_Terms = Image.createImage("/res/btn_main_terms.png");
        img_main_Privacy = Image.createImage("/res/btn_main_privacy.png");
        img_main_Exit = Image.createImage("/res/btn_main_exit.png");

    }
    catch (IOException io)
    {
        io.printStackTrace();
        Dialog.show("Image not Found!", io.getMessage(), "Ok", null);
    }

    btn_main_Search = new Button("Search", img_main_Search);
    btn_main_WishList = new Button("Wish List", img_main_Wishlist);
    btn_main_UpgradeApp = new Button("Upgrade", img_main_UpgradeApp);
    btn_main_Login = new Button("Login", img_main_Login);
    btn_main_NewUser = new Button("NewUser", img_main_NewUser);
    btn_main_Help = new Button("help", img_main_Help);
    btn_main_AboutUs = new Button("About Us", img_main_AboutUs);
    btn_main_ContactUs = new Button("Contact Us", img_main_ContactUs);
    btn_main_Feedback = new Button("FeedBack", img_main_FeedBack);
    btn_main_Privacy = new Button("Privacy", img_main_Privacy);
    btn_main_Terms = new Button("Terms", img_main_Terms);
    btn_main_Exit = new Button("Exit", img_main_Exit);



    lbl_main_WishList.setTextPosition(Component.BOTTOM);
    lbl_main_WishList.setAlignment(Component.CENTER);
    lbl_main_WishList.getStyle().setMargin(0, 30, 0, 30);

    lbl_main_UpgradeApp = new Label("Upgrade");

    cmd_Exit = new Command("Exit", 1);
    cmd_Select = new Command("Select");


    GridLayout grd_MenuLayout = new GridLayout(4, 3);
    frm_Main.setTitle("Menu");
    frm_Main.setLayout(grd_MenuLayout);
    frm_Main.setScrollableY(true);



        //---- Add Button On Main Form
    frm_Main.addComponent(btn_main_Search);
    frm_Main.addComponent(btn_main_WishList);
    frm_Main.addComponent(btn_main_UpgradeApp);
    frm_Main.addComponent(btn_main_Login);
    frm_Main.addComponent(btn_main_NewUser);
    frm_Main.addComponent(btn_ma开发者_JAVA百科in_Help);
    frm_Main.addComponent(btn_main_AboutUs);
    frm_Main.addComponent(btn_main_ContactUs);
    frm_Main.addComponent(btn_main_Feedback);
    frm_Main.addComponent(btn_main_Terms);
    frm_Main.addComponent(btn_main_Privacy);
    frm_Main.addComponent(btn_main_Exit);

    frm_Main.addCommand(cmd_Select);
    frm_Main.addCommand(cmd_Exit);


    //frm_Main.setCommandListener(this);
    frm_Main.addCommandListener(this);
    frm_Main.show();
}

public void pauseApp() {}

public void destroyApp(boolean unconditional) {}

public void actionPerformed(ActionEvent ae)
{
    Command cmd = ae.getCommand();
    String strcmdName = cmd.getCommandName();
    if(strcmdName.equals("Exit"))
    {
        notifyDestroyed();
    }

    if (strcmdName.equals("Select"))
    {
        if(btn_main_Search.hasFocus())
        {
            //Dialog.show("Search", "Search", "Ok", null);
            Form frm_Search = new Form("Search");
            frm_Search.show();
        }


        if(btn_main_UpgradeApp.hasFocus())
        {

            Form UpgradeApp =  new Form("Upgrade App");
            UpgradeApp.show();
        }
    }
}
}

UpgradeApp.java

package com.sun.lwuit.jewelvicinity;


import com.sun.lwuit.Command;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.FlowLayout;

public class UpgradeApp extends Form implements ActionListener
{
Label lbl_UpgradeApp;
Command cmd_Yes, cmd_No;
Form frm_UpgradeApp;

public UpgradeApp()
{
    Display.init(this);
    frm_UpgradeApp = new Form("Upgrade Application");
    lbl_UpgradeApp = new Label("The New Version of Jewel.");
    cmd_Yes = new Command("Yes", 1);
    cmd_No = new Command("No", 2);

    FlowLayout flw_UpgradeLayout = new FlowLayout(CENTER);
    frm_UpgradeApp.setLayout(flw_UpgradeLayout);
    frm_UpgradeApp.addComponent(lbl_UpgradeApp);
    frm_UpgradeApp.addCommand(cmd_No);
    frm_UpgradeApp.addCommand(cmd_Yes);
    frm_UpgradeApp.addCommandListener(this);
    frm_UpgradeApp.setVisible(true);
    frm_UpgradeApp.show();
}

public void actionPerformed(ActionEvent evt)
{

}
}


From a brief review you seem to be calling Display.init(this); in a form subclass. I suggest you use a debugger and walk through the code.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号