Initial import.

This commit is contained in:
Erik C. Thauvin 2004-10-01 01:19:12 +00:00
commit 33777ee43f
13 changed files with 635 additions and 0 deletions

6
.classpath Executable file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="J2MELIB"/>
<classpathentry kind="output" path="build"/>
</classpath>

3
.cvsignore Executable file
View file

@ -0,0 +1,3 @@
build
verified
deployed

2
.eclipseme Executable file
View file

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<eclipsemeMetadata platformDefinition="J2ME Wireless Toolkit 2.1 MIDP 2.0 Platform" version="0.5.0"/>

23
.project Executable file
View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>TipME</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>eclipseme.core.preverifier</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>eclipseme.core.nature</nature>
</natures>
</projectDescription>

10
TipME.jad Executable file
View file

@ -0,0 +1,10 @@
MIDlet-1: TipME,/tipme.png,net.thauvin.j2me.tipme.TipME
MIDlet-Jar-URL: TipME.jar
MIDlet-Icon: /tipme.png
MicroEdition-Configuration: CLDC-1.0
MIDlet-Version: 0.1.0
MIDlet-Vendor: Erik C. Thauvin
MIDlet-Name: TipME
MIDlet-Description: TipME
MIDlet-Info-URL: http://www.thauvin.net/erik/j2me/
MicroEdition-Profile: MIDP-2.0

49
build.xml Executable file
View file

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="TipME" default="build" basedir=".">
<taskdef resource="antenna.properties"/>
<property environment="env"/>
<property name="wtk.home" value="${env.WTK2_HOME}"/>
<property name="wtk.midp.version" value="2.0"/>
<property name="wtk.cldc.version" value="1.0"/>
<property name="path.build" value="build"/>
<property name="path.classes" value="${path.build}/classes"/>
<property name="path.src" value="src"/>
<property name="path.res" value="res"/>
<property name="path.deploy" value="deployed"/>
<target name="init">
<tstamp/>
<mkdir dir="${path.build}"/>
<mkdir dir="${path.deploy}"/>
</target>
<target name="compile" depends="init" description="Compiles sources">
<mkdir dir="${path.classes}"/>
<wtkbuild srcdir="${path.src}" destdir="${path.classes}" preverify="false"/>
</target>
<target name="jar" depends="compile" description="Builds the jar">
<copy todir="${path.deploy}" file="${ant.project.name}.jad"/>
<wtkpackage jarfile="${path.deploy}/${ant.project.name}.jar"
jadfile="${path.deploy}/${ant.project.name}.jad"
obfuscate="true"
preverify="true">
<fileset dir="${path.classes}"/>
<fileset dir="${path.res}" includes="*.png"/>
</wtkpackage>
</target>
<target name="run" description="Execute the program">
<wtkrun jadfile="${path.deploy}/${ant.project.name}.jad" device="DefaultColorPhone" wait="true"/>
</target>
<target name="build" depends="jar" description="Rebuilds project"/>
<target name="clean" depends="init" description="Removes classses and javadoc">
<delete quiet="true" includeEmptyDirs="true">
<fileset dir="${path.build}" includes="*,*/**"/>
</delete>
</target>
</project>

2
cmd.bat Executable file
View file

@ -0,0 +1,2 @@
@echo off
cmd.exe

BIN
res/tipme.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 B

View file

@ -0,0 +1,95 @@
/*
* @(#)MainScreen.java
*
* Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the authors nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id$
*
*/
package net.thauvin.j2me.tipme;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
/**
* The <code>MainScreen</code> class implements a form used to gather the data needed to calculate the tip.
*
* @author <a href="http://www.thauvin.net/erik/">Erik C. Thauvin</a>
* @version $Revision$, $Date$
*
* @created September 16, 2004
* @since 1.0
*/
public class MainScreen extends Form
{
/**
* The tip rate popup.
*/
protected /* final */ ChoiceGroup tipPopup;
/**
* The tax total field.
*/
protected /* final */ TextField taxFld;
/**
* The bill total field.
*/
protected /* final */ TextField totalFld;
/**
* Creates a new MainScreen object.
*
* @param midlet The MIDlet instance.
*/
public MainScreen(TipME midlet)
{
super(midlet.appName);
taxFld = new TextField("Tax Amount: ", midlet.taxAmount, 10, TextField.DECIMAL);
totalFld = new TextField("Bill Amount: ", midlet.totalAmount, 10, TextField.DECIMAL);
tipPopup =
new ChoiceGroup("Tip %:", ChoiceGroup.POPUP, new String[] { "5", "10", "15", "20", "25", "30" }, null);
tipPopup.setSelectedIndex(2, true);
append(taxFld);
append(totalFld);
append(tipPopup);
addCommand(midlet.aboutCommand);
addCommand(midlet.clearCommand);
addCommand(midlet.exitCommand);
addCommand(midlet.calcCommand);
setCommandListener(midlet);
}
}

View file

@ -0,0 +1,93 @@
/*
* @(#)ResultScreen.java
*
* Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the authors nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id$
*
*/
package net.thauvin.j2me.tipme;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
/**
* The <code>ResultScreen</code> class inplements the form used to display the results.
*
* @author <a href="http://www.thauvin.net/erik/">Erik C. Thauvin</a>
* @version $Revision$, $Date$
*
* @created September 16, 2004
* @since 1.0
*/
public class ResultScreen extends Form
{
/**
* The subtotal item.
*/
protected /* final */ StringItem subtotalItem = new StringItem("Subtotal:", "\n");
/**
* The tax item.
*/
protected /* final */ StringItem taxItem = new StringItem("Tax:", "\n");
/**
* The tip item.
*/
protected /* final */ StringItem tipItem = new StringItem("Tip:", "\n");
/**
* The total item.
*/
protected /* final */ StringItem totalItem = new StringItem("Total:", "");
/**
* Creates a new ResultForm object.
*
* @param midlet The MIDlet instance.
*/
public ResultScreen(TipME midlet)
{
super(midlet.appName);
append(subtotalItem);
append(taxItem);
append(tipItem);
append(totalItem);
addCommand(midlet.exitCommand);
addCommand(midlet.backCommand);
setCommandListener(midlet);
}
}

View file

@ -0,0 +1,336 @@
/*
* @(#)TipME.java
*
* Copyright (c) 2004, Erik C. Thauvin (http://www.thauvin.net/erik/)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the authors nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id$
*
*/
package net.thauvin.j2me.tipme;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
/**
* The <code>TipME</code> class implements a simple Tip calculator.
*
* @author <a href="http://www.thauvin.net/erik/">Erik C. Thauvin</a>
* @version $Revision$, $Date$
*
* @created September 16, 2004
* @since 1.0
*/
public class TipME extends MIDlet implements CommandListener
{
/**
* The application name.
*/
protected /* final */ String appName = "TipME";
/**
* The application version.
*/
protected /* final */ String appVersion = "0.1";
/**
* The <code>About</code> command.
*/
protected /* final */ Command aboutCommand = new Command("About", Command.SCREEN, 4);
/**
* The <code>Back</code> command.
*/
protected /* final */ Command backCommand = new Command("Back", Command.BACK, 2);
/**
* The <code>Calculate</code> command.
*/
protected /* final */ Command calcCommand = new Command("Calculate", Command.SCREEN, 2);
/**
* The <code>Clear</code> command.
*/
protected /* final */ Command clearCommand = new Command("Clear", Command.SCREEN, 3);
/**
* The <code>Exit</code> command.
*/
protected /* final */ Command exitCommand = new Command("Exit", Command.EXIT, 2);
/**
* The tax amount.
*/
protected String taxAmount;
/**
* The tip rate.
*/
protected String tipRate;
/**
* The total amount.
*/
protected String totalAmount;
private Display display;
/**
* DOCUMENT ME!
*/
private /* final */ MainScreen mainScreen;
/**
* DOCUMENT ME!
*/
private /* final */ ResultScreen resultScreen;
private int billTotal = 0;
private int subTotal = 0;
private int taxTotal = 0;
private int tipTotal = 0;
/**
* Creates a new TipME object.
*/
public TipME()
{
super();
mainScreen = new MainScreen(this);
resultScreen = new ResultScreen(this);
}
/**
* Performs a command.
*
* @param c The command action.
* @param d The diplayable screen.
*/
public void commandAction(Command c, Displayable d)
{
if (c == exitCommand)
{
exit();
}
else if (c == clearCommand)
{
mainScreen.taxFld.setString("");
mainScreen.totalFld.setString("");
display.setCurrentItem(mainScreen.taxFld);
}
else if (c == aboutCommand)
{
/* final */ Alert about =
new Alert("About " + appName,
appName + ' ' + appVersion + "\nCopyright 2004\nErik C. Thauvin\nerik@thauvin.net", null,
AlertType.INFO);
about.setTimeout(Alert.FOREVER);
display.setCurrent(about, d);
}
else if (c == calcCommand)
{
totalAmount = mainScreen.totalFld.getString();
taxAmount = mainScreen.taxFld.getString();
tipRate = mainScreen.tipPopup.getString(mainScreen.tipPopup.getSelectedIndex());
if ((totalAmount.length() == 0) || (totalAmount.charAt(0) == '0'))
{
error("Please specify a valid bill amount.", d);
}
else
{
calcTip();
resultScreen.subtotalItem.setText(getSubTotalAmount() + '\n');
resultScreen.taxItem.setText(getTaxAmount() + '\n');
resultScreen.tipItem.setText(getTipAmount() + " (" + tipRate + "%)\n");
resultScreen.totalItem.setText(getBillAmount());
display.setCurrent(resultScreen);
display.setCurrentItem(resultScreen.tipItem);
}
}
else if (c == backCommand)
{
display.setCurrent(mainScreen);
display.setCurrentItem(mainScreen.tipPopup);
}
}
/**
* Returns to total bill amount after tip.
*
* @return The bill amount.
*/
protected String getBillAmount()
{
return parseStr(billTotal);
}
/**
* Returns the subtotal amount after calculation.
*
* @return The subtotal amount.
*/
protected String getSubTotalAmount()
{
return parseStr(subTotal);
}
/**
* Returns the tax amount after calculation.
*
* @return the tax amount.
*/
protected String getTaxAmount()
{
if (taxTotal > 0)
{
return parseStr(taxTotal);
}
return "0.00";
}
/**
* Returns the tip amount after calculation.
*
* @return The tip amount.
*/
protected String getTipAmount()
{
return parseStr(tipTotal);
}
/**
* @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
*/
protected void destroyApp(boolean b)
throws MIDletStateChangeException
{
notifyDestroyed();
}
/**
* @see javax.microedition.midlet.MIDlet#pauseApp()
*/
protected void pauseApp()
{
;
}
/**
* @see javax.microedition.midlet.MIDlet#startApp()
*/
protected void startApp()
throws MIDletStateChangeException
{
display = Display.getDisplay(this);
display.setCurrent(mainScreen);
}
// Calulates the tip.
private void calcTip()
{
taxTotal = parseInt(taxAmount);
subTotal = parseInt(totalAmount) - taxTotal;
tipTotal = (subTotal * Integer.parseInt(tipRate)) / 100;
billTotal = subTotal + tipTotal + taxTotal;
if ((billTotal % 100) < 50)
{
while ((billTotal % 100) != 0)
{
tipTotal--;
billTotal = subTotal + tipTotal + taxTotal;
}
}
else
{
while ((billTotal % 100) != 0)
{
tipTotal++;
billTotal = subTotal + tipTotal + taxTotal;
}
}
}
// Displays an error dialog.
private void error(String msg, Displayable d)
{
/* final */ Alert error = new Alert("Error", msg, null, AlertType.ERROR);
error.setTimeout(Alert.FOREVER);
display.setCurrent(error, d);
}
// Exits the application.
private void exit()
{
try
{
destroyApp(false);
}
catch (MIDletStateChangeException e)
{
; // Do nothing
}
}
// Parses a given string to an int, the decimal point is removed.
private int parseInt(String s)
{
/* final */ int dec = s.lastIndexOf('.');
int len = s.length();
if (dec == -1)
{
return Integer.parseInt(s + "00");
}
else if (dec == (len - 1))
{
return Integer.parseInt(s.substring(0, dec) + "00");
}
else if (dec == (len - 2))
{
return Integer.parseInt(s.substring(0, dec) + s.substring(dec + 1) + '0');
}
else
{
return Integer.parseInt(s.substring(0, dec) + s.substring(dec + 1, dec + 3));
}
}
// Parse the given into to a string, the decimal point is added.
private String parseStr(int i)
{
/* final */ String s = String.valueOf(i);
return s.substring(0, s.length() - 2) + '.' + s.substring(s.length() - 2);
}
}

BIN
tipme.gif Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

16
tipme.wml Executable file
View file

@ -0,0 +1,16 @@
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<template>
<do type="prev" label="Back">
<prev/>
</do>
</template>
<card id="card1" title="TipME" newcontext="true">
<p align="center">
TipME 0.1 (5Kb)<br/>
<a href="TipME.jad">Download Jad</a><br/>
<a href="TipME.jar">Download Jar</a><br/>
</p>
</card>
</wml>