Bonjour le Forum
J'ai une petite application pour mon mobile, bien pratique. (merci a Nouknouk pour son aide d’ailleurs) et le souhaite l'adapter pour mon nouveau mobile BlackBery Bold.
voici le code:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class CodeSAV2 extends MIDlet implements CommandListener {
private Display _display;
private TextField _textField1;
private TextField _textField2;
private Command _commandExit;
private Form _form1;
public CodeSAV2() {
_display = Display.getDisplay(this);
_form1 = new Form("Laurent HOJNACKI");
_commandExit = new Command("Exit", Command.SCREEN, 1);
// creation d'un champ de texte
_textField1 = new TextField("Date du jour: ", getDateInString(), 10, TextField.ANY);
_textField2 = new TextField("Code du jour: ", getCode(), 10, TextField.ANY);
_form1.addCommand(_commandExit);
_form1.append(_textField1);
_form1.append(_textField2);
_form1.setCommandListener(this);
}
public void startApp() {
_display.setCurrent(_form1);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == _commandExit) {
destroyApp(false);
notifyDestroyed();
}
}
public static String intToHexa(int units) {
if (units < 10) {
return String.valueOf(units);
} else if (units == 10) {
return "A";
} else if (units == 11) {
return "B";
} else if (units == 12) {
return "C";
} else if (units == 13) {
return "D";
} else if (units == 14) {
return "E";
} else if (units == 15) {
return "F";
} else {
return null;
}
}
public static String getDateInString() {
java.util.Calendar rightNow = java.util.Calendar.getInstance();
int day = rightNow.get(java.util.Calendar.DAY_OF_MONTH);
int month = rightNow.get(java.util.Calendar.MONTH) +1;
int year = rightNow.get(java.util.Calendar.YEAR);
return String.valueOf(day) + "/" + String.valueOf(month) + "/" + String.valueOf(year);
}
public static String getCode() {
java.util.Calendar rightNow = java.util.Calendar.getInstance();
int day = rightNow.get(java.util.Calendar.DAY_OF_MONTH);
int dayDozen = day / 10;
int dayUnits = day % 10;
int month = rightNow.get(java.util.Calendar.MONTH) +1;
int monthDozen = month / 10;
int monthUnits = month % 10;
int year = rightNow.get(java.util.Calendar.YEAR);
int yearMil = year / 1000;
int yearCents = (year % 1000) / 100;
int yearDozen = (year % 100) / 10;
int yearUnits = year % 10;
int hexa = dayDozen + dayUnits + monthDozen + monthUnits + yearMil + yearCents + yearDozen + yearUnits;
int hexaDozen = hexa / 16;
int hexaUnits = hexa % 16;
return String.valueOf(dayDozen) + String.valueOf(monthDozen) + " " + String.valueOf(dayUnits) + String.valueOf(monthUnits) + " " + intToHexa(hexaDozen) + intToHexa(hexaUnits);
}
}
Avec Eclipce et l'exemple de Hello world j'ai essayer de l'adapter sans succès:
package com.rim.samples.device.helloworlddemo;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.RichTextField;
/**
* This class extends the UiApplication class, providing a
* graphical user interface.
*/
public class HelloWorldDemo extends UiApplication
{
private Display _display;
private TextField _textField1;
private TextField _textField2;
private Command _commandExit;
private Form _form1;
public static String intToHexa(int units) {
if (units < 10) {
return String.valueOf(units);
} else if (units == 10) {
return "A";
} else if (units == 11) {
return "B";
} else if (units == 12) {
return "C";
} else if (units == 13) {
return "D";
} else if (units == 14) {
return "E";
} else if (units == 15) {
return "F";
} else {
return null;
}
}
public static String getDateInString() {
java.util.Calendar rightNow = java.util.Calendar.getInstance();
int day = rightNow.get(java.util.Calendar.DAY_OF_MONTH);
int month = rightNow.get(java.util.Calendar.MONTH) +1;
int year = rightNow.get(java.util.Calendar.YEAR);
return String.valueOf(day) + "/" + String.valueOf(month) + "/" + String.valueOf(year);
}
public static String getCode() {
java.util.Calendar rightNow = java.util.Calendar.getInstance();
int day = rightNow.get(java.util.Calendar.DAY_OF_MONTH);
int dayDozen = day / 10;
int dayUnits = day % 10;
int month = rightNow.get(java.util.Calendar.MONTH) +1;
int monthDozen = month / 10;
int monthUnits = month % 10;
int year = rightNow.get(java.util.Calendar.YEAR);
int yearMil = year / 1000;
int yearCents = (year % 1000) / 100;
int yearDozen = (year % 100) / 10;
int yearUnits = year % 10;
int hexa = dayDozen + dayUnits + monthDozen + monthUnits + yearMil + yearCents + yearDozen + yearUnits;
int hexaDozen = hexa / 16;
int hexaUnits = hexa % 16;
return String.valueOf(dayDozen) + String.valueOf(monthDozen) + " " + String.valueOf(dayUnits) + String.valueOf(monthUnits) + " " + intToHexa(hexaDozen) + intToHexa(hexaUnits);
}
/**
* Entry point for application
* @param args Command line arguments (not used)
*/
public static void main(String[] args)
{
// Create a new instance of the application and make the currently
// running thread the application's event dispatch thread.
HelloWorldDemo theApp = new HelloWorldDemo();
theApp.enterEventDispatcher();
}
/**
* Creates a new HelloWorldDemo object
*/
public HelloWorldDemo()
{
// Push a screen onto the UI stack for rendering.
pushScreen(new HelloWorldScreen());
}
}
/**
* A class extending the MainScreen class, which provides default standard
* behavior for BlackBerry GUI applications.
*/
final class HelloWorldScreen extends MainScreen
{
/**
* Creates a new HelloWorldScreen object
*/
HelloWorldScreen()
{
// Set the displayed title of the screen
setTitle("code");
// Add a read only text field (RichTextField) to the screen. The
// RichTextField is focusable by default. Here we provide a style
// parameter to make the field non-focusable.
add(new RichTextField("Code du jour!", Field.NON_FOCUSABLE));
}
/**
* Displays a dialog box to the user with the text "Goodbye!" when the
* application is closed.
*
* @see net.rim.device.api.ui.Screen#close()
*/
public void close()
{
// Display a farewell message before closing the application
Dialog.alert("bye!");
super.close();
}
}
Merci de votre aide
Wei_qi
Partager