package packageone;
我写的计算器!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
[code=Java]
/*导入要使用JAVA的PACKAGES*/
import java.awt.*;
import java.awt.event.*;
import java.lang.Math;
import javax.swing.*;/* Calculation 的类 */
public class Calculation implements ActionListener { /* 在头部声明 GUI 组件 */
private JFrame CalFrame;
private JMenuBar jmenubar;
private JMenu jm1, jm2, jm3;
private JTextField texta, textb;
private JMenuItem jmm1, jmm2, jmm3, jmm4;
private JPanel UpPanel, DownPanel, CenterPanel;
private JButton st, c, seven, backspace, one, two, three, eight, nine, div,
Sqrt, four, five, six, ride, beyond, reduce, reciprocal, zore,
PosNeg, decimal, add, equal;
/* 在头部声明 类中要使用的 变量 */
private StringBuffer b = new StringBuffer(100);
private StringBuffer b1 = new StringBuffer(100);
private int i = -1, fog;
boolean flog = false, flog8 = true, flog1 = true, flog2 = true, lgg = true,
flog3 = true, flog4 = true, flog5 = true, flog6 = true;
private String ss;
private Dimension dim;
private Double iiii, ii, iii, iid, iiid, iiiid;
private String textstring="使用说明:" + "\n" + "当启动本计算器的时候默认是不可以操作的" + "\n"
+ "你可以选择 ->编辑->START 来启动计算器" + "" + "\n"
+ "1.可以用鼠标点击键如要计算的数进行计算." + "\n" + "2.可以用小键盘区的按键进行计算.";
/* 把面板分为三个部分 */
public void CreatText() { /* 创建FRAME面板的UP的面板 并加入面板中的组件 */
UpPanel = new JPanel();
UpPanel.setLayout(new BorderLayout());
texta = new JTextField("", 10);
texta.setBorder(BorderFactory.createEtchedBorder(1));
texta.setHorizontalAlignment(JTextField.RIGHT);
texta.setBackground(Color.WHITE);
texta.setForeground(Color.RED);
texta.setEditable(false);
UpPanel.add(texta);
} private void Creatcenter() { /* 创建FRAME面板的CENTER的面板 */ CenterPanel = new JPanel();
CenterPanel.setLayout(new FlowLayout()); /* 创建CenterPanel */ textb = new JTextField("禁用状态", 7);
textb.setHorizontalAlignment(JTextField.CENTER);
backspace = new JButton("BackSpace"); /* 实例化CenterPanel中的各个组件 */
st = new JButton("ST");
c = new JButton("C"); c.setForeground(Color.red);
textb.setForeground(Color.red); /* 为各个组件设置ForegroundColor */
st.setForeground(Color.red);
backspace.setForeground(Color.red); textb.setEditable(false);
backspace.setEnabled(false); /* 设置组件的初始化的时候Enabled为False */
st.setEnabled(false);
c.setEnabled(false); backspace.addActionListener(this);
st.addActionListener(this); /* 为组件添加ActionListener的监听 */
c.addActionListener(this); CenterPanel.add(textb);
CenterPanel.add(backspace); /* 最后把各个组件添加到CenterPanel中 */
CenterPanel.add(st);
CenterPanel.add(c); } private void CreatDown() { /* 创建FRAME面板的Down的面板 */ DownPanel = new JPanel();
GridLayout gl = new GridLayout(4, 5);/* 创建DownPanel 并设置它的布局方式 */
DownPanel.setLayout(gl);
gl.setHgap(4);
gl.setVgap(4); seven = new JButton("7");
eight = new JButton("8");
nine = new JButton("9");
div = new JButton("/");
Sqrt = new JButton("sqrt");
four = new JButton("4");
five = new JButton("5");
six = new JButton("6");
ride = new JButton("*");
beyond = new JButton("%"); /* 实例化DownPanel中的各个组件 */
one = new JButton("1");
two = new JButton("2");
three = new JButton("3");
reduce = new JButton("-");
reciprocal = new JButton("1/x");
zore = new JButton("0");
PosNeg = new JButton("+/-");
decimal = new JButton(".");
add = new JButton("+");
equal = new JButton("="); div.setForeground(Color.red);
ride.setForeground(Color.red);
reduce.setForeground(Color.red); /* 为单个组件设置ForegroundColor */
equal.setForeground(Color.red);
add.setForeground(Color.red); seven.setEnabled(false);
eight.setEnabled(false);
nine.setEnabled(false);
div.setEnabled(false);
Sqrt.setEnabled(false);
four.setEnabled(false);
five.setEnabled(false);
six.setEnabled(false);
ride.setEnabled(false); /* 设置组件的初始化的时候Enabled为False */
beyond.setEnabled(false);
one.setEnabled(false);
two.setEnabled(false);
three.setEnabled(false);
reduce.setEnabled(false);
reciprocal.setEnabled(false);
zore.setEnabled(false);
PosNeg.setEnabled(false);
decimal.setEnabled(false);
add.setEnabled(false);
equal.setEnabled(false); seven.addActionListener(this);
eight.addActionListener(this);
nine.addActionListener(this);
div.addActionListener(this);
Sqrt.addActionListener(this);
four.addActionListener(this);
five.addActionListener(this);
six.addActionListener(this);
ride.addActionListener(this);
beyond.addActionListener(this);
one.addActionListener(this); /* 为组件添加ActionListener的监听 */
two.addActionListener(this);
three.addActionListener(this);
reduce.addActionListener(this);
reciprocal.addActionListener(this);
zore.addActionListener(this);
PosNeg.addActionListener(this);
decimal.addActionListener(this);
add.addActionListener(this);
equal.addActionListener(this);
我写的计算器!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
[code=Java]
/*导入要使用JAVA的PACKAGES*/
import java.awt.*;
import java.awt.event.*;
import java.lang.Math;
import javax.swing.*;/* Calculation 的类 */
public class Calculation implements ActionListener { /* 在头部声明 GUI 组件 */
private JFrame CalFrame;
private JMenuBar jmenubar;
private JMenu jm1, jm2, jm3;
private JTextField texta, textb;
private JMenuItem jmm1, jmm2, jmm3, jmm4;
private JPanel UpPanel, DownPanel, CenterPanel;
private JButton st, c, seven, backspace, one, two, three, eight, nine, div,
Sqrt, four, five, six, ride, beyond, reduce, reciprocal, zore,
PosNeg, decimal, add, equal;
/* 在头部声明 类中要使用的 变量 */
private StringBuffer b = new StringBuffer(100);
private StringBuffer b1 = new StringBuffer(100);
private int i = -1, fog;
boolean flog = false, flog8 = true, flog1 = true, flog2 = true, lgg = true,
flog3 = true, flog4 = true, flog5 = true, flog6 = true;
private String ss;
private Dimension dim;
private Double iiii, ii, iii, iid, iiid, iiiid;
private String textstring="使用说明:" + "\n" + "当启动本计算器的时候默认是不可以操作的" + "\n"
+ "你可以选择 ->编辑->START 来启动计算器" + "" + "\n"
+ "1.可以用鼠标点击键如要计算的数进行计算." + "\n" + "2.可以用小键盘区的按键进行计算.";
/* 把面板分为三个部分 */
public void CreatText() { /* 创建FRAME面板的UP的面板 并加入面板中的组件 */
UpPanel = new JPanel();
UpPanel.setLayout(new BorderLayout());
texta = new JTextField("", 10);
texta.setBorder(BorderFactory.createEtchedBorder(1));
texta.setHorizontalAlignment(JTextField.RIGHT);
texta.setBackground(Color.WHITE);
texta.setForeground(Color.RED);
texta.setEditable(false);
UpPanel.add(texta);
} private void Creatcenter() { /* 创建FRAME面板的CENTER的面板 */ CenterPanel = new JPanel();
CenterPanel.setLayout(new FlowLayout()); /* 创建CenterPanel */ textb = new JTextField("禁用状态", 7);
textb.setHorizontalAlignment(JTextField.CENTER);
backspace = new JButton("BackSpace"); /* 实例化CenterPanel中的各个组件 */
st = new JButton("ST");
c = new JButton("C"); c.setForeground(Color.red);
textb.setForeground(Color.red); /* 为各个组件设置ForegroundColor */
st.setForeground(Color.red);
backspace.setForeground(Color.red); textb.setEditable(false);
backspace.setEnabled(false); /* 设置组件的初始化的时候Enabled为False */
st.setEnabled(false);
c.setEnabled(false); backspace.addActionListener(this);
st.addActionListener(this); /* 为组件添加ActionListener的监听 */
c.addActionListener(this); CenterPanel.add(textb);
CenterPanel.add(backspace); /* 最后把各个组件添加到CenterPanel中 */
CenterPanel.add(st);
CenterPanel.add(c); } private void CreatDown() { /* 创建FRAME面板的Down的面板 */ DownPanel = new JPanel();
GridLayout gl = new GridLayout(4, 5);/* 创建DownPanel 并设置它的布局方式 */
DownPanel.setLayout(gl);
gl.setHgap(4);
gl.setVgap(4); seven = new JButton("7");
eight = new JButton("8");
nine = new JButton("9");
div = new JButton("/");
Sqrt = new JButton("sqrt");
four = new JButton("4");
five = new JButton("5");
six = new JButton("6");
ride = new JButton("*");
beyond = new JButton("%"); /* 实例化DownPanel中的各个组件 */
one = new JButton("1");
two = new JButton("2");
three = new JButton("3");
reduce = new JButton("-");
reciprocal = new JButton("1/x");
zore = new JButton("0");
PosNeg = new JButton("+/-");
decimal = new JButton(".");
add = new JButton("+");
equal = new JButton("="); div.setForeground(Color.red);
ride.setForeground(Color.red);
reduce.setForeground(Color.red); /* 为单个组件设置ForegroundColor */
equal.setForeground(Color.red);
add.setForeground(Color.red); seven.setEnabled(false);
eight.setEnabled(false);
nine.setEnabled(false);
div.setEnabled(false);
Sqrt.setEnabled(false);
four.setEnabled(false);
five.setEnabled(false);
six.setEnabled(false);
ride.setEnabled(false); /* 设置组件的初始化的时候Enabled为False */
beyond.setEnabled(false);
one.setEnabled(false);
two.setEnabled(false);
three.setEnabled(false);
reduce.setEnabled(false);
reciprocal.setEnabled(false);
zore.setEnabled(false);
PosNeg.setEnabled(false);
decimal.setEnabled(false);
add.setEnabled(false);
equal.setEnabled(false); seven.addActionListener(this);
eight.addActionListener(this);
nine.addActionListener(this);
div.addActionListener(this);
Sqrt.addActionListener(this);
four.addActionListener(this);
five.addActionListener(this);
six.addActionListener(this);
ride.addActionListener(this);
beyond.addActionListener(this);
one.addActionListener(this); /* 为组件添加ActionListener的监听 */
two.addActionListener(this);
three.addActionListener(this);
reduce.addActionListener(this);
reciprocal.addActionListener(this);
zore.addActionListener(this);
PosNeg.addActionListener(this);
decimal.addActionListener(this);
add.addActionListener(this);
equal.addActionListener(this);
/* 为键盘监听和组件的对应键创建一个KeyStroke来进行存储 */ KeyStroke shift1 = KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD1, 0);
DownPanel.registerKeyboardAction(this, "VK_NUMPAD1", shift1,
JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke shift2 = KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD2, 0);
DownPanel.registerKeyboardAction(this, "VK_NUMPAD2", shift2,
JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke shift3 = KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD3, 0);
DownPanel.registerKeyboardAction(this, "VK_NUMPAD3", shift3,
JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke shift4 = KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD4, 0);
DownPanel.registerKeyboardAction(this, "VK_NUMPAD4", shift4,
JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke shift5 = KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD5, 0);
DownPanel.registerKeyboardAction(this, "VK_NUMPAD5", shift5,
JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke shift6 = KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD6, 0);
DownPanel.registerKeyboardAction(this, "VK_NUMPAD6", shift6,
JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke shift7 = KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD7, 0);
DownPanel.registerKeyboardAction(this, "VK_NUMPAD7", shift7,
JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke shift8 = KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD8, 0);
DownPanel.registerKeyboardAction(this, "VK_NUMPAD8", shift8,
JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke shift9 = KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD9, 0);
DownPanel.registerKeyboardAction(this, "VK_NUMPAD9", shift9,
JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke shift0 = KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD0, 0);
DownPanel.registerKeyboardAction(this, "VK_NUMPAD0", shift0,
JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke shiftback = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0);
DownPanel.registerKeyboardAction(this, "VK_BACK_SPACE", shiftback,
JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke shiftperiod = KeyStroke.getKeyStroke(KeyEvent.VK_PERIOD, 0);
DownPanel.registerKeyboardAction(this, "VK_PERIOD", shiftperiod,
JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke shiftequalse = KeyStroke.getKeyStroke(KeyEvent.VK_S, 0);
DownPanel.registerKeyboardAction(this, "VK_S", shiftequalse,
JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke shifteenter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
DownPanel.registerKeyboardAction(this, "VK_ENTER", shifteenter,
JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke shiftepace = KeyStroke.getKeyStroke(KeyEvent.VK_C, 0);
DownPanel.registerKeyboardAction(this, "VK_C", shiftepace,
JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke shifteadd = KeyStroke.getKeyStroke(KeyEvent.VK_ADD, 0);
DownPanel.registerKeyboardAction(this, "VK_ADD", shifteadd,
JComponent.WHEN_IN_FOCUSED_WINDOW); DownPanel.add(seven);
DownPanel.add(eight);
DownPanel.add(nine);
DownPanel.add(div);
DownPanel.add(Sqrt);
DownPanel.add(four);
DownPanel.add(five);
DownPanel.add(six);
DownPanel.add(ride);
DownPanel.add(beyond); /* 把各个组件加入DownPanel中去 */
DownPanel.add(one);
DownPanel.add(two);
DownPanel.add(three);
DownPanel.add(reduce);
DownPanel.add(reciprocal);
DownPanel.add(zore);
DownPanel.add(PosNeg);
DownPanel.add(decimal);
DownPanel.add(add);
DownPanel.add(equal);
} /* 创建Frame的方法 */
private void CreatFrame() {
CalFrame = new JFrame("简易计算器");
CalFrame.setLayout(new BorderLayout()); /* 实例化并设置布局方式 */ CreatText();
Creatcenter();
CreatDown(); jmenubar = new JMenuBar();
jmenubar.setBorder(BorderFactory.createEtchedBorder(1));
jm1 = new JMenu("编辑");
jm2 = new JMenu("帮助");
jm3 = new JMenu("关于");
jmm1 = new JMenuItem("START");
jmm2 = new JMenuItem("EXIT");
jmm3 = new JMenuItem("说明");
jmm4 = new JMenuItem("作者");
jmenubar.add(jm1);
jmenubar.add(jm2); /* 为FRAME添加菜单 */
jmenubar.add(jm3);
jm1.add(jmm1);
jm1.addSeparator();
jm1.add(jmm2);
jm2.add(jmm3);
jm3.add(jmm4);
jmm1.addActionListener(this);
jmm2.addActionListener(this);
jmm3.addActionListener(this); /* 给菜单的JMenuItem添加ActionListener */
jmm4.addActionListener(this); /* 设置FRAME的各个PANEL的边框样式 和BackgroundColor */
CenterPanel.setBorder(BorderFactory.createEtchedBorder(1));
CenterPanel.setBackground(Color.GRAY);
UpPanel.setBorder(BorderFactory.createEtchedBorder(1));
UpPanel.setBackground(Color.GRAY);
DownPanel.setBorder(BorderFactory.createEtchedBorder(1)); dim = CalFrame.getToolkit().getScreenSize(); /* 得到当前屏幕的W和H并放入到一个Dimension里面保存 */ /* 把FRAME的三个PANEL加入FRAME里面 */
CalFrame.add(UpPanel, BorderLayout.NORTH);
CalFrame.add(CenterPanel, BorderLayout.CENTER);
CalFrame.add(DownPanel, BorderLayout.SOUTH); /* 设置一些FRAME的属性 */
CalFrame.setSize(313, 255);
CalFrame.setLocation(dim.width / 2 - 156, dim.height / 2 - 127);
CalFrame.setJMenuBar(jmenubar);
CalFrame.setResizable(false);
CalFrame.setVisible(true);
CalFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } /* Action响应的方法 */
public void actionPerformed(ActionEvent e) { /* 当按下jmm3的对象的时候相应处理 */
if (e.getSource() == jmm3) {
JDialog jd = new JDialog(CalFrame, "说明");
JTextArea jtext = new JTextArea(5, 5); jtext.setText(textstring);
jd.setResizable(false);
jtext.setForeground(Color.RED);
jtext.setEditable(false);
jd.add(jtext);
int x = dim.width / 2 - 125;
int y = dim.height / 2 - 90;
jd.setBounds(x, y, 250, 180);
jd.setVisible(true);
}
/* 当按下jmm2的对象的时候相应处理 */
if (e.getSource() == jmm2) {
System.exit(0);
}
/* 当按下jmm2的对象的时候相应处理 */
if (e.getSource() == jmm4) {
JOptionPane
.showMessageDialog(null, "作者:曹朋" + " " + "版本:1.0");
}
if (e.getActionCommand().equalsIgnoreCase("VK_S")
|| e.getSource() == jmm1) {
if (flog1) {
backspace.setEnabled(true);
c.setEnabled(true);
seven.setEnabled(true);
eight.setEnabled(true);
nine.setEnabled(true);
one.setEnabled(true);
two.setEnabled(true);
three.setEnabled(true);
four.setEnabled(true);
five.setEnabled(true);
six.setEnabled(true);
zore.setEnabled(true);
div.setEnabled(true);
Sqrt.setEnabled(true);
ride.setEnabled(true);
beyond.setEnabled(true);
reduce.setEnabled(true);
st.setEnabled(true);
reciprocal.setEnabled(true);
PosNeg.setEnabled(true);
decimal.setEnabled(true);
add.setEnabled(true);
equal.setEnabled(true);
flog1 = false;
st.setText("CL");
textb.setText("开启状态");
} else {
backspace.setEnabled(false);
c.setEnabled(false);
seven.setEnabled(false);
eight.setEnabled(false);
nine.setEnabled(false);
one.setEnabled(false);
two.setEnabled(false);
three.setEnabled(false);
four.setEnabled(false);
five.setEnabled(false);
six.setEnabled(false);
zore.setEnabled(false);
div.setEnabled(false);
Sqrt.setEnabled(false);
ride.setEnabled(false);
st.setEnabled(false);
beyond.setEnabled(false);
reduce.setEnabled(false);
reciprocal.setEnabled(false);
PosNeg.setEnabled(false);
decimal.setEnabled(false);
add.setEnabled(false);
equal.setEnabled(false);
flog1 = true;
st.setText("ST");
textb.setText("禁用状态");
}
} /* 当触发组件one或小键盘的数子键1时候的响应 */
if (e.getSource() == one
|| e.getActionCommand().equalsIgnoreCase("VK_NUMPAD1")) {
if (flog) {
b.delete(0, i + 1);
texta.setText("");
i = -1;
flog = false;
}
i = i + 1;
b.insert(i, 1);
ss = new String(b);
texta.setText(ss); }
/* 当触发组件PosNeg的响应 */
if (e.getSource() == PosNeg && b.length() == 0) {
if (flog) {
b.delete(0, i + 1);
texta.setText("");
i = -1;
flog = false;
}
i = i + 1;
b.insert(i, "-");
ss = new String(b);
texta.setText(ss);
} /* 当触发组件two或小键盘的数子键2时候的响应 */
if (e.getSource() == two
|| e.getActionCommand().equalsIgnoreCase("VK_NUMPAD2")) {
if (flog) {
b.delete(0, i + 1);
texta.setText("");
i = -1;
flog = false;
}
i = i + 1;
b.insert(i, 2);
ss = new String(b);
texta.setText(ss);
} /* 当触发组件three或小键盘的数子键3时候的响应 */
if (e.getSource() == three
|| e.getActionCommand().equalsIgnoreCase("VK_NUMPAD3")) {
if (flog) {
b.delete(0, i + 1);
texta.setText("");
i = -1;
flog = false;
}
i = i + 1;
b.insert(i, 3);
ss = new String(b);
texta.setText(ss);
} /* 当触发组件four或小键盘的数子键4时候的响应 */
if (e.getSource() == four
|| e.getActionCommand().equalsIgnoreCase("VK_NUMPAD4")) {
if (flog) {
b.delete(0, i + 1);
texta.setText("");
i = -1;
flog = false;
}
i = i + 1;
b.insert(i, 4);
ss = new String(b);
texta.setText(ss);
} /* 当触发组件five或小键盘的数子键5时候的响应 */
if (e.getSource() == five
|| e.getActionCommand().equalsIgnoreCase("VK_NUMPAD5")) {
if (flog) {
b.delete(0, i + 1);
texta.setText("");
i = -1;
flog = false;
}
i = i + 1;
b.insert(i, 5);
ss = new String(b);
texta.setText(ss);
} /* 当触发组件six或小键盘的数子键6时候的响应 */
if (e.getSource() == six
|| e.getActionCommand().equalsIgnoreCase("VK_NUMPAD6")) {
if (flog) {
b.delete(0, i + 1);
texta.setText("");
i = -1;
flog = false;
}
i = i + 1;
b.insert(i, 6);
ss = new String(b);
texta.setText(ss);
} /* 当触发组件seven或小键盘的数子键7时候的响应 */
if (e.getSource() == seven
|| e.getActionCommand().equalsIgnoreCase("VK_NUMPAD7")) {
if (flog) {
b.delete(0, i + 1);
texta.setText("");
i = -1;
flog = false;
}
i = i + 1;
b.insert(i, 7);
ss = new String(b);
texta.setText(ss);
} /* 当触发组件eight或小键盘的数子键8时候的响应 */
if (e.getSource() == eight
|| e.getActionCommand().equalsIgnoreCase("VK_NUMPAD8")) {
if (flog) {
b.delete(0, i + 1);
texta.setText("");
i = -1;
flog = false;
}
i = i + 1;
b.insert(i, 8);
ss = new String(b);
texta.setText(ss);
} /* 当触发组件nine或小键盘的数子键9时候的响应 */
if (e.getSource() == nine
|| e.getActionCommand().equalsIgnoreCase("VK_NUMPAD9")) {
if (flog) {
b.delete(0, i + 1);
texta.setText("");
i = -1;
flog = false;
}
i = i + 1;
b.insert(i, 9);
ss = new String(b);
texta.setText(ss);
} /* 当触发组件zore或小键盘的数子键0时候的响应 */
if (e.getSource() == zore
|| e.getActionCommand().equalsIgnoreCase("VK_NUMPAD0")) {
if (flog) {
b.delete(0, i + 1);
texta.setText("");
i = -1;
flog = false;
}
i = i + 1;
b.insert(i, 0);
ss = new String(b);
texta.setText(ss);
} /* 当触发组件decimal的响应 */
if ((e.getSource() == decimal || e.getActionCommand().equalsIgnoreCase(
"VK_PERIOD"))
&& b.length() != 0) {
i = i + 1;
b.insert(i, ".");
ss = new String(b);
texta.setText(ss);
} /* 当触发组件backspace或键盘backspace的时候的响应 */
if (e.getSource() == backspace
|| e.getActionCommand().equalsIgnoreCase("VK_BACK_SPACE")) {
if (b.length() != 0) {
b.delete(i, i + 1);
i = i - 1;
ss = new String(b);
texta.setText(ss);
}
}
if (e.getSource() == Sqrt) {
if (b1.length() != 0) {
String sub;
Double d = Double.parseDouble(b1.toString());
b1.delete(0, b1.length());
Double ddd = Math.sqrt(d);
String dddstr = String.valueOf(ddd);
sub = dddstr.substring(0, dddstr.length());
b1.append(sub);
texta.setText(sub);
} else {
String sub;
Double d = Double.parseDouble(b.toString()); b.delete(0, i + 1);
b1.delete(0, b1.length());
b1.append(b);
i = -1;
Double ddd = Math.sqrt(d);
String dddstr = String.valueOf(ddd);
sub = dddstr.substring(0, dddstr.length());
b.append(sub);
i = b.length();
texta.setText(sub);
flog = true;
flog8 = false;
} }