Codename One: Switch Form - codenameone

I tried a simple project with 2 forms: Login and MainMenu
I made GUI with Codename One design:
I checked in StateMachineBase class, I think it for LoginForm (the first form)
And now, I want to click on Login button it will open MainMenuForm, but I don't know how to do.
Can you help me, maybe some tutorial or simple sample.

You can look at this: http://www.codenameone.com/how-do-i---handle-eventsnavigation-in-the-gui-builder--populate-the-form-from-code.html it covers pretty much everything.
The state machine base shouldn't be modified. Just select the login button and do one of two things:
Click the Action Event button and then when you are sent to the Statemachine class where the callback method would be added you can just use code like:
showForm("MainMenuForm", null);
Alternatively you can select the Command property of the login button and select that it would be a navigation command that will lead you to the main menu form. This is done entirely in the GUI builder with no code required.

Related

Codename One nested Sidemenu

I am trying to create a nested side menu for a CN1 application, similar to the one in the screenshot.
For the nested sidemenu to work, I image it has to stay open when the user presses a command of a dropdown list , so that he/ she can choose an option.
But the CN1 sidemenu appears to close every time and I couldn't find a workaround.
One approach I was trying was to add an action event to the "hamburger menu ", but this doesn't seem to work.
Button sideBtn = (Button)((BorderLayout)bar.getLayout()).getEast();
sideBtn.addActionListener(new ActionListener(){
#Override
public void actionPerformed(ActionEvent evt) {
Toolbar.setPermanentSideMenu(true);
};
Neither does adding Toolbar.setPermanentSideMenu(true) to any other button's action event.
Anther approach I have in mind is to add hidden buttons to the sidemenu and repaint the toolbar when the button is clicked, but this still does not keep the sidemenu open and seems to be not very direct.
Is there anything more straightforward? What would be the best approach?
Thanks in advance for any kind response.
The setPermanentSideMenu method is designed for tablets and not for what you are trying to do. Toggling it after the init(Object) method was invoked doesn't make sense and might break your app.
You didn't list how you added the button to the side menu but adding it using addComponentToSideMenu(Component) should work (notice I didn't use the version that accepts a Command).

How to collapse a codename one accordion component programmatically?

How to collapse a codename one accordion component programmatically?
In my App, I have an accordion that expands a body container with some radio buttons. I want to collapse (Close) the body automatically when a radio button is selected.
Adding more details about the problem:
My intention is create a component that has same behavior of a ComboBox, but using Accodion component as base class.
I wrote a minimal use case that reproduce the problem and you can get its source file here MyApplication.java.This code implements Steve Hanna answer.I suppose. And it didn't work for me. Running this code is simple.
Just create a CodeName One project and replace the MyApplication.java file generated by CodeName One Wizard and run the project (I use Netbeans IDE).
I put inside Radio Button action the command to collapse the component as you can see at lines 271 til 280. But it didn't work.
In the radio button's action listener, check if it's not selected and then call collapse(bodyContainer) on the accordion.
EDIT: There was a bug in Accordion that caused collapse() to work incorrectly. This has now been fixed, and will be available in the next plugin update.
See this sample to see correct usage.
Note that after calling collapse(component), you should call the Accordion's animateLayout() method so that the change is shown.

codename one transfer data between forms without stateMachine

Hi I am new to codename one and i want to transfer some data between the button clicked on one form and then doing something on the show of the second form.
Any example will be really helpful as i am not able to find anything on the web which is not using the GUI builder.
Usually I just use member variables on the StateMachine class. E.g. when the button is clicked, store whatever data you need in member variables on the statemachine class. Then when the second form shows, you can access this data in the on show form callback.

In my Windows Phone app,I want to turn my current page unable in gray and show a textbox in foreground

Like the title said,how may i turn the grid(or page) and the components in it into background gray and unable and show a new component in foreground.
It's a common effect in the web page,but i cannot do that with a xaml.
Please answer in detail better with sample code if you do.Thanks in advance.
Here's an example of using a Popup to display a UserControl when a Page is navigated to. The OnNavigatedTo function creates a popup, binds a Click event to the UserControl, and then shows the UserControl over the entire page. If the correct password is entered, ("password" in the example) the control disappears. You'll need to modify it for your own requirements, but it should definitely get you started.
https://skydrive.live.com/redir.aspx?cid=ef08824b672fb5d8&resid=EF08824B672FB5D8!343
You'll want to use the VisualStateManager and create some animation transitions to switch between the old and new components. I won't paste the code here for brevity, but if you check out:
http://visualstudiomagazine.com/articles/2011/07/22/wcmob_visual-states.aspx
You'll see a simple example of switching between two UI components on a single page within a Windows Phone 7 PhoneApplicationPage. In your scenario, you'd use this paradigm to create 2 animation storyboards, one for showing an overlay control and one for settings the 'disabled' property on the main grid.

How can I make some functionality of my WinForm application accessible even if running a Modal Dialog?

I've got a "Main Window" containing quite a few things, including, in the status bar (at the very bottom of the window), a "Support" button, which the user can use at any time to open a window containing our support phone number, along with a little chat functionality if the user prefers to chat with us.
The problem is that if the program is displaying a modal dialog, the "support" button is not clickable anymore.
Stopping using modal dialogs is not an option ; I use them because I sometimes want to force the user into performing a specific task before I can do something else in the software.
What's the best way to let the user contact the support without having to close the current modal dialog?
Modal dialogs should behave as modal dialogs, the user won't expect to be able to click a button in the main window even if it were possible.
Your best bet is to put a support button on the dialog too.
Using a shortcut key instead of a button may be an option. The functionality could be factorized into a base form class like this :
public class BaseForm : Form
{
protected override bool ProcessDialogKey(Keys keyData)
{
if (keyData == Keys.F1)
{
SupportForm f = new SupportForm ();
f.Show();
}
return base.ProcessDialogKey(keyData);
}
}
Not using modal dialogs is an option. You can disable other parts of your interface during the required interaction to get whatever it is that you need out of the user.
The solution is to avoid situations where the user 'must' do something. Modal dialogs often get in the way if, for example, the user wants to quit the application right at that moment, or see something in a backgrounded window, or refer to another part of your application. Instead of using them, design your interaction so that if there is a required action/piece of information, it's folded into the application logic.
Think about website design -- modal dialogs are very rarely found on the web, and for good reason -- they disrupt the user's workflow unnecessarily. And yet plenty of sites have 'required' information.
Don't use modal dialogs; they are a shortcut to avoid a better design.

Resources