Skip to main content

Confirmation alert

7 replies [Last post]
javasol
Offline
Joined: 2003-06-13
Points: 0

Hi,

I have been researching for weeks how to create an alert that looks like a normal confirmation/info/warning/error alert. As far as I could tell the default Alert in J2ME like all other Forms display fullscreen. I cannot remember ever seeing an app that uses a full screen just for an alert. I tried using LWUIT but that has its own issues with BlackBerrys. Is there a way in J2ME to create a "normal" looking alert?

Any help will be greatly appreciated!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
javasol
Offline
Joined: 2003-06-13
Points: 0

Anyone know how to do this?

sfitzjava
Offline
Joined: 2003-06-15
Points: 0

What about making a custom component based on a Canvas and then you can just draw your own alert however you want it. You can even set the background to an image.
It's a little bit of work, but then you have what you want and not just what LCDUI or LWUIT gives you. LCDUI is ugly, and LWUIT requires a rewrite of your app within it.

There are 2 key things you need to to, 1) handle key actions so the user can cancel/ok out of the alert. 2) overwrite the paint(Graphics _gfx) method of canvas

The paint() would have something like:

_gfx.drawImage(bgImg,0,0,0); // paint some background image
_gfx.setColor(0xffffff); // set White fill color
int sizeW=getWidth()/4; // figure that your alert box will have a 1/4 screen margin
int sizeH =getHeight()/4;
_gfx.fillRect(sizeW,sizeH, sizeW*2, sizeH*2); // box will take up 1/2 screen dim
_gfx.drawString(,sizeW+5, sizeH+5); // put string with insets of 5

Get Jonathan Knudsen's book on KickButt MIDP2.0 and MSA (or something like that, I forget the exact title.) He has very good books for JavaME reference.

=Shawn

javasol
Offline
Joined: 2003-06-13
Points: 0

Thanks sfitzjava. I did create all this (without the image, just fillRect) but I wanted to know if I was missing something very obvious on how to create an alert that would automatically wrap text and scroll if there is to much text. On the plus side of having this, I have full control over where to put the buttons and what text should be on the buttons

Again its hard to imagine what the writes of J2ME where thinking when they decided that the alerts should have the look and feel that it currently has

jaywayjohan
Offline
Joined: 2008-06-18
Points: 0

I think that this is a limitation in the MIDP specification. The Alert class inherits from the Screen class, which uses the whole screen.

Regards
Johan

javasol
Offline
Joined: 2003-06-13
Points: 0

Thanks for your reply.

Is there a way to at least set the background of the screen part of the alert so that it should match all my other screens? By default I get a white screen and a box in the center with 2 buttons, what I would like to do is leave the box (the alert) the way it is and set the rest of the screen to mimick the theme of my app. This is on a BB, on other phones it looks even worse...

I have used different apps on my BB and on other phones, I don't remember seeing alerts like this. Is it that they did not use J2ME? or maybe there is a way to create a custom alert? I know LWUIT has a way of creating alerts that look better then the default alerts but as I mentioned earlier LWUIT doesn't work well with Blackberry's. Its frustrating to write a professional looking app and having the alerts make it look like a 5 year old wrote it!

jaywayjohan
Offline
Joined: 2008-06-18
Points: 0

I do not have any experience with Java ME development on BB. AFAIK there is no way to set the background part to match the other backgrounds.

I agree that the MIDP look very ugly on most phones and that it is frustrating as a developer.

Regards
Johan

javasol
Offline
Joined: 2003-06-13
Points: 0

Thank you Johan.

Is there anyone else out there that did somehow find a way to do this? All I need is a decent looking alert without having to have to use a completly new set of API's. i.e. LWUIT or J2ME polish