Skip to content

Commit

Permalink
Bonus screen delete + README update
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinduks committed Jul 31, 2011
1 parent 6525a3a commit f3ab0f0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 47 deletions.
6 changes: 6 additions & 0 deletions 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.
63 changes: 16 additions & 47 deletions src/LoveMeter/LoveMeter.java
Expand Up @@ -15,14 +15,12 @@ public class LoveMeter extends MIDlet implements CommandListener {
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;
Expand All @@ -31,10 +29,9 @@ public class LoveMeter extends MIDlet implements CommandListener {

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");
Expand All @@ -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;
Expand All @@ -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) );

Expand All @@ -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();
Expand All @@ -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);
}

Expand All @@ -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;
}*/

}
Binary file removed src/LoveMeter/icon.jpg
Binary file not shown.

0 comments on commit f3ab0f0

Please sign in to comment.