|
|
| (6 intermediate revisions by 4 users not shown) |
| Line 1: |
Line 1: |
| [http://people.msoe.edu/~millerni/forums.php?show=topic&id=114&forum=13 online meridia] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=157&forum=13 wwe ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=128&forum=13 phentermine online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=158&forum=13 xanax online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=106&forum=13 hydrocodone online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=160&forum=13 cheap zanaflex] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=102&forum=13 free ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=97&forum=13 buy didrex] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=135&forum=13 free real ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=100&forum=13 fioricet online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=96&forum=13 diazepam online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=136&forum=13 cheap rivotril] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=87&forum=13 cheap ativan] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=144&forum=13 free sonyericsson ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=137&forum=13 free sagem ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=152&forum=13 verizon ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=139&forum=13 free sharp ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=125&forum=13 ortho online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=156&forum=13 cheap wellbutrin] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=151&forum=13 online valium] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=121&forum=13 cheap nexium] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=147&forum=13 free tracfone ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=142&forum=13 sony ericsson ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=94&forum=13 free cool ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=161&forum=13 zoloft] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=117&forum=13 free motorola ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=133&forum=13 qwest ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=138&forum=13 samsung ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=122&forum=13 nextel ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=89&forum=13 celexa online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=99&forum=13 free ericsson ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=115&forum=13 midi ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=146&forum=13 tenuate online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=109&forum=13 cheap levitra] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=82&forum=13 adipex online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=132&forum=13 punk ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=130&forum=13 cheap propecia] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=83&forum=13 albuterol online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=85&forum=13 alprazolam online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=153&forum=13 viagra online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=148&forum=13 tramadol online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=143&forum=13 sony ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=86&forum=13 ambien online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=103&forum=13 funny ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=104&forum=13 cheap hgh] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=129&forum=13 polyphonic ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=90&forum=13 cialis online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=123&forum=13 nokia ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=101&forum=13 cheap flexeril] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=124&forum=13 norco] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=149&forum=13 cheap ultracet] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=88&forum=13 cheap carisoprodol] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=108&forum=13 free kyocera ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=93&forum=13 cheap clonazepam] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=127&forum=13 pharmacy online online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=95&forum=13 cheap cyclobenzaprine] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=150&forum=13 cheap ultram] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=111&forum=13 lisinopril online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=159&forum=13 cheap xenical] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=162&forum=13 zyban online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=116&forum=13 free mono ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=112&forum=13 buy lorazepam] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=145&forum=13 sprint ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=110&forum=13 cheap lipitor] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=131&forum=13 order prozac] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=120&forum=13 music ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=105&forum=13 hoodia online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=155&forum=13 vigrx] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=98&forum=13 cheap diethylpropion] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=113&forum=13 but lortab] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=154&forum=13 cheap vicodin] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=119&forum=13 free mtv ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=84&forum=13 free alltel ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=141&forum=13 cheap soma] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=107&forum=13 jazz ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=140&forum=13 sildenafil online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=126&forum=13 cheap paxil] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=118&forum=13 free mp3 ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=92&forum=13 cheap clomid] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=91&forum=13 cingular ringtones] == Zombie Detector ==
| | == Zombie Detector == |
|
| |
|
| === Setup === | | === Setup === |
| Line 17: |
Line 17: |
| # Run your MIDlet | | # Run your MIDlet |
|
| |
|
| <pre>package src; | | <pre>/** |
| | * Simple Zombie Detector by Michael Sharon |
| | * |
| | * This program will allow a user to type in a sentence and detect if they are a zombie or not. |
| | */ |
|
| |
|
| | //import relevant libraries |
| import javax.microedition.midlet.*; | | import javax.microedition.midlet.*; |
| import javax.microedition.lcdui.*; | | import javax.microedition.lcdui.*; |
|
| |
|
| /**
| | public class ZombieDetector extends MIDlet implements CommandListener { |
| * Zombie Detector
| | |
| * @author Michael Sharon
| | //contains a reference to the display |
| *
| | private Display mDisplay; |
| * This program will allow a user to type in a sentence and detect if they are a zombie or not.
| |
| *
| |
| * Notice that we're implementing the CommandListener and Runnable. Read up on those two classes in the API docs.
| |
| * Runnable - http://uberthings.com/mobile/docs/midp1/java/lang/Runnable.html
| |
| * CommandListenter - http://uberthings.com/mobile/docs/midp1/javax/microedition/lcdui/CommandListener.html
| |
| */
| |
| public class ZombieDetector extends MIDlet implements CommandListener, Runnable { | |
|
| |
|
| //Create our variables
| | //these are the commands that we will use |
| | private Command mExitCommand, mDetectCommand, mCancelCommand; |
|
| |
|
| //Every MIDlet will always contain exactly one Display object
| | //high level user interface classes |
| //Display represents the device's display manager and input devices
| | private TextBox mSubmitBox; |
| private Display mDisplay;
| |
|
| |
|
| private Command mExitCommand, mDetectCommand, mCancelCommand; | | //constructor |
| | public ZombieDetector() { |
| | |
| | //create the commands that we'll be using |
| | mExitCommand = new Command("Exit", Command.EXIT, 0); |
| | mDetectCommand = new Command("Detect", Command.SCREEN, 0); |
| | mCancelCommand = new Command("Cancel", Command.CANCEL, 0); |
| | |
| | //create the textbox that we'll be using |
| | mSubmitBox = new TextBox("Zombie Detector", "Am I a Zombie?", 64, 0); |
| | mSubmitBox.addCommand(mExitCommand); |
| | mSubmitBox.addCommand(mDetectCommand); |
| | mSubmitBox.setCommandListener(this); |
| | } |
|
| |
|
| //Setting up the Textbox and Progress Forms (like the example in class)
| | //startApp is the very first thing run after the constructure |
| private TextBox mSubmitBox;
| | public void startApp() { |
| | //get a reference to the current display - usually the first thing you do |
| | mDisplay = Display.getDisplay(this); |
| | |
| | //display the submit screen |
| | mDisplay.setCurrent(mSubmitBox); |
| | } |
|
| |
|
| private Form mProgressForm;
| | //handles the MIDlet's paused state |
| | public void pauseApp() {} |
|
| |
|
| private StringItem mProgressString;
| | //cleans up when the MIDlet is destroyed |
| | public void destroyApp(boolean unconditional) {} |
|
| |
|
| //Field / Form style
| | //This gets called whenever we select a command |
| private TextField mSubmitField;
| | public void commandAction(Command c, Displayable s) { |
| | if (c == mExitCommand) { |
| | destroyApp(false); |
| | notifyDestroyed(); |
| | } |
| | else if (c == mDetectCommand) { |
| | //start searching for zombies |
| | zombieSearch(); |
| | } |
| | } |
|
| |
|
| private Form mDetectionForm;
| | //The function which searches for zombies at the phone |
| | | public void zombieSearch() { |
| public ZombieDetector() {
| | String word = mSubmitBox.getString(); |
| mExitCommand = new Command("Exit", Command.EXIT, 0);
| | String isZombie = null; |
| mDetectCommand = new Command("Detect", Command.SCREEN, 0);
| | int zombieCheck = 0; |
| | | |
| mSubmitBox = new TextBox("ZombieDetector", "Am I a Zombie?", 32, 0); | | //Check if we're dealing with a zombie |
| mSubmitBox.addCommand(mExitCommand); | | zombieCheck = word.indexOf("brains"); |
| mSubmitBox.addCommand(mDetectCommand); | | |
| mSubmitBox.setCommandListener(this);
| | //See API docs for String.indexOf |
| | | if (zombieCheck == -1) |
| mSubmitField = new TextField(
| | { |
| "Type a few words below to check if you are a zombie:",
| | isZombie = "This is a live one. No zombies here."; |
| "I am not a zombie.. honest..", 32, 0);
| |
| mDetectionForm = new Form("Zombie Detector"); | |
| mDetectionForm.addCommand(mExitCommand);
| |
| mDetectionForm.addCommand(mDetectCommand);
| |
| mDetectionForm.append(mSubmitField);
| |
| mDetectionForm.setCommandListener(this);
| |
| | |
| mProgressForm = new Form("Lookup progress");
| |
| mProgressString = new StringItem(null, null); | |
| mProgressForm.append(mProgressString);
| |
| }
| |
| | |
| public void startApp() {
| |
| mDisplay = Display.getDisplay(this);
| |
| | |
| //uncomment the mSubmitbox line below to run it like the example in class
| |
| //mDisplay.setCurrent(mSubmitBox); | |
| mDisplay.setCurrent(mDetectionForm);
| |
| | |
| }
| |
| | |
| public void pauseApp() {
| |
| }
| |
| | |
| public void destroyApp(boolean unconditional) {
| |
| }
| |
| | |
| //This is called whenever we select a command
| |
| public void commandAction(Command c, Displayable s) {
| |
| if (c == mExitCommand) { | |
| destroyApp(false);
| |
| notifyDestroyed();
| |
| } else if (c == mDetectCommand) { | |
| // Show the progress form. | |
| mDisplay.setCurrent(mProgressForm);
| |
| // Kick off the thread to do the query.
| |
| Thread t = new Thread(this);
| |
| t.start();
| |
| } | | } |
| }
| | else |
| | | { |
| /*
| | isZombie = "Eeek! Run for your lives!"; |
| * The run() method is automatically called when a new Thread is started.
| |
| *
| |
| */
| |
| public void run() {
| |
| | |
| //uncomment the line below if you want use the TextBox | |
| //String word = mSubmitBox.getString();
| |
| String word = mSubmitField.getString();
| |
| //System.out.println is useful for debugging and sending things to the console.
| |
| System.out.println("Got the String - " word);
| |
| String result;
| |
| | |
| result = checkForZombie(word);
| |
| | |
| //Place the result into an Alert
| |
| Alert results = new Alert("Result", result, null, null); | |
| results.setTimeout(Alert.FOREVER);
| |
| | |
| //Display the Alert, followed by the next Displayable - in this case our Form or Textbox
| |
| //Uncomment the line below to use the Textbox
| |
| //mDisplay.setCurrent(results, mSubmitBox);
| |
| mDisplay.setCurrent(results, mDetectionForm);
| |
| }
| |
| | |
| private String checkForZombie(String word) {
| |
| String isZombie = null;
| |
| int zombieCheck = 0;
| |
| | |
| //Check if we're dealing with a zombie
| |
| zombieCheck = word.indexOf("brain");
| |
| | |
| if (zombieCheck == -1) {
| |
| isZombie = "This is a live one. No zombies here.";
| |
| } else {
| |
| isZombie = "Eeek! Run for your lives!"; | |
| } | | } |
| | |
| | //Create a new alert |
| | Alert results = new Alert("Definition", isZombie,null, null); |
| | results.setTimeout(Alert.FOREVER); |
| | |
| | //Display the alert, then the submit field again |
| | mDisplay.setCurrent(results, mSubmitBox); |
| | } |
|
| |
|
| return isZombie;
| |
| }
| |
| } | | } |
Zombie Detector
Setup
- Create a new J2ME Midlet Suite in Eclipse by right-clicking in the Package Manager, selecting New -> Project -> J2ME Midlet Suite
- Call this ZombieDetector. Leave everything else as is.
- Right-click on your ZombieDetector project and select New -> Class
- Use src as your package and ZombieDetector as the class name. Click Finish.
- Open your new ZombieDetector class
- Cut and paste the code from below into your file. Save.
- Open up the ZombieDetector.jad file
- Click on the Midlets tab. Click Add.
- Write in ZombieDetector as the MIDlet name.
- Click in the button that appears in class. You may have to start typing Zombie in. It should find your class automatically. If nothing happens, try closing all the files down and opening them again.
- Right-click your project again, select Run As, then Run...
- Setup so that it looks something like this -

- Run your MIDlet
/**
* Simple Zombie Detector by Michael Sharon
*
* This program will allow a user to type in a sentence and detect if they are a zombie or not.
*/
//import relevant libraries
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class ZombieDetector extends MIDlet implements CommandListener {
//contains a reference to the display
private Display mDisplay;
//these are the commands that we will use
private Command mExitCommand, mDetectCommand, mCancelCommand;
//high level user interface classes
private TextBox mSubmitBox;
//constructor
public ZombieDetector() {
//create the commands that we'll be using
mExitCommand = new Command("Exit", Command.EXIT, 0);
mDetectCommand = new Command("Detect", Command.SCREEN, 0);
mCancelCommand = new Command("Cancel", Command.CANCEL, 0);
//create the textbox that we'll be using
mSubmitBox = new TextBox("Zombie Detector", "Am I a Zombie?", 64, 0);
mSubmitBox.addCommand(mExitCommand);
mSubmitBox.addCommand(mDetectCommand);
mSubmitBox.setCommandListener(this);
}
//startApp is the very first thing run after the constructure
public void startApp() {
//get a reference to the current display - usually the first thing you do
mDisplay = Display.getDisplay(this);
//display the submit screen
mDisplay.setCurrent(mSubmitBox);
}
//handles the MIDlet's paused state
public void pauseApp() {}
//cleans up when the MIDlet is destroyed
public void destroyApp(boolean unconditional) {}
//This gets called whenever we select a command
public void commandAction(Command c, Displayable s) {
if (c == mExitCommand) {
destroyApp(false);
notifyDestroyed();
}
else if (c == mDetectCommand) {
//start searching for zombies
zombieSearch();
}
}
//The function which searches for zombies at the phone
public void zombieSearch() {
String word = mSubmitBox.getString();
String isZombie = null;
int zombieCheck = 0;
//Check if we're dealing with a zombie
zombieCheck = word.indexOf("brains");
//See API docs for String.indexOf
if (zombieCheck == -1)
{
isZombie = "This is a live one. No zombies here.";
}
else
{
isZombie = "Eeek! Run for your lives!";
}
//Create a new alert
Alert results = new Alert("Definition", isZombie,null, null);
results.setTimeout(Alert.FOREVER);
//Display the alert, then the submit field again
mDisplay.setCurrent(results, mSubmitBox);
}
}