
求一个J2ME的手机计算器代码
求一个能在netbeans-5_0-windows-zh_CN.exe,netbeans_mobility-5_0-win-zh_CN.exe运行的J2ME的手机代码。...
求一个能在netbeans-5_0-windows-zh_CN.exe,netbeans_mobility-5_0-win-zh_CN.exe运行的J2ME的手机代码。
展开
1个回答
展开全部
package text2;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class MIDlet1 extends MIDlet {
static MIDlet1 instance;
Displayable1 displayable = new Displayable1();
public MIDlet1() {
instance = this;
}
public void startApp() {
Display.getDisplay(this).setCurrent(displayable);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public static void quitApp() {
instance.destroyApp(true);
instance.notifyDestroyed();
instance = null;
}
}
package text2;
import javax.microedition.lcdui.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2008</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Displayable1 extends Canvas {
public Displayable1() {
setFullScreenMode(true);
}
String[] numStr = {
"1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "0", "#"
};
String Str = "0";
int tem;
int keynum;
boolean clearFlag = true;
int oper; //第一次操作运算变量
int oper1 = 0; // = 后 两值 操作变量
protected void paint(Graphics g) {
g.setColor(0xffffff);
g.fillRect(0, 0, 176, 208);
g.setColor(0);
g.drawRect(5, 5, 160, 16); // 显示条
g.drawString(Str, 160, 10, 24); // 添加输入数字
g.drawArc(80, 25, 15, 15, 0, 360);
g.drawString("+", 88, 28, 17);
g.drawArc(60, 45, 15, 15, 0, 360);
g.drawString("*", 68, 48, 17);
g.drawRect(80, 45, 15, 15);
g.drawString("=", 88, 48, 17);
g.drawArc(100, 45, 15, 15, 0, 360);
g.drawString("/", 108, 48, 17);
g.drawArc(80, 65, 15, 15, 0, 360);
g.drawString("-", 88, 68, 17);
int index = 0;
for (int j = 0; j < 4; j++) { //数字键
for (int i = 0; i < 3; i++) {
g.drawRect(35 + 35 * i, 85 + 20 * j, 30, 15);
g.drawString(numStr[index++], 50 + 35 * i, 88 + 20 * j, 17);
}
}
}
public void update() {
}
public void input() {
switch (keynum) {
case -2: // -
oper = 2;
clearFlag = true;
calculate();
break;
case -1: // +
oper = 1;
clearFlag = true;
calculate();
break;
case -3: // *
oper = 3;
clearFlag = true;
calculate();
break;
case -4: // /
oper = 4;
clearFlag = true;
calculate();
break;
case -5: // =
oper = 5;
clearFlag = true;
calculate();
break;
case 42:
Str = "0";
break;
case 35:
Str = "0";
break;
}
if (keynum >= 48 && keynum <= 57) {
if (clearFlag) {
Str = ""; // 清空值
if (keynum == 48) {
clearFlag = true;
}
else {
clearFlag = false;
}
}
Str += getKeyName(keynum);
}
repaint();
}
public void keyPressed(int key) {
keynum = key;
input();
}
public void calculate() { //运算
try {
int num = Integer.parseInt(Str);
switch (oper) { // 给相应运算付值 oper1 是操作运算变量
case 1:
oper1 = 1;
tem = num; //保存第一个数
break;
case 2:
oper1 = 2;
tem = num;
break;
case 3:
oper1 = 3;
tem = num;
break;
case 4:
oper1 = 4;
tem = num;
break;
case 5 :
switch (oper1) { //判断运算
case 1:
tem = tem + num;
break;
case 2:
tem = tem - num;
break;
case 3:
tem = tem * num;
break;
case 4:
if (num != 0) {
tem = tem / num;
}
break;
}
}
}
catch (Exception e) {
tem = 0;
e.printStackTrace();
}
Str = String.valueOf(tem);
}
}
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class MIDlet1 extends MIDlet {
static MIDlet1 instance;
Displayable1 displayable = new Displayable1();
public MIDlet1() {
instance = this;
}
public void startApp() {
Display.getDisplay(this).setCurrent(displayable);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public static void quitApp() {
instance.destroyApp(true);
instance.notifyDestroyed();
instance = null;
}
}
package text2;
import javax.microedition.lcdui.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2008</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Displayable1 extends Canvas {
public Displayable1() {
setFullScreenMode(true);
}
String[] numStr = {
"1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "0", "#"
};
String Str = "0";
int tem;
int keynum;
boolean clearFlag = true;
int oper; //第一次操作运算变量
int oper1 = 0; // = 后 两值 操作变量
protected void paint(Graphics g) {
g.setColor(0xffffff);
g.fillRect(0, 0, 176, 208);
g.setColor(0);
g.drawRect(5, 5, 160, 16); // 显示条
g.drawString(Str, 160, 10, 24); // 添加输入数字
g.drawArc(80, 25, 15, 15, 0, 360);
g.drawString("+", 88, 28, 17);
g.drawArc(60, 45, 15, 15, 0, 360);
g.drawString("*", 68, 48, 17);
g.drawRect(80, 45, 15, 15);
g.drawString("=", 88, 48, 17);
g.drawArc(100, 45, 15, 15, 0, 360);
g.drawString("/", 108, 48, 17);
g.drawArc(80, 65, 15, 15, 0, 360);
g.drawString("-", 88, 68, 17);
int index = 0;
for (int j = 0; j < 4; j++) { //数字键
for (int i = 0; i < 3; i++) {
g.drawRect(35 + 35 * i, 85 + 20 * j, 30, 15);
g.drawString(numStr[index++], 50 + 35 * i, 88 + 20 * j, 17);
}
}
}
public void update() {
}
public void input() {
switch (keynum) {
case -2: // -
oper = 2;
clearFlag = true;
calculate();
break;
case -1: // +
oper = 1;
clearFlag = true;
calculate();
break;
case -3: // *
oper = 3;
clearFlag = true;
calculate();
break;
case -4: // /
oper = 4;
clearFlag = true;
calculate();
break;
case -5: // =
oper = 5;
clearFlag = true;
calculate();
break;
case 42:
Str = "0";
break;
case 35:
Str = "0";
break;
}
if (keynum >= 48 && keynum <= 57) {
if (clearFlag) {
Str = ""; // 清空值
if (keynum == 48) {
clearFlag = true;
}
else {
clearFlag = false;
}
}
Str += getKeyName(keynum);
}
repaint();
}
public void keyPressed(int key) {
keynum = key;
input();
}
public void calculate() { //运算
try {
int num = Integer.parseInt(Str);
switch (oper) { // 给相应运算付值 oper1 是操作运算变量
case 1:
oper1 = 1;
tem = num; //保存第一个数
break;
case 2:
oper1 = 2;
tem = num;
break;
case 3:
oper1 = 3;
tem = num;
break;
case 4:
oper1 = 4;
tem = num;
break;
case 5 :
switch (oper1) { //判断运算
case 1:
tem = tem + num;
break;
case 2:
tem = tem - num;
break;
case 3:
tem = tem * num;
break;
case 4:
if (num != 0) {
tem = tem / num;
}
break;
}
}
}
catch (Exception e) {
tem = 0;
e.printStackTrace();
}
Str = String.valueOf(tem);
}
}

2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询