Splash Screen in J2ME

Hello %abrowser%!

Disclaimer:


Just want to say that this article is intended for beginners and not for advanced gurus.

J2ME is dead... But no!

Information technology is rapidly evolving, with the arrival in our lives of smart phones, PDAs, and other innovations — people quickly began to forget about the phones, programming on J2ME silenced. With tears in my eyes, to my last breath, I want to believe that it is not. And it seems. tomorrow, you will see a new statistics — statistics where java 2 micro edition not inferior to anyone, and even on the contrary — is superior to numbers. Alas, perhaps this is just a dream.

I remember a time when the word "j2me" was on everyone's lips, and forums bent from the issues and ideas connected with j2me. It was and is truly a powerful technology! So for me it will remain.

Higher and higher rise sales statistics s device with an installed OS. Statistics is good, but if you can trust them to 100%? I for example can't, because every day I see a lot of tubes, people who can easily afford to buy an expensive Android or Apple products. But at least the subject use conventional phones, Samsung, Sony Ericsson, Nokia.
And to the question:
— "Why don't You buy it?"
Answer with pride:
— "I'm here and satisfied with everything".

However, the principle of "Only for calls" in my case is not working. Often see how friends in full strength use the simple functionality of the phone. When you need a quick recharge mobile yourself or family saw what I was doing this using WM Keeper Mobile. Also write down appointments, important dates, organizer works as it should. Read the news in the native RSS Reader e, Sending e-mails and even write in your Blogger blog. And it's true!

After these words I want to include classical music, access to favorite programming and NetBeans, programming and once again programming. The way we now do. And we write Splash Screen, the details under the cut...


I hope that all of the tools needed are already prepared to work? Then proceed!

SplashScreen Usually the first thing that the user sees on the screen (in our case a mobile phone). This is an image which appears while downloading programs/games. Usually the logo or just a picture with information. But this is not always the image, is that it's just a text or splash screen is absent. Some J2ME programmers claim that if the application does not have a "screen saver" — it is 25% failed project.

note: On the first run is already necessary to think seriously. Whatever You're posted — it's Your choice. But we should remember that this may depend on continue %excellent% work with the product or not. There is also a view. what if the user is delighted with the first run — even if in a little bit frighten UI it still comes back to this app. To keep the user should have the first run of the app, what do You think?


As already mentioned above — in Splash usually place a logo or information. But it is possible for example to incorporate thematic advertising generator, Your imagination. But it is necessary without fanaticism!
But as the great Hippocrates:
— "Noli nocere!"

Thus, the attack code. I suggest to make a simple Splash Screen, It will display a picture and will wait until we press any key. Classics so to speak.

HabraSplash.java

the
import javax.microedition.lcdui.*;

public class HabraSplash extends Canvas{
private int w,h; //screen Dimensions
private Image splash = null; // Our image
public Display Display;
//Constructor
public HabraSplash() {
setFullScreenMode(true); //Full screen mode 
w = getWidth();
h = getHeight();
// Try to load the image 
try {
splash = Image.createImage("/habra_splash.png");
} 
// If not - hang in perpetual Alert 
catch (Exception e) {
Alert a = new Alert("Error!", "Splash Screen image found!", null, AlertType.ERROR);

display.setCurrent(a);
}
}
// Draw our Splash Screen
protected void paint(Graphics g) {
g.drawImage(splash, w/2, h/2, 3);
}
// Do something here if the user clicked on any button
protected void keyPressed(int keyCode) {
System.out.println("Hello Habrahabr!");
}
}


Habra.java
the
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

Habra public class extends MIDlet {

public static Habra habra_midlet;
public static HabraSplash splash_screen;
public Display disp;


public Habra(){
habra_midlet = this;
splash_screen = new HabraSplash();
splash_screen.setFullScreenMode(true);
}

public void startApp() {
disp = Display.getDisplay(this);
disp.setCurrent(splash_screen);
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
}

Result:



And finally:


For a beginner, java programming very interesting and fun. Don't listen to anyone, the time spent is worth it! Study J2ME will give You knowledge of the OOP, will teach good control of memory and many other things.

It is only a primitive example. Next — interesting...

Says "Hungry" from Irkutsk:
— "Drink coffee, write Java!"


Goodbye.
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Integration of PostgreSQL with MS SQL Server for those who want faster and deeper

Custom database queries in MODx Revolution

Parse URL in Zend Framework 2