run j2me midlet as a foregorund process - java-me

I have got a problem with my MIDlet application.
Whenever I execute this MIDlet the emulator shows the error: 'This application does not use the screen, and runs in background'.
So far I know that we have to give the reference of the screen to the instance of the Display, for that I did this:
private Display display;
display = Display.getDisplay(this);
Still I am facing the above error.
please help me with this

Not only do you need to initialize the display you also need to set the current form:
mainForm= new Form("My Form");
display = Display.getDisplay(this);
display.setCurrent(mainForm);

Check your commandAction parameter for Displayable's variable.
If you give Displayable and Display the same variable, then you get the above error.
Often, Display and Displayable are given "d" as the variable name which causes a problem.

Related

Button handling and output (Wicket framework)

I have got a task to write a calculator on wicket and I have faced with some problems.
How to get button value(1,2,3...-,+,/,*) handle it(multiply or divide) and output a result to text field to user? Could you help me, please.
In swing it is really easy, e.g. new JtextField.setText("Shalom world!"); How I can do the same in wicket?
Thank you
Use a TextField, or Label, to display the calculator value. The model for the component should get an object that you update on each click of a button. A quick way to do this would be to create a member variable in your class that holds your total and use a PropertyModel to get the value of the member variable. If you are using AjaxLink, you will need to add the TextField to your target on click of each button and you need setOutputMarkupId to be true.

Using beforeShow in primefaces context menu is not working

I need to execute a metod before a <p:contextMenu> is displayed I was looking in the properties of the component and found beforeShow I'm not sure if I don't understand pretty well how this attribute works, but I tried to call the method with this
beforeShow="#{repositController.validate(item)}
and nothing happens when I do right click in the area, but the method is called once in the loading of the page.
The variable item come from the tree selection element. (IĀ“dont know if that matters)
My java method is
public void validate(String cat) {
this.name = cat;
}
PD the the context menu is working right I just have that problem to run a method after display it.
thanks in advance for your time and answers.

CUITe/Coded UI : mouse.Click position wrong (Screen resolutions)

I'm using CUITe to automate the testing of a UI piece (captured as a Page Object model).
I have a class that captures the buttons in my UI, like so:
class Navigators : CUITe_BrowserWindow
{
public new string sWindowTitle = "Window";
public CUITe_HtmlInputButton next = new CUITe_HtmlInputButton("Id=Content_btnNext");
// Other such buttons
//And a method to click any button
public void ClickButton(string id)
{
CUITe_BrowserWindow.GetBrowserWindow<Navigators>().Get<CUITe_HtmlInputButton>(string.Concat("Id=", id)).Click();
}
}
And the test I'm trying to automate is this, the click of a button:
CUITe_BrowserWindow.Launch<Navigators>("url");
CUITe_BrowserWindow.GetBrowserWindow<Navigators>().ClickButton("Content_btnNext");
My problem is this:
When I project my screen to a secondary monitor and extend it, the 'Next' button is clicked perfectly. However, on my system, the mouse passes over the button to another position and the click doesn't happen.
I have tried refreshing the CodedUI cache (by setting SearchConfiguration to Always), but that hasn't worked. Also, SetFocus on the control works correctly, whereas DrawHighlight shows the wrong position.
Any help would be greatly appreciated.
EDIT
When I changed my screen's resolution to 1440x900 (which is that of the secondary monitor's), the click happened.
I would be glad if someone could provide links that show how to handle screens of different resolutions in Coded UI
This is how I click controls on Win 8.1 store app which may or maynot be of help to you:
Mouse.Click(new Microsoft.VisualStudio.TestTools.UITest.Input.Point(uiControl.Left + (uiControl.Width / 2), uiControl.Top + (uiControl.Height / 2)));
Below is how I've been doing it in my CUITe scripts & it works fine at 1920x1080 on my larger monitor & at 1280x1024 on my laptop screen.
Given your OR definition above.
using Navigators.ObjectRepository; //guessing the name here
var pgNavigator = new Navigators();
//whatever else you do before clicking on next
Navigators.next.Click();

MonoTouch: How to update a view [duplicate]

I have a problem that the ViewWillAppear method for a UIView does not fire when the application returns from the background. This is a problem, as my main application screen is showing values that are retrieved from the user settings, and if the user has changed these while the application was in the background I need to have the screen refreshed. I have read that one should register for the UIApplicationWillEnterForegroundNotification using NSNotificationCenter.
How do you do this in MonoTouch? Or does anyone know an alternate way of ensuring that the screen is always kept up to date, even when returning from the background?
You could try something along the lines of:
//Register for the notification somewhere in the app
NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.WillEnterForegroundNotification, EnteredForeground);
//snip
void EnteredForeground (NSNotification notification)
{
// do your stuff here
}
Bear in mind you would need to do this for every view controller you'd like to update when enterting from the background!

Multiple consecutive alerts in Java ME

According to the documentation, Display.setCurrent doesn't work if the current displayable is an alert. This is a problem as I would like to pop up another alert when the user selects a command. Does anyone know how to work around this so that we can go from one alert to another? I am using CLDC 1.0 and MIDP 2.0.
Additional Information
The spec does allow us to edit an alert while it is on screen, but some Nokia phones don't handle it well at all. So I am now trying to go from the alert to a blank canvas, then back to the alert. Of course I don't want the user to interact with the previous canvas, so it seems that I am forced to create a new blank canvas. As a sidenote, this has the slight disadvantage of looking worse on phones which still have the previous screen when an alert is shown.
The bigger problem is how to transition from the blank canvas back to an alert once the canvas is loaded. Testing on the Motorola emulator revealed that showNotify is not called after returning from an alert to the previous screen. I guess I could create the next alert in the paint method, but this seems like a ugly hack.
OK, so your problem is that you can't set it up to do:
Display.setCurrent(alert1, alert2);
and
Display.setCurrent(alert2);
is also not possible if the current Displayable is already alert1.
So how about put an intermediate Displayable item that is blank and that immediately changes to the next alert? Assuming the current Displayable is alert1, like this in your alert1's command block:
Display.setCurrent(blankForm);
Display.setCurrent(alert2);
That should work assuming you are not using the default 'Dismiss' command. So basically it goes from alert1->(blankForm->alert2).
I couldn't find a way around this, so I just used the paint hack.
public class AlertPage extends Canvas{
MIDlet midlet;
Alert alert;
private AlertPage(MIDlet midlet){
this.midlet=midlet;
}
protected void paint(Graphics arg0){
//Yep, this is a hack, but showNotify doesn't seem to work well for Motorola
if(alert!=null){
Display d=Display.getDisplay(midlet);
d.setCurrent(alert);
alert=null;
}
}
public static void showAlert(MIDlet m, Alert a){
AlertPage page=new AlertPage(m);
Display d=Display.getDisplay(m);
page.alert=a;
d.setCurrent(page);
}
}

Resources