Permalink
Browse files

Bonus screen delete + README update

  • Loading branch information...
1 parent 6525a3a commit f3ab0f0f4eabb9178383f37f442d5e080d362473 @Dinduks committed Jul 31, 2011
Showing with 22 additions and 47 deletions.
  1. +6 −0 README
  2. +16 −47 src/LoveMeter/LoveMeter.java
  3. BIN src/LoveMeter/icon.jpg
View
6 README
@@ -0,0 +1,6 @@
+This J2ME application retuns the percentage of "love" between two names. It uses hashCode() method from String class to generate it, so the result will be always the same.
+This app is built using "Sun Java Wireless Toolkit 2.5.2_01 for CLDC ".
+I hope this app will help you to understand how do J2ME apps work. ;)
+
+Note:
+Why I chose a Love Meter? Because a friend of mine who develops in J2ME has already done one, and that was the first time I've thought about when I decided to create a J2ME app.
@@ -15,14 +15,12 @@
private Command exitCommand = new Command("Quitter", Command.EXIT, 0);
private Command okCommand = new Command("Ok", Command.OK, 0);
private Command backCommand = new Command("Retour", Command.BACK, 2);
- private Command bonusCommand = new Command("Bonus", Command.OK, 0);
private Form mainForm;
private Form results;
private Form bonus;
- private String instructions = "Bienvenue sur Love Meter! \n\n";
- private Image logo;
+ private String instructions = "Welcome to the Love Meter! \n\n";
private Image usPicture;
private String himValue;
@@ -31,10 +29,9 @@
private int pourcentage;
- private TextField himField = new TextField("Lui", null, 30, TextField.ANY);
- private TextField herField = new TextField("Elle", null, 30, TextField.ANY);
-
-
+ private TextField himField = new TextField("He", null, 30, TextField.ANY);
+ private TextField herField = new TextField("She", null, 30, TextField.ANY);
+
public Form showMainForm() {
if (mainForm == null) {
mainForm = new Form("Love Meter");
@@ -49,22 +46,22 @@ public Form showMainForm() {
}
public String getPResults(String himValue, String herValue) {
- descResults = "Le pourcentage d'amour entre ";
+ descResults = "Love percentage between ";
descResults += himValue.substring(0,1).toUpperCase() + himValue.substring(1);
- descResults += " et ";
+ descResults += " and ";
descResults += herValue.substring(0,1).toUpperCase() + herValue.substring(1);
- descResults += " est: \n";
+ descResults += " is: \n";
return descResults;
}
public int getPourcentage(String himValue, String herValue) {
// Here you can add special values depending of the "lovers" name ;)
- if ( ( himValue.equals("samy") || himValue.equals("dinduks") ) && (herValue.equals("nora") ) )
+ if (himValue.equals("samy") && (herValue.equals("nora")))
pourcentage = 666;
else
pourcentage = ( himValue.hashCode() + herValue.hashCode() ) % 100;
- if ( pourcentage < 0 )
+ if (pourcentage < 0)
pourcentage *= -1;
return pourcentage;
@@ -75,7 +72,7 @@ public Form showResults() {
herValue = herField.getString().toLowerCase();
if (results == null) {
- results = new Form("Résultats");
+ results = new Form("Results");
results.append( getPResults(himValue, herValue) );
@@ -88,45 +85,29 @@ public Form showResults() {
// Here you can add special text/screen depending
// of the percentage (and indirectly the lovers name) ;)
- if ( pourcentage == 666 ) {
+ if (pourcentage == 666) {
results.append("!");
results.append(getPicture());
results.append("\nI love you! <3 \n");
- //results.addCommand(bonusCommand);
}
return results;
}
-
- // Un écran bonus au cas où
- public Form showBonus() {
- if (bonus == null) {
- bonus = new Form("Bonus");
- bonus.append("I love you! <3");
- bonus.append(getPicture());
- bonus.addCommand(exitCommand);
- bonus.addCommand(backCommand);
- bonus.setCommandListener(this);
- }
- return bonus;
- }
-
public void commandAction(Command command, Displayable displayable) {
if (displayable == mainForm) {
if (command == exitCommand)
exitApp();
else if (command == okCommand)
- if( !himField.getString().equals("") && !herField.getString().equals("") )
+ if (!himField.getString().equals("") && !herField.getString().equals(""))
switchDisplayable(null, showResults());
} else if (displayable == results) {
if (command == exitCommand)
exitApp();
else if (command == backCommand) {
switchDisplayable(null, showMainForm());
results = null;
- } else if (command == bonusCommand)
- switchDisplayable(null, showBonus());
+ }
} else if ( displayable == bonus ) {
if (command == exitCommand)
exitApp();
@@ -151,12 +132,12 @@ public void switchDisplayable(Alert alert, Displayable nextDisplayable) {
}
public void exitApp() {
- switchDisplayable (null, null);
+ switchDisplayable(null, null);
destroyApp(true);
notifyDestroyed();
}
- public Display getDisplay () {
+ public Display getDisplay() {
return Display.getDisplay(this);
}
@@ -167,24 +148,12 @@ public void destroyApp(boolean unconditional) {
}
public Image getPicture() {
- if(usPicture == null) {
+ if (usPicture == null) {
try {
usPicture = Image.createImage("/LoveMeter/picture.jpg");
} catch (java.io.IOException e) {
}
}
return usPicture;
}
-
- /*public Image getLogo() {
- if(logo == null) {
- try {
- logo = Image.createImage("/splash.jpg");
- } catch (java.io.IOException e) {
- e.printStackTrace();
- }
- }
- return logo;
- }*/
-
}
View
Deleted file not rendered

0 comments on commit f3ab0f0

Please sign in to comment.