Note that there are some explanatory texts on larger screens.

plurals
  1. POLWUIT: Need help `Back` command is not working properly
    primarykey
    data
    text
    <p>We show a <em>SPLASH</em> screen using form which is followed with <em>MENU</em> form that holds many buttons like about-us, login, feedback etc. Now I move to <code>LOGIN</code> form that holds <code>menu</code> and <code>back</code> commands. My problem is when the <code>back</code> command is clicked in this form it goes to <code>SPLASH</code> screen.</p> <p>The expected behavior is the back command in <code>LOGIN</code> form must go back to <code>MENU</code> form and not <code>SPLASH</code> form.</p> <p>How to do this? </p> <p><strong>Splash.java</strong></p> <pre><code>public class Splash extends MIDlet implements ActionListener { Image img_Splash; Form frm_Main; String str_URL; int Width, Height; Label lbl_Splash; Command cmd_Cancel; public void startApp() { Display.init(this); frm_Main = new Form(); try { //Resources theme = Resources.open("/44444.res"); img_Splash = Image.createImage("/res/splash.png"); Resources theme = Resources.open("/666666.res"); UIManager.getInstance().setThemeProps( theme.getTheme(theme.getThemeResourceNames()[0])); } catch (IOException io) { io.printStackTrace(); Dialog.show("Theme Exception", io.getMessage(), "Ok", null); } lbl_Splash = new Label(img_Splash); lbl_Splash.getStyle().setBgColor(16777215); frm_Main.addComponent(lbl_Splash); frm_Main.setScrollable(true); cmd_Cancel = new Command("Cancel"); frm_Main.addCommand(cmd_Cancel); frm_Main.addCommandListener(this); frm_Main.show(); // th Thread splashThread = new Thread() { public void run() { try { sleep(5000); } catch (InterruptedException ex) { ex.printStackTrace(); } finally { MainMenu mainmenu = new MainMenu(frm_Main); mainmenu.show(); } } }; splashThread.start(); } public void pauseApp() { } public void destroyApp(boolean unconditional) { //notifyDestroyed(); } public void actionPerformed(ActionEvent ae) { Command con = ae.getCommand(); String str_CmdName = con.getCommandName(); if (str_CmdName.equals("Cancel")) { notifyDestroyed(); } } } </code></pre> <p><strong>Mainmenu.java</strong></p> <pre><code>class MainMenu extends Form implements ActionListener { Form frm_Main; //MainMidlet main; public Button btn_main_Login, btn_main_NewUser, btn_main_Help; public Label lbl_main_Login, lbl_main_NewUser, lbl_main_Help; public Image img_main_Login, img_main_NewUser, img_main_Help; public Command cmd_Exit, cmd_Select; public MainMenu(Form form) { this.frm_Main = form; try { 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"); } catch (IOException io) { io.printStackTrace(); //Dialog.show("Image not Found!", io.getMessage(), "Ok", null); System.out.println("Image not found" + io.getMessage()); } //--------- Whole form define as BorderLayout with three Container. BorderLayout bor_MainMenuLayout = new BorderLayout(); setLayout(bor_MainMenuLayout); setScrollable(false); //----------- Define Container for Header On North Container con_Header = new Container(); lbl_Header = new Label(img_Header); con_Header.addComponent(lbl_Header); //----------- Define Container as GridLayout and place //----------- on BorderLayout Center position //--------- Define Container(CENTER) for search details //--------- with BoxLayout BoxLayout bx_CenterLayout = new BoxLayout(BoxLayout.Y_AXIS); Container con_Center = new Container(bx_CenterLayout); con_Center.setScrollableY(true); con_Center.getStyle().setPadding(0, 10, 3, 3); //--------- FlowLayout for Header Details FlowLayout flw_MenuHdr = new FlowLayout(); Container con_HdrDetails = new Container(flw_MenuHdr); lbl_MenuHdr = new Label("Menu"); lbl_MenuHdr.getStyle().setBgTransparency(0); lbl_MenuHdr.getStyle().setPadding(0, 5, 10, 0); con_HdrDetails.addComponent(lbl_MenuHdr); con_Center.addComponent(con_HdrDetails); //---------- GridLayout define 1 rows and 3 coloumn //---------- First row GridLayout grd_Row1Layout = new GridLayout(1, 3); Container con_Row1Layout = new Container(grd_Row1Layout); btn_main_Login = new Button(img_main_Login); btn_main_Help = new Button(img_main_Help; btn_main_NewUser = new Button(img_main_NewUser); con_Row1Layout.addComponent(btn_main_Login); con_Row1Layout.addComponent(btn_main_Help); con_Row1Layout.addComponent(btn_main_NewUser); con_Center.addComponent(con_Row1Layout); //----------- Add Command on softkey cmd_Exit = new Command("Exit"); cmd_Select = new Command("Select"); addCommand(cmd_Select); addCommand(cmd_Exit); addCommandListener(this); addComponent(BorderLayout.NORTH, con_Header); addComponent(BorderLayout.CENTER, con_Center); //this.getStyle().setBgColor(12105912); frm_Main.getStyle().setBgColor(12105912); } public void actionPerformed(ActionEvent ae) { Command cmd = ae.getCommand(); String str_CmdName = cmd.getCommandName(); //----------- When Click on Exit Button if (str_CmdName.equals("Exit")) { //System.exit(0); //frm_Main.notifyAll(); } //----------- When Click on Select Button if (str_CmdName.equals("Select")) { //----------- When Click on Login if (btn_main_Login.hasFocus()) { String str_MemberId = GlobalClass.getInstance().getMemberId(); if (!(str_MemberId == "" || str_MemberId == null)) { SearchDiamond searchdiamond = new SearchDiamond(frm_Main); searchdiamond.setTransitionInAnimator( Transition3D.createRotation(800, true)); searchdiamond.show(); } else { Login login = new Login(frm_Main); login.setTransitionInAnimator( Transition3D.createRotation(800, true)); login.show(); } } //----------- When Click on New User if (btn_main_NewUser.hasFocus()) { //Dialog.show("New User", "NewUser", "Ok", null); NewUser newuser = new NewUser(frm_Main); //newuser.setTransitionInAnimator( CommonTransitions.createFade(1500)); newuser.setTransitionInAnimator( Transition3D.createRotation(800, true)); newuser.show(); } //----------- When Click on Help if (btn_main_Help.hasFocus()) { Help help = new Help(frm_Main); help.setTransitionInAnimator( Transition3D.createRotation(800, true)); help.show(); } //----------- When Click on Exit if (btn_main_Exit.hasFocus()) { System.exit(0); } } } } </code></pre> <p><strong>Login.java</strong></p> <pre><code>class Login extends Form implements ActionListener { Form frm_Main; Label lbl_Header, lbl_Footer, lbl_SepLine, lbl_HdrAlreadyMember, lbl_UserID, lbl_PWD, lbl_Blank2, lbl_Blank3, lbl_HdrNewMember, lbl_Info; TextField txtf_UserID, txtf_PWD; Button btn_Login; Command cmd_Back, cmd_AboutUs, cmd_Privacy; public Login(Form form) { this.frm_Main = form; //--------- Whole form define as BorderLayout with three Container. BorderLayout bor_LoginLayout = new BorderLayout(); setLayout(bor_LoginLayout); setScrollable(false); //--------- Define Container(NORTH) for Header. Container con_Header = new Container(); lbl_Header = new Label(); con_Header.addComponent(lbl_Header); //--------- Define Container(CENTER) for search details //--------- with BoxLayout BoxLayout bx_CenterLayout = new BoxLayout(BoxLayout.Y_AXIS); Container con_Center = new Container(bx_CenterLayout); con_Center.setScrollableY(true); con_Center.getStyle().setMargin(5, 5, 0, 0); //--------- FlowLayout for Header Details FlowLayout flw_HdrLayout = new FlowLayout(); Container con_HdrDetails = new Container(flw_HdrLayout); lbl_HdrAlreadyMember = new Label("Already a Member?"); lbl_HdrAlreadyMember.setAlignment(Component.LEFT); con_HdrDetails.addComponent(lbl_HdrAlreadyMember); con_Center.addComponent(con_HdrDetails); //--------- BoxLayout for Login details BoxLayout bx_Login1Layout = new BoxLayout(BoxLayout.Y_AXIS); Container con_Login1Details = new Container(bx_Login1Layout); con_Login1Details.setScrollableY(true); lbl_UserID = new Label("User Name:"); txtf_UserID = new TextField(""); txtf_UserID.setFocusable(true); txtf_UserID.setFocus(true); txtf_UserID.setConstraint(TextField.ANY); txtf_UserID.setInputMode("abc"); lbl_PWD = new Label("Password:"); txtf_PWD = new TextField(""); txtf_PWD.setConstraint(TextField.PASSWORD); con_Login1Details.addComponent(lbl_UserID); con_Login1Details.addComponent(txtf_UserID); con_Login1Details.addComponent(lbl_PWD); con_Login1Details.addComponent(txtf_PWD); //--------- BoxLayout for Login Button FlowLayout flw_LoginBtnLayout = new FlowLayout(CENTER); Container con_LoginBtnDetails = new Container( flw_LoginBtnLayout); con_LoginBtnDetails.setScrollableY(true); btn_Login = new Button("Login"); btn_Login.setPreferredSize(new Dimension(80, 25)); btn_Login.setAlignment(Component.CENTER); con_LoginBtnDetails.addComponent(btn_Login); con_Login1Details.addComponent(con_LoginBtnDetails); con_Center.addComponent(con_Login1Details); //--------- BoxLayout for other Login details BoxLayout bx_Login2Layout = new BoxLayout(BoxLayout.Y_AXIS); Container con_Login2Details = new Container(bx_Login2Layout); con_Login2Details.setScrollableY(true); con_Login2Details.getStyle().setMargin(5, 5, 10, 10); //--------- Login type 3 New Remember Me chk_RememberMe = new CheckBox("Remember Me"); chk_RememberMe.setTickerEnabled(false); con_Login2Details.addComponent(chk_RememberMe); //--------- Login type 3 New Forgot Password btn_ForgotPWD = new Button("Forgot Password?"); btn_ForgotPWD.setTickerEnabled(false); btn_ForgotPWD.setAlignment(Component.LEFT); btn_ForgotPWD.setTextPosition(Component.RIGHT); con_Login2Details.addComponent(btn_ForgotPWD); con_Center.addComponent(con_Login2Details); con_Center.getStyle().setPadding(0, 0, 10, 10); addComponent(BorderLayout.NORTH, con_Header); addComponent(BorderLayout.CENTER, con_Center); cmd_Back = new Command("Back"); this.setBackCommand(cmd_Back); addCommand(cmd_Back); addCommandListener(this); //---------- Add More Command for Menu item cmd_AboutUs = new Command("About Us"); cmd_Privacy = new Command("Privacy"); addCommand(cmd_AboutUs); addCommand(cmd_Privacy); //------- When Login Button is Clicked btn_Login.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { .... } }); } public void actionPerformed(ActionEvent ae) { Command con = ae.getCommand(); String str_CmdName = con.getCommandName(); if (str_CmdName.equals("Back")) { // here back code frm_Main.setTransitionInAnimator( Transition3D.createRotation(800, true)); frm_Main.showBack(); } .... if (str_CmdName.equals("About Us")) { AboutUs aboutus = new AboutUs(frm_Main); aboutus.show(); } if (str_CmdName.equals("Privacy")) { Privacy privacy = new Privacy(frm_Main); privacy.show(); } } } </code></pre> <p><strong>EDIT:</strong> Added the form's source code</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload