Created
September 4, 2014 10:44
-
-
Save shibafu528/1585ca42001ceb6baf09 to your computer and use it in GitHub Desktop.
昔作ったiアプリですね…ああ何もかも懐かしい
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.nttdocomo.ui.*; | |
import com.nttdocomo.util.*; | |
import java.lang.*; | |
public class PacketCalc extends IApplication { | |
MainCanvas c; | |
public void start() { | |
c = new MainCanvas(this); | |
Display.setCurrent((Frame)c); | |
} | |
public void resume() { | |
c.tm.start(); | |
} | |
} | |
class MainCanvas extends Canvas implements TimerListener{ | |
String in = "", out = ""; | |
int mode = 0, pake = 0; | |
public Timer tm; | |
private PacketCalc par; | |
final int PAKE_FOMA = 0; | |
final int PAKE_HO = 1; | |
final int PAKE_D2 = 2; | |
final int MODE_PKT = 0; | |
final int MODE_BYTE = 1; | |
final int MODE_KB = 2; | |
final int MODE_MB = 3; | |
MainCanvas(PacketCalc pr) { | |
par = pr; | |
setSoftLabel(SOFT_KEY_1, "END"); | |
setSoftLabel(SOFT_KEY_2, "."); | |
setBackground(Graphics.getColorOfName(Graphics.WHITE)); | |
tm = new Timer(); | |
tm.setTime(100); | |
tm.setRepeat(true); | |
tm.setListener((TimerListener)this); | |
tm.start(); | |
} | |
public void paint(Graphics g) { | |
g.lock(); | |
Font f = Font.getFont(Font.SIZE_SMALL); | |
g.setFont(f); | |
g.clearRect(0, 0, 240, 240); | |
g.setColor(Graphics.getColorOfName(Graphics.BLACK)); | |
g.drawRect(14,38,130,30); | |
g.drawString("通信料概算機",70,20); | |
g.drawLine(50,25,190,25); | |
g.drawString(in,20,60); | |
g.drawLine(1,144,68,144); | |
g.drawLine(167,144,239,144); | |
g.drawLine(1,230,239,230); | |
g.drawString("パケット単価",70,150); | |
g.drawString("FOMA通信料 (0.21 円)",22,180); | |
g.drawString("パケホーダイ ダブル (0.084 円)",22,200); | |
g.drawString("パケホーダイ ダブル2(0.0525円)",22,220); | |
switch (mode) { | |
case MODE_PKT: | |
g.drawString("パケット",172,61); | |
break; | |
case MODE_BYTE: | |
g.drawString("バイト",175,61); | |
break; | |
case MODE_KB: | |
g.drawString("KB",180,61); | |
break; | |
case MODE_MB: | |
g.drawString("MB",180,61); | |
break; | |
} | |
g.drawRect(8,90,240,25); | |
g.drawString(out,10,110); | |
g.setColor(Graphics.getColorOfName(Graphics.BLUE)); | |
g.drawString("▲",0,180); | |
g.drawString("▼",0,220); | |
g.drawString("←",150,60); | |
g.drawString("→",220,60); | |
g.drawString("(単位)",169,82); | |
switch (pake) { | |
case PAKE_FOMA: | |
g.drawRect(20,162,210,21); | |
break; | |
case PAKE_HO: | |
g.drawRect(20,182,210,21); | |
break; | |
case PAKE_D2: | |
g.drawRect(20,202,210,21); | |
break; | |
} | |
g.unlock(true); | |
} | |
public void processEvent(int type, int param) { | |
if (type == Display.KEY_RELEASED_EVENT) { | |
if (param == Display.KEY_SOFT1 | |
|| param == Display.KEY_IAPP | |
|| param == Display.KEY_CLEAR) { | |
if (in.equals("") && out.equals("")) | |
par.terminate(); | |
in = ""; | |
out = ""; | |
} | |
//入力文字数は15桁以内とする | |
if (in.length() < 15) { | |
if (param == Display.KEY_SOFT2) in += "."; | |
if (param == Display.KEY_1) in += "1"; | |
if (param == Display.KEY_2) in += "2"; | |
if (param == Display.KEY_3) in += "3"; | |
if (param == Display.KEY_4) in += "4"; | |
if (param == Display.KEY_5) in += "5"; | |
if (param == Display.KEY_6) in += "6"; | |
if (param == Display.KEY_7) in += "7"; | |
if (param == Display.KEY_8) in += "8"; | |
if (param == Display.KEY_9) in += "9"; | |
if (param == Display.KEY_0) in += "0"; | |
} | |
if (param == Display.KEY_UP) { | |
if (pake == 0) pake = 2; | |
else pake--; | |
} | |
if (param == Display.KEY_DOWN) { | |
if (pake == 2) pake = 0; | |
else pake++; | |
} | |
if (param == Display.KEY_LEFT) { | |
if (mode == 0) mode = 3; | |
else mode--; | |
} | |
if (param == Display.KEY_RIGHT) { | |
if (mode == 3) mode = 0; | |
else mode++; | |
} | |
if (param == Display.KEY_SELECT && !in.equals("") ) { | |
try { | |
double dat = Double.parseDouble(in); | |
double mny = 0; | |
int work = mode; | |
while(work > 1) { | |
dat = dat * 1024; | |
work--; | |
} | |
if (work == 1) dat = dat / 128; | |
switch (pake) { | |
case 0: | |
mny = 0.21 * dat; | |
break; | |
case 1: | |
mny = 0.084 * dat; | |
break; | |
case 2: | |
mny = 0.0525 * dat; | |
break; | |
} | |
out = ("→ " + String.valueOf(mny) + "円(税込)"); | |
} | |
catch (NumberFormatException ex1) { | |
out = "Syntax Error"; | |
} | |
} | |
if (!in.equals("") || !out.equals("")) setSoftLabel(SOFT_KEY_1, "クリア"); | |
else setSoftLabel(SOFT_KEY_1, "END"); | |
} | |
} | |
public void timerExpired(Timer source) { | |
repaint(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment