import java.util.Scanner;
融水ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18980820575(备注:SSL证书合作)期待与您的合作!
import java.awt.*;
import java.awt.event.*;
public class Test extends WindowAdapter {
Panel p1 = new Panel();
Panel p2 = new Panel();
Panel p3 = new Panel();
TextField txt;
private Button[] b = new Button[17];
private String ss[] = { "7", "8", "9", "+", "4", "5", "6", "-", "1", "2",
"3", "*", "clear", "0", "=", "/", "close" };
static double a;
static String s, str;// 定义变量 创建对像
public static void main(String args[]) {
(new Test()).frame();
}
public void frame() {
Frame fm = new Frame("简单计算器");
for (int i = 0; i = 16; i++) {
b[i] = new Button(ss[i]);
}
for (int i = 0; i = 15; i++) {
p2.add(b[i]);
} // 创建按钮 并添加到P2
b[16].setBackground(Color.yellow);
txt = new TextField(15);
txt.setEditable(false);
for (int i = 0; i = 16; i++) {
b[i].addActionListener(new buttonlistener());// 添加监听器
}
b[16].addActionListener(new close());
fm.addWindowListener(this);
fm.setBackground(Color.red);
p1.setLayout(new BorderLayout());
p1.add(txt, "North");
p2.setLayout(new GridLayout(4, 4));
p3.setLayout(new BorderLayout());
p3.add(b[16]);
fm.add(p1, "North");
fm.add(p2, "Center");
fm.add(p3, "South");
fm.pack();
fm.setVisible(true);// 都是些窗中设置 添加相关组件和监听器
}
public void windowClosing(WindowEvent e) {
System.exit(0);// 退出系统
}
class buttonlistener implements ActionListener {// 编写监听器事件 通过按键得出给果
public void actionPerformed(ActionEvent e) {
Button btn = (Button) e.getSource();
if (btn.getLabel() == "=") {
jisuan();
str = String.valueOf(a);
txt.setText(str);
s = "";
} else if (btn.getLabel() == "+") {
jisuan();
txt.setText("");
s = "+";
} else if (btn.getLabel() == "-") {
jisuan();
txt.setText("");
s = "-";
} else if (btn.getLabel() == "/") {
jisuan();
txt.setText("");
s = "/";
} else if (btn.getLabel() == "*") {
jisuan();
txt.setText("");
s = "*";
} else {
txt.setText(txt.getText() + btn.getLabel());
if (btn.getLabel() == "clear")
txt.setText("");
}
}
public void jisuan() {// 编写具体计算方法
if (s == "+")
a += Double.parseDouble(txt.getText());
else if (s == "-")
a -= Double.parseDouble(txt.getText());
else if (s == "*")
a *= Double.parseDouble(txt.getText());
else if (s == "/")
a /= Double.parseDouble(txt.getText());
else
a = Double.parseDouble(txt.getText());
}
}
}
class close implements ActionListener {// 退出
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
java EE是java企业级开发平台的意思,实在是看不出跟计算器这种小程序有什么关联。不知道楼主要找的是不是这个。
package ex1;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JTextField;
public class Calcutor extends JFrame {
private JTextField tf;
private JPanel panel1, panel2, panel3, panel4;
private JMenuBar myBar;
private JMenu menu1, menu2, menu3;
private JMenuItem editItem1, editItem2, help1, help2, help3;
private JRadioButtonMenuItem seeItem1, seeItem2;//单选框
private JCheckBoxMenuItem seeItem3;//复选框
private ButtonGroup bgb;
private String back;
private boolean IfResult = true, flag = false;
private String oper = "=";
private double result = 0;
private Num numActionListener;
private DecimalFormat df;
public Calcutor(){
super("科学计算器");//设置标题栏
df = new DecimalFormat("#.####");//保留四位小数
this.setLayout(new BorderLayout(10, 5));
panel1 = new JPanel(new GridLayout(1, 3, 10, 10));
panel2 = new JPanel(new GridLayout(5, 6, 5, 5));//5行6列
panel3 = new JPanel(new GridLayout(5, 1, 5, 5));
panel4 = new JPanel(new BorderLayout(5, 5));
/**
* 菜单栏
*/
myBar = new JMenuBar();
menu1 = new JMenu("编辑(E)");
menu2 = new JMenu("查看(V)");
menu3 = new JMenu("帮助(H)");
menu1.setFont(new Font("宋体", Font.PLAIN, 12));
menu2.setFont(new Font("宋体", Font.PLAIN, 12));
menu3.setFont(new Font("宋体", Font.PLAIN, 12));
/**
* 编辑栏
*/
editItem1 = new JMenuItem("复制(C) Ctrl+C");
editItem2 = new JMenuItem("粘贴(P) Ctrl+V");
editItem1.setFont(new Font("宋体",Font.PLAIN,12));
editItem2.setFont(new Font("宋体",Font.PLAIN,12));
/**
* 查看栏
*/
seeItem1 = new JRadioButtonMenuItem("科学型(T)");
seeItem2 = new JRadioButtonMenuItem("标准型(S)");
seeItem3 = new JCheckBoxMenuItem("数字分组(I)");
seeItem1.setFont(new Font("宋体",Font.PLAIN,12));
seeItem2.setFont(new Font("宋体",Font.PLAIN,12));
seeItem3.setFont(new Font("宋体",Font.PLAIN,12));
/**
* 帮助栏
*/
help1 = new JMenuItem("帮助主题(H)");
help2 = new JMenuItem("关于计算器(A)");
help1.setFont(new Font("宋体",Font.PLAIN,12));
help2.setFont(new Font("宋体",Font.PLAIN,12));
bgb = new ButtonGroup();//选项组
menu1.add(editItem1);
menu1.add(editItem2);
menu2.add(seeItem1);
menu2.add(seeItem2);
menu2.addSeparator();//添加一条分割线
menu2.add(seeItem3);
menu3.add(help1);
menu3.addSeparator();//添加一条分割线
menu3.add(help2);
myBar.add(menu1);
myBar.add(menu2);
myBar.add(menu3);
this.setJMenuBar(myBar);
numActionListener = new Num();//实现数字监听
/**
* 文本域,即为计算器的屏幕显示区域
*/
tf = new JTextField();
tf.setEditable(false);//文本区域不可编辑
tf.setBackground(Color.white);//文本区域的背景色
tf.setHorizontalAlignment(JTextField.RIGHT);//文字右对齐
tf.setText("0");
tf.setBorder(BorderFactory.createLoweredBevelBorder());
init();//对计算器进行初始化
}
/**
* 初始化操作
* 添加按钮
*/
private void init(){
addButton(panel1, "Backspace", new Clear(), Color.red);
addButton(panel1, "CE", new Clear(), Color.red);
addButton(panel1, "C", new Clear(), Color.red);
addButton(panel2, "1/x", new Signs(), Color.magenta);
addButton(panel2, "log", new Signs(), Color.magenta);
addButton(panel2, "7", numActionListener, Color.blue);
addButton(panel2, "8", numActionListener, Color.blue);
addButton(panel2, "9", numActionListener, Color.blue);
addButton(panel2, "÷", new Signs(), Color.red);
addButton(panel2, "n!", new Signs(), Color.magenta);
addButton(panel2, "sqrt", new Signs(), Color.magenta);
addButton(panel2, "4", numActionListener, Color.blue);
addButton(panel2, "5", numActionListener, Color.blue);
addButton(panel2, "6", numActionListener, Color.blue);
addButton(panel2, "×", new Signs(), Color.red);
addButton(panel2, "sin", new Signs(), Color.magenta);
addButton(panel2, "x^2", new Signs(), Color.magenta);
addButton(panel2, "1", numActionListener, Color.blue);
addButton(panel2, "2", numActionListener, Color.blue);
addButton(panel2, "3", numActionListener, Color.blue);
addButton(panel2, "-", new Signs(), Color.red);
addButton(panel2, "cos", new Signs(), Color.magenta);
addButton(panel2, "x^3", new Signs(), Color.magenta);
addButton(panel2, "0", numActionListener, Color.blue);
addButton(panel2, "-/+", new Clear(), Color.blue);
addButton(panel2, ".", new Dot(), Color.blue);
addButton(panel2, "+", new Signs(), Color.red);
addButton(panel2, "tan", new Signs(), Color.magenta);
addButton(panel2, "%", new Signs(), Color.magenta);
addButton(panel2, "π", numActionListener, Color.orange);
addButton(panel2, "e", numActionListener, Color.orange);
addButton(panel2, "′″", new Signs(), Color.orange);
addButton(panel2, "=", new Signs(), Color.red);
JButton btns = new JButton("计算器");
btns.setBorder(BorderFactory.createLoweredBevelBorder());
btns.setEnabled(false);//按钮不可操作
btns.setPreferredSize(new Dimension(20, 20));
panel3.add(btns);//加入按钮
addButton(panel3, "MC", null, Color.red);
addButton(panel3, "MR", null, Color.red);
addButton(panel3, "MS", null, Color.red);
addButton(panel3, "M+", null, Color.red);
panel4.add(panel1, BorderLayout.NORTH);
panel4.add(panel2, BorderLayout.CENTER);
this.add(tf, BorderLayout.NORTH);
this.add(panel3, BorderLayout.WEST);
this.add(panel4);
pack();
this.setResizable(false);//窗口不可改变大小
this.setLocation(300, 200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/**
* 统一设置按钮的的使用方式
* @param panel
* @param name
* @param action
* @param color
*/
private void addButton(JPanel panel, String name, ActionListener action, Color color){
JButton bt = new JButton(name);
panel.add(bt);//在面板上增加按钮
bt.setForeground(color);//设置前景(字体)颜色
bt.addActionListener(action);//增加监听事件
}
/**
* 计算器的基础操作(+ - × ÷)
* @param x
*/
private void getResult (double x){
if(oper == "+"){result += x;}
else if(oper == "-"){result -= x;}
else if(oper == "×"){result *= x;}
else if(oper == "÷"){result /= x;}
else if(oper == "="){result = x;}
tf.setText(df.format(result));
}
/**
* 运算符号的事件监听
*/
class Signs implements ActionListener{
public void actionPerformed(ActionEvent e) {
/*
* 用ActionEvent对象的getActionCommand()方法
* 取得与引发事件对象相关的字符串
*/
String str = e.getActionCommand();
/* sqrt求平方根 */
if(str.equals("sqrt")){
double i = Double.parseDouble(tf.getText());
if(i=0){
/*
* String.valueOf() 转换为字符串
* df.format() 按要求保留四位小数
* Math.sqrt() 求算数平方根
*/
tf.setText(String.valueOf(df.format(Math.sqrt(i))));
}
else{
tf.setText("负数不能开平方根");
}
}
/* log求常用对数 */
else if(str.equals("log")){
double i = Double.parseDouble(tf.getText());
if(i0){
tf.setText(String.valueOf(df.format(Math.log(i))));
}else{
tf.setText("负数不能求对数");
}
}
/* %求百分比 */
else if(str.equals("%")){
tf.setText(df.format(Double.parseDouble(tf.getText()) / 100));
}
/* 1/x求倒数 */
else if(str.equals("1/x")){
if(Double.parseDouble(tf.getText()) == 0){
tf.setText("除数不能为零");
}else{
tf.setText(df.format(1 / Double.parseDouble(tf.getText())));
}
}
/* sin求正弦函数 */
else if(str.equals("sin")){
double i = Double.parseDouble(tf.getText());
tf.setText(String.valueOf(df.format(Math.sin(i))));
}
/* cos求余弦函数 */
else if(str.equals("cos")){
double i = Double.parseDouble(tf.getText());
tf.setText(String.valueOf(df.format(Math.cos(i))));
}
/* tan求正切函数 */
else if(str.equals("tan")){
double i = Double.parseDouble(tf.getText());
tf.setText(String.valueOf(df.format(Math.tan(i))));
}
/* n!求阶乘 */
else if(str.equals("n!")){
double i = Double.parseDouble(tf.getText());
if((i%2==0)||(i%2==1))//判断为整数放进行阶乘操作
{
int j = (int)i;//强制类型转换
int result=1;
for(int k=1;k=j;k++)
result *= k;
tf.setText(String.valueOf(result));
}
else
{
tf.setText("无法进行阶乘");
}
}
/* x^2求平方 */
else if(str.equals("x^2")){
double i = Double.parseDouble(tf.getText());
tf.setText(String.valueOf(df.format(i*i)));
}
/* x^3求立方 */
else if(str.equals("x^3")){
double i = Double.parseDouble(tf.getText());
tf.setText(String.valueOf(df.format(i*i*i)));
}
/* ′″角度转换 */
/**
* 将角度值转换成弧度值,方便三角函数的计算
*/
else if(str.equals("′″")){
double i = Double.parseDouble(tf.getText());
tf.setText(String.valueOf(i/180*Math.PI));
}
else{
if(flag){
IfResult = false;
}
if(IfResult){
oper = str;
}else{
getResult(Double.parseDouble(tf.getText()));
oper = str;
IfResult = true;
}
}
}
}
/**
* 清除按钮的事件监听
*/
class Clear implements ActionListener{
public void actionPerformed(ActionEvent e) {
/*
* 用ActionEvent对象的getActionCommand()方法
* 取得与引发事件对象相关的字符串
*/
String str = e.getActionCommand();
if(str == "C"){
tf.setText("0");
IfResult = true;
result = 0;
}else if(str == "-/+"){
double i = 0 - Double.parseDouble(tf.getText().trim());
tf.setText(df.format(i));
}else if(str == "Backspace"){
if(Double.parseDouble(tf.getText()) 0){
if(tf.getText().length() 1){
tf.setText(tf.getText().substring(0, tf.getText().length() - 1));
//使用退格删除最后一位字符
}else{
tf.setText("0");
IfResult = true;
}
}else{
if(tf.getText().length() 2){
tf.setText(tf.getText().substring(0, tf.getText().length() - 1));
}else{
tf.setText("0");
IfResult = true;
}
}
}else if(str == "CE"){
tf.setText("0");
IfResult = true;
}
}
}
/**
* 数字输入的事件监听
*/
class Num implements ActionListener{
public void actionPerformed(ActionEvent e) {
String str = e.getActionCommand();
if(IfResult){
tf.setText("");
IfResult = false;
}
if(str=="π")
{
tf.setText(String.valueOf(Math.PI));
}
else if(str=="e")
{
tf.setText(String.valueOf(Math.E));
}
else{
tf.setText(tf.getText().trim() + str);
if(tf.getText().equals("0")){
tf.setText("0");
IfResult = true;
flag = true;
}
}
}
}
/**
* 小数点的事件监听
*/
class Dot implements ActionListener{
public void actionPerformed(ActionEvent e) {
IfResult = false;
if(tf.getText().trim().indexOf(".") == -1){
tf.setText(tf.getText() + ".");
}
}
}
/**
* main方法
*/
public static void main(String[] args) {
new Calcutor().setVisible(true);
}
}
//引入各种类文件
import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//定义JsqFrame继承Frame
class JsqFrame extends Frame {
double d1, d2; //定义两个double类型的变量
int op = -1; //定义两个int类型的变量
static TextField tf;//定义静态对象TextField
CalPanelL p1; //定义CalPanelL对象
// Constructor构造方法
JsqFrame() {
//以下设置属性
super("计算器");
setLayout(new FlowLayout());
setResizable(false);
setSize(250, 250);
tf = new TextField(18);
tf.setEditable(false);
tf.setBackground(Color.lightGray);
tf.setForeground(Color.red);
tf.setFont(new Font("Arial", Font.BOLD, 16));
add(tf);
p1 = new CalPanelL();
add(p1);
setVisible(true);
// addWindowListener(new Wclose());
}
//添加按钮继承Button类
class CalButton extends Button {
CalButton(String s) {
//设置按钮属性
super(s);
setBackground(Color.WHITE); //设置颜色为白色
}
}
//定义显示器继承Panel类
class CalPanelL extends Panel {
CalButton a, c, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, bPN, bPoint,
bAdd, bSub, bMul, bDiv, bL, bR, bLn, bEqual, bCE, bQuit;
CalPanelL() {
//设置显示器的属性
setLayout(new GridLayout(6, 4));
setFont(new Font("TimesRoman", Font.BOLD, 16));
a = new CalButton("");
c = new CalButton("");
b0 = new CalButton("0");
b1 = new CalButton("1");
b2 = new CalButton("2");
b3 = new CalButton("3");
b4 = new CalButton("4");
b5 = new CalButton("5");
b6 = new CalButton("6");
b7 = new CalButton("7");
b8 = new CalButton("8");
b9 = new CalButton("9");
bPN = new CalButton("+/-");
bPoint = new CalButton(".");
// 设置按钮
bAdd = new CalButton("+");
bSub = new CalButton("-");
bMul = new CalButton("*");
bDiv = new CalButton("/");
bL = new CalButton("(");
bR = new CalButton(")");
bLn = new CalButton("ln");
bEqual = new CalButton("=");
bCE = new CalButton("CE");
bQuit = new CalButton("退出");
// 加入按钮
add(a);
add(c);
add(bCE);
bCE.addActionListener(new PressBCE());
add(bQuit);
bQuit.addActionListener(new PressBQuit());
add(b7);
b7.addActionListener(new PressB7());
add(b8);
b8.addActionListener(new PressB8());
add(b9);
b9.addActionListener(new PressB9());
add(bDiv);
bDiv.addActionListener(new PressBDiv());
add(b4);
b4.addActionListener(new PressB4());
add(b5);
b5.addActionListener(new PressB5());
add(b6);
b6.addActionListener(new PressB6());
add(bMul);
bMul.addActionListener(new PressBMul());
add(b1);
b1.addActionListener(new PressB1());
add(b2);
b2.addActionListener(new PressB2());
add(b3);
b3.addActionListener(new PressB3());
add(bSub);
bSub.addActionListener(new PressBSub());
add(b0);
b0.addActionListener(new PressB0());
add(bPoint);
bPoint.addActionListener(new PressBPoint());
add(bPN);
bPN.addActionListener(new PressBPN());
;
add(bAdd);
bAdd.addActionListener(new PressBAdd());
add(bL);
bL.addActionListener(new PressBL());
add(bR);
bR.addActionListener(new PressBR());
add(bLn);
bLn.addActionListener(new PressBLn());
add(bEqual);
bEqual.addActionListener(new PressBEqual());
}
}
//定义PressBAdd实现ActionListener
//大体的意思是按计算机按键的时出发的时间,设置按键的监听[加号的监听事件]
class PressBAdd implements ActionListener {
public void actionPerformed(ActionEvent e) {
try {
String d1 = tf.getText();
op = 0;
tf.setText(d1 + "+");
} catch (Exception ee) {
}
}
}
//定义PressBSub实现ActionListener
//大体的意思是按计算机按键的时出发的时间,设置按键的监听[减号的监听事件]
class PressBSub implements ActionListener {
public void actionPerformed(ActionEvent e) {
try {
String d1 = tf.getText();
op = 1;
tf.setText(d1 + "-");
} catch (Exception ee) {
}
}
}
//定义PressBMul实现ActionListener
//大体的意思是按计算机按键的时出发的时间,设置按键的监听[乘号的监听事件]
class PressBMul implements ActionListener {
public void actionPerformed(ActionEvent e) {
try {
String d1 = tf.getText();
op = 2;
tf.setText(d1 + "*");
} catch (Exception ee) {
}
}
}
//定义PressBDiv实现ActionListener
//大体的意思是按计算机按键的时出发的时间,设置按键的监听[除号的监听事件]
class PressBDiv implements ActionListener {
public void actionPerformed(ActionEvent e) {
try {
String d1 = tf.getText();
op = 3;
tf.setText(d1 + "/");
} catch (Exception ee) {
}
}
}
//定义PressBL实现ActionListener
//大体的意思是按计算机按键的时出发的时间,设置按键的监听[向左键的监听事件]
class PressBL implements ActionListener {
public void actionPerformed(ActionEvent e) {
try {
String d1 = tf.getText();
op = 3;
tf.setText(d1 + "(");
} catch (Exception ee) {
}
}
}
//定义PressBR实现ActionListener
//大体的意思是按计算机按键的时出发的时间,设置按键的监听[向右键的监听事件]
class PressBR implements ActionListener {
public void actionPerformed(ActionEvent e) {
try {
String d1 = tf.getText();
op = 3;
tf.setText(d1 + ")");
} catch (Exception ee) {
}
}
}
//定义PressBEqual实现ActionListener
//大体的意思是按计算机按键的时出发的时间,设置按键的监听[等号的监听事件]
class PressBEqual implements ActionListener {
public void actionPerformed(ActionEvent e) {
try {
Jsq jsq = new Jsq();
String s = tf.getText();
System.out.println(s);
while (s.indexOf("(") + 1 0 s.indexOf(")") 0) {
String s1 = jsq.caculateHigh(s);
System.out.println(s1);
s = s1;
}
String str = jsq.cacluteMain(s);
System.out.println(str);
tf.setText(String.valueOf(str));
} catch (Exception ee) {
}
}
}
/*
* 批量写吧
* 以下是按1、2、3等等的监听事件
* 还有清零的等等监听事件
*/
class PressBLn implements ActionListener {
public void actionPerformed(ActionEvent e) {
try {
double x = Double.parseDouble(tf.getText());
double y;
y = Math.log10(x);
tf.setText(y + "");
} catch (Exception ee) {
}
}
}
class PressBCE implements ActionListener {
public void actionPerformed(ActionEvent e) {
tf.setText("");
}
}
class PressBPN implements ActionListener {
public void actionPerformed(ActionEvent e) {
try {
String text = tf.getText();
if (text != "") {
if (text.charAt(0) == '-')
tf.setText(text.substring(1));
else if (text.charAt(0) = '0' text.charAt(0) = '9')
tf.setText("-" + text.substring(0));
else if (text.charAt(0) == '.')
tf.setText("-0" + text.substring(0));
}
} catch (Exception ee) {
}
}
}
class PressBPoint implements ActionListener {
public void actionPerformed(ActionEvent e) {
String text = tf.getText();
if (text.lastIndexOf(".") == -1)
tf.setText(text + ".");
}
}
class PressB0 implements ActionListener {
public void actionPerformed(ActionEvent e) {
String text = tf.getText();
tf.setText(text + "0");
}
}
class PressB1 implements ActionListener {
public void actionPerformed(ActionEvent e) {
String text = tf.getText();
tf.setText(text + "1");
}
}
class PressB2 implements ActionListener {
public void actionPerformed(ActionEvent e) {
String text = tf.getText();
tf.setText(text + "2");
}
}
class PressB3 implements ActionListener {
public void actionPerformed(ActionEvent e) {
String text = tf.getText();
tf.setText(text + "3");
}
}
class PressB4 implements ActionListener {
public void actionPerformed(ActionEvent e) {
String text = tf.getText();
tf.setText(text + "4");
}
}
class PressB5 implements ActionListener {
public void actionPerformed(ActionEvent e) {
String text = tf.getText();
tf.setText(text + "5");
}
}
class PressB6 implements ActionListener {
public void actionPerformed(ActionEvent e) {
String text = tf.getText();
tf.setText(text + "6");
}
}
class PressB7 implements ActionListener {
public void actionPerformed(ActionEvent e) {
String text = tf.getText();
tf.setText(text + "7");
}
}
class PressB8 implements ActionListener {
public void actionPerformed(ActionEvent e) {
String text = tf.getText();
tf.setText(text + "8");
}
}
class PressB9 implements ActionListener {
public void actionPerformed(ActionEvent e) {
String text = tf.getText();
tf.setText(text + "9");
}
}
class PressBQuit implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
public void Js() {
String text = tf.getText();
tf.setText(text);
}
}
//////////////////////////这个很简单,方法也差不多////////////////////
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Calculator extends JFrame implements ActionListener
{
///////////////菜单
JMenuBar mb;
JMenu mEdit,mFind,mHelp;
JMenuItem mEditCopy,mEditPaste;
JMenuItem mFindStandarded,mFindScience,mFindGroup;
JMenuItem mHelpTopic,mHelpAbout;
JPanel pan;
/////////////按钮
JTextField tf;
JButton butnull;
JButton butBackspace,butCE,butC;
JButton butMC,butMR,butMS,butM;
JButton but1,but2,but3,but4,but5,but6,but7,but8,but9,but0;
JButton butChu,butSqrt,butCheng,butYu,butJian,but1x,butDot,butJia,butEqual,butJJ;
Calculator()
{
mb =new JMenuBar();
mEdit =new JMenu("编辑(E)");
mEdit.setMnemonic('E');
mFind =new JMenu("查看(F)");
mFind.setMnemonic('F');
mHelp =new JMenu("帮助(H)");
mFind.setMnemonic('H');
mEditCopy =new JMenuItem("复制(C)");
mEditCopy.setMnemonic('C');
mEditPaste =new JMenuItem("粘贴(P)");
mEditCopy.setMnemonic('P');
mFindStandarded=new JMenuItem("标准型(T)");
mFindStandarded.setMnemonic('T');
mFindScience=new JMenuItem("科学型(S)");
mFindScience.setMnemonic('S');
mFindGroup =new JMenuItem("数字分组(I)");
mFindGroup.setMnemonic('I');
mHelpTopic =new JMenuItem("帮助主题(H)");
mHelpTopic.setMnemonic('H');
mHelpAbout =new JMenuItem("关于我们(A)");
mHelpAbout.setMnemonic('A');
////////////////////////////添加mb组件beginning
mb.add(mEdit);
mb.add(mFind);
mb.add(mHelp);
mEdit.add(mEditCopy);
mEdit.add(mEditPaste);
mFind.add(mFindStandarded);
mFind.add(mFindScience);
mFind.add(mFindGroup);
mHelp.add(mHelpTopic);
mHelp.add(mHelpAbout);//////////////ending
////////////////////////***创建计算机按钮***////////////////////
Color red =new Color(250,0,0);
Color green =new Color(0,127,0);
butnull =new JButton("?");
butnull.setForeground(red);
butnull.addActionListener(this);
butBackspace =new JButton("Backspace");
butBackspace.setForeground(green);
butCE =new JButton("CE");
butCE.setForeground(green);
butC =new JButton("C");
butC.addActionListener(this);
butC.setForeground(red);
butMC =new JButton("MC");
butMC.setForeground(green);
butMR =new JButton("MR");
butMR.setForeground(green);
butMS =new JButton("MS");
butMS.setForeground(green);
butM =new JButton("M+");
butM.setForeground(green);
butChu =new JButton("/");
butChu.addActionListener(this);
butChu.setForeground(red);
butCheng =new JButton("*");
butCheng.addActionListener(this);
butCheng.setForeground(red);
butJian =new JButton("-");
butJian.addActionListener(this);
butJian.setForeground(red);
butJia =new JButton("+");
butJia.addActionListener(this);
butJia.setForeground(red);
butEqual =new JButton("=");
butEqual.addActionListener(this);
butEqual.setForeground(red);
Color blue =new Color(0,0,250);
butSqrt =new JButton("sqrt");
butSqrt.setForeground(green);
butYu =new JButton("%");
butYu.setForeground(green);
but1x =new JButton("1/x");
but1x.setForeground(green);
butDot =new JButton(".");
butDot.setForeground(blue);
butDot.addActionListener(this);
butJJ =new JButton("+/-");
butJJ.setForeground(blue);
butJJ.addActionListener(this);
but1 =new JButton("1");
but1.addActionListener(this);
but1.setForeground(blue);
but2 =new JButton("2");
but2.addActionListener(this);
but2.setForeground(blue);
but3 =new JButton("3");
but3.addActionListener(this);
but3.setForeground(blue);
but4 =new JButton("4");
but4.addActionListener(this);
but4.setForeground(blue);
but5 =new JButton("5");
but5.addActionListener(this);
but5.setForeground(blue);
but6 =new JButton("6");
but6.addActionListener(this);
but6.setForeground(blue);
but7 =new JButton("7");
but7.addActionListener(this);
but7.setForeground(blue);
but8 =new JButton("8");
but8.addActionListener(this);
but8.setForeground(blue);
but9 =new JButton("9");
but9.addActionListener(this);
but9.setForeground(blue);
but0 =new JButton("0");
but0.addActionListener(this);
but0.setForeground(blue);///////////////////////////////ending
pan =new JPanel(null);//创建最大的panel
tf =new JTextField("0");//输入显示框
tf.setBounds(5,0,337,25);//显示框设置大小位置
tf.setBackground(Color.white);
tf.setHorizontalAlignment(JTextField.RIGHT);//输入框设置位子居右显示
tf.setEditable(false);
JPanel pa=new JPanel(new BorderLayout());//所有按钮的panel
pa.setBounds(5,35,340,240);
JPanel pp=new JPanel(new BorderLayout());//null,MC,MR,MS,M+的panel;pa的西
JPanel aa=new JPanel(new BorderLayout());//其余所有Button的panel;pa的中
JPanel p =new JPanel(new GridLayout(4,1));//MC,MR,MS,M+的Panel,pp的中 北是一个butnull
JPanel a =new JPanel(new GridLayout(1,3));//backspace,ce,c的panel,aa的北
JPanel a2=new JPanel(new GridLayout(4,5));//其余的button的panel,aa的中
pa.add(pp,BorderLayout.WEST);
pa.add(aa,BorderLayout.CENTER);
pp.add(butnull,BorderLayout.NORTH);
pp.add(p,BorderLayout.CENTER);
p.add(butMC);
p.add(butMR);
p.add(butMS);
p.add(butM);
aa.add(a,BorderLayout.NORTH);
aa.add(a2,BorderLayout.CENTER);
a.add(butBackspace);
a.add(butCE);
a.add(butC);
a2.add(but7);
a2.add(but8);
a2.add(but9);
a2.add(butChu);
a2.add(butSqrt);
a2.add(but4);
a2.add(but5);
a2.add(but6);
a2.add(butCheng);
a2.add(butYu);
a2.add(but1);
a2.add(but2);
a2.add(but3);
a2.add(butJian);
a2.add(but1x);
a2.add(but0);
a2.add(butJJ);
a2.add(butDot);
a2.add(butJia);
a2.add(butEqual);
this.add(pan);
pan.add(tf);
pan.add(pa);
this.setTitle("我的计算器");
this.setJMenuBar(mb);
this.setBounds(200,300,353,330);//设置窗口大小
this.setResizable(false);
this.setVisible(true);
}
public static void main(String args[])
{
try
{
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
}
catch (Exception ex)
{
ex.printStackTrace();
}
new Calculator();
}
////////////////////********以下是监听设置和运算*******///////////////////
boolean b=true;//初始值设置为真未点运算符号
String fuhao="";//保存最后一次运算符号,用于进行上次结果的运算
String lastCommand="";//保存按等号前的最后的运算符号
double lastValue=0.0;//保存按等号钱的最后的输入框里的值
double value=0.0;//原值,当你点完运算符的时候计算之前的值
double fuzhi=0.0;
public void actionPerformed(ActionEvent click)/////////////////////行为监听设置
{
if(click.getSource()==butJJ)
{
fuzhi=Double.parseDouble(tf.getText());
if(tf.getText().equals("0")||tf.getText().equals("0."))
{
boolean b=true;
String fuhao="";
double value=0.0;
tf.setText("0");
}
else if(fuzhi0)
{
tf.setText((-fuzhi)+"");
}
else
{
tf.setText("-"+tf.getText());
}
}
if(click.getSource()==butnull)
{
tf.setText("本计算器版权所有归青软培训--胡迅--2008年10月18日著 ");
}
if(click.getSource()==butC)
{
tf.setText("0");
lastCommand="";
lastValue=0.0;
b=true;
fuhao="";
value=0.0;
}
if(click.getSource()==but1)
{
if(b==false)
{
tf.setText("1");
b=true;
}
else if(tf.getText().equals("0"))
{
tf.setText("1");
}
else
{
tf.setText(tf.getText()+1);
}
}
if(click.getSource()==but2)
{
if(b==false)
{
tf.setText("2");
b=true;
}
else if(tf.getText().equals("0"))
{
tf.setText("2");
}
else
{
tf.setText(tf.getText()+2);
}
}
if(click.getSource()==but3)
{
if(b==false)
{
tf.setText("3");
b=true;
}
else if(tf.getText().equals("0"))
{
tf.setText("3");
}
else
{
tf.setText(tf.getText()+3);
}
}
if(click.getSource()==but4)
{
if(b==false)
{
tf.setText("4");
b=true;
}
else if(tf.getText().equals("0"))
{
tf.setText("4");
}
else
{
tf.setText(tf.getText()+4);
}
}
if(click.getSource()==but5)
{
if(b==false)
{
tf.setText("5");
b=true;
}
else if(tf.getText().equals("0"))
{
tf.setText("5");
}
else
{
tf.setText(tf.getText()+5);
}
}
if(click.getSource()==but6)
{
if(b==false)
{
tf.setText("6");
b=true;
}
else if(tf.getText().equals("0"))
{
tf.setText("6");
}
else
{
tf.setText(tf.getText()+6);
}
}
if(click.getSource()==but7)
{
if(b==false)
{
tf.setText("7");
b=true;
}
else if(tf.getText().equals("0"))
{
tf.setText("7");
}
else
{
tf.setText(tf.getText()+7);
}
}
if(click.getSource()==but8)
{
if(b==false)
{
tf.setText("8");
b=true;
}
else if(tf.getText().equals("0"))
{
tf.setText("8");
}
else
{
tf.setText(tf.getText()+8);
}
}
if(click.getSource()==but9)
{
if(b==false)
{
tf.setText("9");
b=true;
}
else if(tf.getText().equals("0"))
{
tf.setText("9");
}
else
{
tf.setText(tf.getText()+9);
}
}
if(click.getSource()==but0)
{
if(b==false)
{
tf.setText("0");
b=true;
}
else if(tf.getText().equals("0"))
{
tf.setText("0");
}
else
{
tf.setText(tf.getText()+0);
}
}
if(click.getSource()==butDot)
{
/////////code/////////////////////////////////////////////////////////////////////////////////////////////////////////???
int izhi=Integer.parseInt(tf.getText());
double dzhi=Double.parseDouble(tf.getText());
if(tf.getText().equals("0"))
{
tf.setText("0.");
}
else
{
if(tf.getText().equals("0."))
{
tf.setText("0.");
}
else
{
if(dzhi0)
{
izhi=izhi;
dzhi=dzhi;
if(dzhi==izhi)
{
tf.setText(tf.getText()+".");
}
}
else
{
izhi=-izhi;
dzhi=-dzhi;
if(dzhi==izhi)
{
tf.setText(tf.getText()+".");
}
}
}
}
}
if(click.getSource()==butJia)///////////////////////////////////////////////"+"
{
if(tf.getText().equals("0"))
{
}
else if(fuhao=="")
{
double tfvaluejia;
tfvaluejia=Double.parseDouble(tf.getText());
value=tfvaluejia;
tf.setText(""+value);
b=false;
fuhao="+";
}
else if(fuhao=="*")
{
double tfvalueCheng;
tfvalueCheng=Double.parseDouble(tf.getText());
value=value*tfvalueCheng;
tf.setText(""+value);
b=false;
}
else if(fuhao=="/")
{
double tfvalueChu;
tfvalueChu=Double.parseDouble(tf.getText());
value=value/tfvalueChu;
tf.setText(""+value);
b=false;
}
else if(fuhao=="-")
{
double tfvaluejian;
tfvaluejian=Double.parseDouble(tf.getText());
value=value-tfvaluejian;
tf.setText(""+value);
b=false;
}
else if(fuhao=="=")
{
double tfvaluejia;
tfvaluejia=Double.parseDouble(tf.getText());
value=tfvaluejia;
b=false;
}
else
{
double tfvaluejia;
tfvaluejia=Double.parseDouble(tf.getText());//2
value=value+tfvaluejia;
tf.setText(""+value);
b=false;
}
lastValue=Double.parseDouble(tf.getText());
fuhao="+";
lastCommand="+";
}
if(click.getSource()==butCheng)////////////////////////////////////////////////////////////"*"
{
if(tf.getText().equals("0"))
{
}
else if(fuhao=="")
{
double tfvalueCheng;
tfvalueCheng=Double.parseDouble(tf.getText());
value=tfvalueCheng;
tf.setText(""+value);
b=false;
fuhao="*";
}
else if(fuhao=="+")
{
double tfvaluejia;
tfvaluejia=Double.parseDouble(tf.getText());
value=value+tfvaluejia;
tf.setText(""+value);
b=false;
}
else if(fuhao=="/")
{
double tfvalueChu;
tfvalueChu=Double.parseDouble(tf.getText());
value=value/tfvalueChu;
tf.setText(""+value);
b=false;
}
else if(fuhao=="-")
{
double tfvaluejian;
tfvaluejian=Double.parseDouble(tf.getText());
value=value-tfvaluejian;
tf.setText(""+value);
b=false;
}
else if(fuhao=="=")
{
double tfvalueCheng;
tfvalueCheng=Double.parseDouble(tf.getText());
value=tfvalueCheng;
b=false;
}
else
{
double tfvalueCheng;
tfvalueCheng=Double.parseDouble(tf.getText());
value=value*tfvalueCheng;
tf.setText(""+value);
b=false;
}
lastValue=Double.parseDouble(tf.getText());
fuhao="*";
lastCommand="*";
}
if(click.getSource()==butChu)//////////////////////////////////////////////"/"
{
if(tf.getText().equals("0"))
{
}
else if(fuhao=="")
{
double tfvalueChu;
tfvalueChu=Double.parseDouble(tf.getText());
value=tfvalueChu;
tf.setText(""+value);
b=false;
fuhao="/";
}
else if(fuhao=="+")
{
double tfvaluejia;
tfvaluejia=Double.parseDouble(tf.getText());
value=value+tfvaluejia;
tf.setText(""+value);
b=false;
}
else if(fuhao=="*")
{
double tfvalueCheng;
tfvalueCheng=Double.parseDouble(tf.getText());
value=value*tfvalueCheng;
tf.setText(""+value);
b=false;
}
else if(fuhao=="-")
{
double tfvaluejian;
tfvaluejian=Double.parseDouble(tf.getText());
value=value-tfvaluejian;
tf.setText(""+value);
b=false;
}
else if(fuhao=="=")
{
double tfvalueCheng;
tfvalueCheng=Double.parseDouble(tf.getText());
value=tfvalueCheng;
b=false;
}
else
{
double tfvalueChu;
tfvalueChu=Double.parseDouble(tf.getText());
value=value/tfvalueChu;
tf.setText(""+value);
b=false;
}
lastValue=Double.parseDouble(tf.getText());
fuhao="/";
lastCommand="/";
}
if(click.getSource()==butJian)////////////////////////////////////////////////////////////////////////"-"
{
if(tf.getText().equals("0"))
{
}
else if(fuhao=="")
{
double tfvaluejian;
tfvaluejian=Double.parseDouble(tf.getText());
value=tfvaluejian;
tf.setText(""+value);
b=false;
fuhao="/";
}
else if(fuhao=="+")
{
double tfvaluejia;
tfvaluejia=Double.parseDouble(tf.getText());
value=value+tfvaluejia;
tf.setText(""+value);
b=false;
}
else if(fuhao=="*")
{
double tfvalueCheng;
tfvalueCheng=Double.parseDouble(tf.getText());
value=value*tfvalueCheng;
tf.setText(""+value);
b=false;
}
else if(fuhao=="/")
{
double tfvalueChu;
tfvalueChu=Double.parseDouble(tf.getText());
value=value/tfvalueChu;
tf.setText(""+value);
b=false;
}
else if(fuhao=="=")
{
double tfvalueCheng;
tfvalueCheng=Double.parseDouble(tf.getText());
value=tfvalueCheng;
b=false;
}
else
{
double tfvaluejian;
tfvaluejian=Double.parseDouble(tf.getText());
value=value-tfvaluejian;
tf.setText(""+value);
b=false;
}
lastValue=Double.parseDouble(tf.getText());
fuhao="-";
lastCommand="-";
}
if(click.getSource()==butEqual)//////////////////////////////////////////"="
{
if(tf.getText().equals("0"))
{
}
if(fuhao=="+")
{
double tfvaluejia;
tfvaluejia=Double.parseDouble(tf.getText());
value=value+tfvaluejia;
tf.setText(""+value);
b=false;
}
else if(fuhao=="*")
{
double tfvalueCheng;
tfvalueCheng=Double.parseDouble(tf.getText());
value=value*tfvalueCheng;
tf.setText(""+value);
b=false;
}
else if(fuhao=="/")
{
double tfvalueChu;
tfvalueChu=Double.parseDouble(tf.getText());
value=value/tfvalueChu;
tf.setText(""+value);
b=false;
}
else if(fuhao=="-")
{
double tfvaluejian;
tfvaluejian=Double.parseDouble(tf.getText());
value=value-tfvaluejian;
tf.setText(""+value);
b=false;
}
else if(fuhao=="=")
{
if(lastCommand=="+")
{
value = value +lastValue;
tf.setText(""+value);
b=false;
}
else if(lastCommand=="-")
{
value = value - lastValue;
tf.setText(""+value);
b=false;
}
if(lastCommand=="*")
{
value = value *lastValue;
tf.setText(""+value);
b=false;
}
if(lastCommand=="/")
{
value = value /lastValue;
tf.setText(""+value);
b=false;
}
}
fuhao="=";
}
}
}
试试这个
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
public class SZJSQ extends JApplet implements ActionListener
{
boolean i=true;
private JButton num0=new JButton("0");
private JButton num1=new JButton("1");
private JButton num2=new JButton("2");
private JButton num3=new JButton("3");
private JButton num4=new JButton("4");
private JButton num5=new JButton("5");
private JButton num6=new JButton("6");
private JButton num7=new JButton("7");
private JButton num8=new JButton("8");
private JButton num9=new JButton("9");
private JButton zuok=new JButton("(");
private JButton youk=new JButton(")");
private JButton dian=new JButton(".");
private JButton NULL=new JButton("N");
private JButton plu=new JButton("+");
private JButton min=new JButton("-");
private JButton mul=new JButton("x");
private JButton div=new JButton("/");
private JButton equ=new JButton("=");
private JButton cle=new JButton("C");//清除
private JTextField space=new JTextField(30);
public void init()
{
JPanel text=new JPanel();
text.setLayout(new FlowLayout());
text.add(space);
JPanel buttons=new JPanel();
buttons.setLayout(new GridLayout(5,4));
buttons.add(num9);
buttons.add(num8);
buttons.add(num7);
buttons.add(plu);
buttons.add(num6);
buttons.add(num5);
buttons.add(num4);
buttons.add(min);
buttons.add(num3);
buttons.add(num2);
buttons.add(num1);
buttons.add(mul);
buttons.add(num0);
buttons.add(cle);
buttons.add(equ);
buttons.add(div);
buttons.add(zuok);
buttons.add(youk);
buttons.add(dian);
buttons.add(NULL);
(num9).addActionListener(this);
(num8).addActionListener(this);
(num7).addActionListener(this);
(num6).addActionListener(this);
(num5).addActionListener(this);
(num4).addActionListener(this);
(num3).addActionListener(this);
(num2).addActionListener(this);
(num1).addActionListener(this);
(num0).addActionListener(this);
(plu).addActionListener(this);
(min).addActionListener(this);
(mul).addActionListener(this);
(div).addActionListener(this);
(equ).addActionListener(this);
(cle).addActionListener(this);
(zuok).addActionListener(this);
(youk).addActionListener(this);
(dian).addActionListener(this);
setLayout(new BorderLayout());
add("North",text);
add("South",buttons);
space.setText("0");
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==num9)
{
if(i==true)
{
space.setText("9");
i=false;
}
else space.setText(space.getText()+'9');
}
if(e.getSource()==num8)
{
if(i==true)
{
space.setText("8");
i=false;
}
else space.setText(space.getText()+'8');
}
if(e.getSource()==num7)
{
if(i==true)
{
space.setText("7");
i=false;
}
else space.setText(space.getText()+'7');
}
if(e.getSource()==num6)
{
if(i==true)
{
space.setText("6");
i=false;
}
else space.setText(space.getText()+'6');
}
if(e.getSource()==num5)
{
if(i==true)
{
space.setText("5");
i=false;
}
else space.setText(space.getText()+'5');
}
if(e.getSource()==num4)
{
if(i==true)
{
space.setText("4");
i=false;
}
else space.setText(space.getText()+'4');
}
if(e.getSource()==num3)
{
if(i==true)
{
space.setText("3");
i=false;
}
else space.setText(space.getText()+'3');
}
if(e.getSource()==num2)
{
if(i==true)
{
space.setText("2");
i=false;
}
else space.setText(space.getText()+'2');
}
if(e.getSource()==num1)
{
if(i==true)
{
space.setText("1");
i=false;
}
else space.setText(space.getText()+'1');
}
if(e.getSource()==num0)
{
if(i==true)
{
space.setText("0");
i=false;
}
else space.setText(space.getText()+'0');
}
if(e.getSource()==zuok)
{
if(i==true)
{
space.setText("(");
i=false;
}
else space.setText(space.getText()+'(');
} if(e.getSource()==youk)
{
if(i==false)
space.setText(space.getText()+')');
}
if(e.getSource()==dian)
{
if(i==false)
space.setText(space.getText()+'.');
}
if(e.getSource()==plu)
{
space.setText(space.getText()+'+');
i=false;
}
if(e.getSource()==min)
{
space.setText(space.getText()+'-');
i=false;
}
if(e.getSource()==mul)
{
space.setText(space.getText()+'*');
i=false;
}
if(e.getSource()==div)
{
space.setText(space.getText()+'/');
i=false;
}
if(e.getSource()==equ)
{
space.setText(String.valueOf(Calculator(space.getText())));
i=true;
}
if(e.getSource()==cle)
{
space.setText("0");
i=true;
}
}
public double Calculator(String f)//科学计算
{
int i=0,j=0,k;
char c;
StringBuffer s=new StringBuffer();
s.append(f);
s.append('=');
String formula=s.toString();
char[] anArray;
anArray=new char[50];
StackCharacter mystack=new StackCharacter();
while(formula.charAt(i)!='=')
{
c=formula.charAt(i);
switch(c)
{
case '(': mystack.push(new Character(c));
i++;
break;
case ')':
while(mystack.peek().charValue()!='(')
{
anArray[j++]=mystack.pop().charValue();
}
mystack.pop();
i++;
break;
case '+':
case '-':
while(!mystack.empty()mystack.peek().charValue()!='(')
{
anArray[j++]=mystack.pop().charValue();
}
mystack.push(new Character(c));
i++;
break;
case '*':
case '/':
while(!mystack.empty()(mystack.peek().charValue()=='*'||mystack.peek().charValue()=='/'))
{
anArray[j++]=mystack.pop().charValue();
}
mystack.push(new Character(c));
i++;
break;
case' ': i++;
break;
default: while((c='0'c='9')||c=='.')
{
anArray[j++]=c;
i++;
c=formula.charAt(i);
}
anArray[j++]='#';
break;
}
}
while(!(mystack.empty()))
anArray[j++]=mystack.pop().charValue();
i=0;
int count;
double a,b,d;
StackDouble mystack1 =new StackDouble();
while(ij)
{
c=anArray[i];
switch(c)
{
case '+':
a=mystack1.pop().doubleValue();
b=mystack1.pop().doubleValue();
d=b+a;
mystack1.push(new Double(d));
i++;
break;
case '-':
a=mystack1.pop().doubleValue();
b=mystack1.pop().doubleValue();
d=b-a;
mystack1.push(new Double(d));
i++;
break;
case '*':
a=mystack1.pop().doubleValue();
b=mystack1.pop().doubleValue();
d=b*a;
mystack1.push(new Double(d));
i++;
break;
case '/':
a=mystack1.pop().doubleValue();
b=mystack1.pop().doubleValue();
if(a!=0)
{
d=b/a;
mystack1.push(new Double(d));
i++;
}
else
{
System.out.println("Error!");
}
break;
default:
d=0;count=0;
while((c='0'c='9'))
{
d=10*d+c-'0';
i++;
c=anArray[i];
}
if(c=='.')
{
i++;
c=anArray[i];
while((c='0'c='9'))
{
count++;
d=d+(c-'0')/Math.pow(10,count);
i++;
c=anArray[i];
}
}
if(c=='#')
mystack1.push(new Double(d));
i++;
break;
}
}
return(mystack1.peek().doubleValue());
}
}