java可编程计算器器(新手求解,急)

JSP+JavaBean简单计算器
public class CalculatorBean {
private double firstN
private double secondN
private char operator='+';
public double getFirstNum() {
return firstN
public void setFirstNum(double firstNum) {
this.firstNum = firstN
public double getSecondNum() {
return secondN
public void setSecondNum(double secondNum) {
this.secondNum = secondN
public char getOperator() {
public void setOperator(char operator) {
this.operator =
public double getResult() {
public void setResult(double result) {
this.result =
public void calculate(){
switch(this.operator){
this.result=this.firstNum+this.secondN
this.result=this.firstNum-this.secondN
this.result=this.firstNum*this.secondN
if(this.secondNum==0)
throw new RuntimeException("被除数不能为0!");
this.result=this.firstNum/this.secondN
throw new RuntimeException("对不起,输入的运算符非法!");Java编程实现Windows计算器
///////////////////////////////////
//Eclipse开发环境
////////////////////////////////
import java.awt.*;//AWT核心包
import java.awt.datatransfer.C
import java.awt.datatransfer.DataF
import java.awt.datatransfer.StringS
import java.awt.datatransfer.UnsupportedFlavorExcepti
import java.awt.event.*;//提供事件类和监听器
import java.io.IOE
import javax.swing.*;
import javax.swing.border.EtchedB
/////////////////////////////////////////////////////////////
public class Calculator extends JFrame implements
ActionListener{
&//设置各变量及所需组件
&StringBuffer show=new StringBuffer();
&int jin=10;
&&& double
double_operator1,double_operator2;//算术运算左右操作数
&&& double
result,//结果
&&& boolean
&&& String
Operator3,Operator4;//操作数
&&& String
&&& JButton
&&& //JMenuItem
&&& JTextField
&&& private
objConversion convert = new objConversion();
&&& JRadioButton
jPadiobutton_
int_operator1,int_operator2,s1,res,
&&& JFrame
frame=new JFrame("计算器");
&&& JTextField
showField=new JTextField(" ");//输出框
&&& JPanel
jPanel1=new JPanel();//存放输出框、进制和角度面板
&&& JPanel
jpanel_scale=new JPanel();//存放进制的面板
&&& JPanel
jpanel_degree=new JPanel();//存放角度、弧度、梯度面板
&&& JPanel
jpanel_sca_deg=new
JPanel();//存放jpanel_scale面板和jpanel_degree面板&
&&& JPanel
rbutton_jpanel=new JPanel();//左面板
&&& JPanel
lbutton_jpanel1=new JPanel();
&&& JPanel
lbutton_jpanel2=new JPanel();
&&& JPanel
lbutton_jpanel3=new JPanel();
&&& JPanel
right_jpanel=new JPanel();
&&& JPanel
left_jpanel=new JPanel();
&&& JMenuBar
jMenuBar=new JMenuBar();
num=new JMenu("编辑(E)",true);
&&& JMenuItem
copy_item=new JMenuItem("复制(C) ctrl+c");
&&& JMenuItem
paste_item=new JMenuItem("粘贴(P) ctrl+v");
&&& JMenuItem
jMenuFileExit = new JMenuItem("退出");
set_JMenu = new JMenu("设置(S)");
SwitchPanel1= new JMenu("外观风格");
&&& JMenuItem
SwitchPanel2 = new JMenuItem("●Windows风格");
&&& JMenuItem
SwitchPanel3 = new JMenuItem("Motif风格");
&&& JMenuItem
SwitchPanel4 = new JMenuItem(" Metal风格");
check_JMenu=new JMenu("查看(V)");
&&& JMenuItem
check_item1=new JMenuItem("●科学型(T)");
&&& JMenuItem
check_item2=new JMenuItem("标准型(S)");
&&& JMenuItem
check_item3=new JMenuItem("十六进制(H) F5");
&&& JMenuItem
check_item4=new JMenuItem("●十进制(D) F6");
&&& JMenuItem
check_item5=new JMenuItem("八进制(O) F7");
&&& JMenuItem
check_item6=new JMenuItem("二进制(B) F8");
&&& JMenuItem
check_item7=new JMenuItem("●角度(E) F2");
&&& JMenuItem
check_item8=new JMenuItem("弧度(R) F3");
&&& JMenuItem
check_item9= new JMenuItem("梯度(G) F4");
&&& JMenuItem
check_item21= new JMenuItem("●四字(Q) F12");
&&& JMenuItem
check_item22= new JMenuItem("DWORD(R) F2");
&&& JMenuItem
check_item23= new JMenuItem("单字(W) F3");
&&& JMenuItem
check_item24= new JMenuItem("字节(Y) F4");
&&& JMenuItem
check_item10= new JMenuItem("数字分组(I)");
help_JMenu=new JMenu("帮助(H)");
&&& JMenuItem
help_Item= new JMenuItem("帮助主题(H)");
&&& JMenuItem
about_Item= new JMenuItem("关于计算器(A)");
&&& JMenuItem
information =new JMenuItem("计算器使用方法");
&&& JButton[]
number_button=new JButton[10];//数字键按钮
&&& JButton[]
function_button2=new JButton[20];//开始
&&& JButton
Backspace_button=new JButton("Backspace");
&&& JButton
C_button=new JButton("C");
&&& JButton
CE_button=new JButton("CE");//结束,为右侧符号键按钮。
&&& JButton []
function_button1=new JButton[25];
&&& JRadioButton
scale_button1=new JRadioButton("十六进制",false);//单选按钮
&&& JRadioButton
scale_button2=new JRadioButton("十进制",true);
&&& JRadioButton
scale_button3=new JRadioButton("八进制",false);
&&& JRadioButton
scale_button4=new JRadioButton("二进制",false);
JRadioButton degree_button1=new JRadioButton("角度",true);
JRadioButton degree_button2=new JRadioButton("弧度",false);
JRadioButton degree_button3=new JRadioButton("梯度",false);
JRadioButton word_button1=new JRadioButton("四字",true);
JRadioButton word_button2=new JRadioButton("双字",false);
JRadioButton word_button3=new JRadioButton("单字",false);
JRadioButton word_button4=new JRadioButton("字节",false);
ButtonGroup group_button1=new ButtonGroup();
ButtonGroup group_button2=new ButtonGroup();
ButtonGroup group_button3=new ButtonGroup();
////////////////////////////////////////////////
//构造函数进行面板布局
public Calculator(){
setTitle("计算器");
showField.setBackground(Color.white);//设置输出框白底
showField.setEnabled(true);//设置该对象的启用状态
showField.setFont(new java.awt.Font("Dialog", 1, 13));
showField.setEditable(false);//设置输出框不可编辑
showField.setHorizontalAlignment(SwingConstants.RIGHT);//设置输出结果为右对齐
setJMenuBar(jMenuBar);&&
//将菜单条填入窗口&&&&
num.add(copy_item);//将复制菜单项添加编辑菜单
num.add(paste_item);//将粘贴菜单项添加到编辑菜单
num.add(jMenuFileExit);//将退出菜单项添加到编辑菜单
//退出菜单项设置监听器
Edit edit= new Edit();
jMenuFileExit.addActionListener(edit);
set_JMenu.add(SwitchPanel1);//将外观风格菜单添加到设置菜单中
//将windows,Motif,Metal风格添加到外观风格菜单中,并设置监听器
Style style=new Style();
SwitchPanel1.add(SwitchPanel2);
SwitchPanel2.addActionListener(style);
SwitchPanel1.add(SwitchPanel3);
SwitchPanel3.addActionListener(style);
SwitchPanel1.add(SwitchPanel4);
SwitchPanel4.addActionListener(style);
//在查看菜单中添加进制,度,计数型,数字分组菜单项,并添加分割线
check_JMenu.add(check_item1);check_JMenu.add(check_item2);
check_JMenu.add(check_item3); check_JMenu.add(check_item4);
check_JMenu.add(check_item5);check_JMenu.add(check_item6);
check_JMenu.add(check_item7);check_JMenu.add(check_item8);
check_JMenu.add(check_item9);
check_JMenu.add(check_item10);&&
//在帮助菜单中添加,帮助主题和关于计算器菜单项,并设置监听器
help_JMenu.add(help_Item);
help_Item.addActionListener(new
Frame1_jMenuItem6_actionAdapter(this));
help_JMenu.add(about_Item);
about_Item.addActionListener(new
Frame1_jMenuHelpAbout_ActionAdapter(this));
//将编辑,查看,帮助,设置添加到菜单条中
jMenuBar.add(num);
jMenuBar.add(check_JMenu);
jMenuBar.add(help_JMenu);
jMenuBar.add(set_JMenu);
//创建菜单监听类对象,设置各个菜单项的监听器
Menus menus=new Menus();
copy_item.addActionListener(this);paste_item.addActionListener(this);
check_item1.addActionListener(menus);check_item2.addActionListener(menus);
check_item3.addActionListener(menus);check_item4.addActionListener(menus);
check_item5.addActionListener(menus);check_item6.addActionListener(menus);
check_item7.addActionListener(menus);check_item8.addActionListener(menus);
check_item9.addActionListener(menus);check_item10.addActionListener(menus);
check_item21.addActionListener(menus);check_item22.addActionListener(menus);
check_item23.addActionListener(menus);check_item24.addActionListener(menus);
word_button1.addActionListener(menus);word_button2.addActionListener(menus);
word_button3.addActionListener(menus);word_button4.addActionListener(menus);
degree_button1.addActionListener(menus);degree_button2.addActionListener(menus);
degree_button3.addActionListener(menus);
help_JMenu.add(information);
information.addActionListener(menus);
//设置面板jpanel_scale,存放各进制
jpanel_scale.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)));
group_button1.add(scale_button1);group_button1.add(scale_button2);group_button1.add(scale_button3);group_button1.add(scale_button4);&&&
//设置面板jpanel_degree,存放角度,弧度,梯度单选按钮
jpanel_degree.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)));
jpanel_degree.add(degree_button1);jpanel_degree.add(degree_button2);jpanel_degree.add(degree_button3);
// 设置角度,弧度,梯度群组
group_button2.add(degree_button1);group_button2.add(degree_button2);group_button2.add(degree_button3);
&&&&&&&&&&
//设置字节,字,双字,四字群组
group_button3.add(word_button1);group_button3.add(word_button2);group_button3.add(word_button3);group_button3.add(word_button4);
//创建复选框
//&& JPanel fx=new
JCheckBox fx1=new JCheckBox("Inv",false);
JCheckBox fx2=new JCheckBox("Hyp",false);
// fx.add(fx1);fx.add(fx2);
JTextField(2);&&&&&//创建显示记忆的索引值的文本框
//窗口顶部
jpanel_scale.add(scale_button1);jpanel_scale.add(scale_button2);jpanel_scale.add(scale_button3);jpanel_scale.add(scale_button4);
& jpanel_degree.setLayout(new
GridLayout(1,4,5,5));jpanel_scale.setLayout(new
GridLayout(1,4,5,5));//添加文本框和p3到p中。
& jpanel_sca_deg.setLayout(new
GridLayout(1,2,5,5));jPanel1.setLayout(new
GridLayout(2,1,5,5));
jpanel_sca_deg.add(jpanel_scale);jpanel_sca_deg.add(jpanel_degree);jPanel1.add(showField);jPanel1.add(jpanel_sca_deg);
& registerEvent();//单选框事件处理。
& //开始窗口右侧
&&& for(int
i=0;i&10;i++)
number_button[i]=new JButton(String.valueOf(i));
number_button[i].setForeground(Color.blue);
& function_button2[0]=new
JButton("/");function_button2[1]=new
JButton("Mod");& function_button2[2]=new
JButton("And");
& function_button2[3]=new
JButton("*");function_button2[4]=new
JButton("Or");function_button2[5]=new JButton("Xor");
& function_button2[6]=new
JButton("-");function_button2[7]=new
JButton("Lsh");function_button2[8]=new JButton("Not");
& function_button2[9]=new
JButton("+");function_button2[10]=new
JButton("=");function_button2[11]=new JButton("Int");
& function_button2[12]=new
JButton("+/-");function_button2[13]=new JButton(".");
function_button2[12].setForeground(Color.blue);function_button2[13].setForeground(Color.blue);
function_button2[1].setToolTipText("取余Mod");
& for(int i=0;i&12;i++)
function_button2[i].setForeground(Color.red);
Backspace_button.setForeground(Color.red);
Backspace_button.setToolTipText("回车键");
C_button.setForeground(Color.red);
C_button.setToolTipText("清除键");
CE_button.setForeground(Color.red);//设置按键颜色。
CE_button.setToolTipText("清零键");
& for(int i=0;i&3;i++)
for(int j=0;j&3;j++)
rbutton_jpanel.add(number_button[9+j-3*i-2]);
for(int k=0;k&3;k++)
rbutton_jpanel.add(function_button2[i*3+k]);
& rbutton_jpanel.setLayout(new
GridLayout(5,6,5,5));
rbutton_jpanel.add(number_button[0]);rbutton_jpanel.add(function_button2[12]);rbutton_jpanel.add(function_button2[13]);
rbutton_jpanel.add(function_button2[9]);rbutton_jpanel.add(function_button2[10]);rbutton_jpanel.add(function_button2[11]);
& char c='A';
& for(int i=14;i&20;i++){
function_button2[i]=new JButton(String.valueOf(c));
rbutton_jpanel.add(function_button2[i]);
c=(char)(c + 1);
function_button2[i].setForeground(Color.blue);
& } //结束,右下方各键位按钮添加p1。
&& for(int
i=14;i&20;i++)
function_button2[i].setEnabled(false);
///////////////////////////////////////
& GridBagLayout gridbag2=new
GridBagLayout();//设网格包装布局
& GridBagConstraints gridbag1=new
GridBagConstraints();//设置对网格包装布局的约束,如组件插入的位置、大小、对齐方式、填充
right_jpanel.setLayout(gridbag2);
gridbag1.fill=GridBagConstraints.BOTH;//用于确定是否(以及如何)调整组件,使组件完全填满其显示区域
gridbag1.ipadx=10;gridbag1.ipady=1;//设置组件的高度为其最小高度加上 ipady 像素
gridbag1.weightx=10;gridbag1.weighty=4;//用于确定分布空间方式,设置组件的权重
& gridbag1.insets=new
Insets(3,100,8,0);//设置组件与其显示区域边缘之间间距的最小量
gridbag2.setConstraints(Backspace_button,gridbag1);
& gridbag1.weightx=10;
& gridbag1.weighty=4;
& gridbag1.insets=new Insets(3,5,8,0);
gridbag2.setConstraints(C_button,gridbag1);
& gridbag1.weightx=10;gridbag1.weighty=4;
& gridbag1.insets=new Insets(3,5,8,6);
gridbag1.gridwidth=GridBagConstraints.REMAINDER;//指定组件的显示区域中行&
中的单元数。
gridbag2.setConstraints(CE_button,gridbag1);
& GridBagConstraints gridbag3=new
GridBagConstraints();
& gridbag3.weightx=44;
& gridbag3.weighty=12;
gridbag3.gridwidth=GridBagConstraints.REMAINDER;
& gridbag3.insets=new Insets(3,100,6,6);
gridbag2.setConstraints(rbutton_jpanel,gridbag3);
///////////////////////////////////////////////////////
right_jpanel.add(Backspace_button);right_jpanel.add(C_button);right_jpanel.add(CE_button);right_jpanel.add(rbutton_jpanel);//结束,用网格包布局管理器把p1和fd1、C_button、fd3加到p6中。
& //创建数字键监听对象,使数字键添加监听器
& Monitor_numbers btnjian1=new
Monitor_numbers();
&&& for(int
i=0;i&10;i++)
number_button[i].addActionListener(btnjian1);
& for(int i=14;i&20;i++)
function_button2[i].addActionListener(btnjian1);
& //创建运算符监听对象,使加减乘除取余添加监听器
& Monitor_symbol btnjian2=new
Monitor_symbol();
function_button2[1].addActionListener(btnjian2);
function_button2[9].addActionListener(btnjian2);
function_button2[6].addActionListener(btnjian2);
function_button2[3].addActionListener(btnjian2);
function_button2[0].addActionListener(btnjian2);
& //创建等号监听对象,使等号添加监听器
& Monitor_equals btnjian3=new
Monitor_equals();
function_button2[10].addActionListener(btnjian3);
& //创建回车监听对象,使回车添加监听器
& Monitor_backspace monitor=new
Monitor_backspace();
Backspace_button.addActionListener(monitor);
& //创建清除监听对象,使清除添加监听器
& C cf=new C();
& C_button.addActionListener(cf);
& //创建 清零监听对象,使清零添加监听器
& CE ce=new CE();
& CE_button.addActionListener(ce);
& //创建正负监听对象,使正负添加监听器
& Monitor_plus_minus btnjian5=new
Monitor_plus_minus();
function_button2[12].addActionListener(btnjian5);
& //创建小数点监听对象,使小数点添加监听器
& Monitor_point btnjian6=new
Monitor_point();
function_button2[13].addActionListener(btnjian6);
& //窗口左侧
& function_button1[0]=new
JButton("Sta");function_button1[0].setForeground(Color.blue);
function_button1[1]=new JButton("Ave");
& function_button1[2]=new JButton("Sum");
function_button1[3]=new JButton("S"); function_button1[4]=new
JButton("Dat");
& lbutton_jpanel1.setLayout(new
GridLayout(5,1,5,5));
& function_button1[0].addActionListener(new
Frame1_function_button_ActionAdapter(this));
& for(int i=1;i&=4;i++)
function_button1[i].setForeground(Color.blue);
& function_button1[i].setEnabled(false);
& for(int i=0;i&5;i++){
lbutton_jpanel1.add(function_button1[i]);
& function_button1[5]=new JButton("F-E");
function_button1[6]=new JButton("(");function_button1[7]=new
JButton(")");
& function_button1[8]=new JButton("dms");
function_button1[9]=new JButton("Exp");function_button1[10]=new
JButton("ln");
& function_button1[11]=new
JButton("sin");function_button1[12]=new JButton("x^y");
function_button1[13]=new JButton("log");
& function_button1[14]=new
JButton("cos");function_button1[15]=new JButton("x^3");
function_button1[16]=new JButton("n!");
& function_button1[17]=new JButton("tan");
function_button1[18]=new JButton("x^2"); function_button1[19]=new
JButton("1/x");
& lbutton_jpanel2.setLayout(new
GridLayout(5,3,5,5));
& function_button1[6].addActionListener(new
ActionListener()
&& public void
actionPerformed(ActionEvent e)
showField.requestFocus();
& function_button1[7].addActionListener(new
ActionListener()
&& public void
actionPerformed(ActionEvent e)
leng=showField.getText().length();
if(leng&0)
showField.requestFocus();
JOptionPane.showMessageDialog(null,
"你输入的第一个字符为右括号,不符合要求,请重新输入.");
showField.requestFocus();
& for(int i=5;i&20;i++){
lbutton_jpanel2.add(function_button1[i]);
function_button1[i].setForeground(Color.blue);
& function_button1[20]=new JButton("MC");
function_button1[21]=new JButton("MR");function_button1[22]=new
JButton("MS");
& function_button1[23]=new JButton("M+");
function_button1[24]=new JButton("π");
& lbutton_jpanel3.setLayout(new
GridLayout(5,1,5,5));
& Monitor_Pock pock=new Monitor_Pock();
function_button1[20].setToolTipText("清除存储的数字");
function_button1[20].addActionListener(pock);
function_button1[22].setToolTipText("存储显示框的数字");
function_button1[22].addActionListener(pock);
function_button1[21].setToolTipText("显示存储数字");
function_button1[21].addActionListener(pock);
function_button1[23].setToolTipText("存储数字键+显示框数字");
function_button1[23].addActionListener(pock);
& Monitor_exp exp=new Monitor_exp();
function_button1[9].addActionListener(exp);
& for(int i=20;i&25;i++){
lbutton_jpanel3.add(function_button1[i]);
function_button1[i].setForeground(Color.red);
}function_button1[24].setForeground(Color.blue);
////////////////////////////////////////////
& GridBagLayout wgz=new GridBagLayout();//开始
& left_jpanel.setLayout(wgz);//设置网格包装布局
& GridBagConstraints grid=new
GridBagConstraints();//设置对网格包装布局的约束,如组件插入的位置、大小、对齐方式、填充
grid.fill=GridBagConstraints.BOTH;//使组件完全填满其显示区域
& grid.weightx=11;grid.weighty=4;
& grid.insets=new Insets(3,6,8,6);
& wgz.setConstraints(fx1,grid);
& grid.weightx=11;grid.weighty=4;
& grid.insets=new Insets(3,6,8,6);
& wgz.setConstraints(fx2,grid);
& grid.weightx=11;grid.weighty=4;
& grid.insets=new Insets(3,6,8,6);
grid.gridwidth=GridBagConstraints.REMAINDER;
& wgz.setConstraints(txfM,grid);
& GridBagConstraints grid1=new
GridBagConstraints();
& grid1.weightx=55;grid1.weighty=12;
& grid1.insets=new Insets(3,6,6,20);
& wgz.setConstraints(lbutton_jpanel1,grid1);
& grid1.insets=new Insets(3,0,6,20);
& wgz.setConstraints(lbutton_jpanel2,grid1);
& grid1.insets=new Insets(3,0,6,20);
grid.gridwidth=GridBagConstraints.REMAINDER;
gridbag2.setConstraints(lbutton_jpanel3,grid1);
///////////////////////////////////////////////////
left_jpanel.add(fx1);left_jpanel.add(fx2);left_jpanel.add(txfM);
left_jpanel.add(lbutton_jpanel1);left_jpanel.add(lbutton_jpanel2);left_jpanel.add(lbutton_jpanel3);
& symbol1 btnjianz1=new symbol1();
& for(int i=13;i&=19;i++){
function_button1[i].addActionListener(btnjianz1);
function_button1[10].addActionListener(btnjianz1);
function_button1[11].addActionListener(btnjianz1);
function_button1[12].addActionListener(btnjian2);
& //创建π监听对象,使π添加监听器
& Monitor_π pai=new Monitor_π();
& function_button1[24].addActionListener(pai);
&frame.setLayout(new BorderLayout());
& setLocation(100, 100);
& add(jPanel1,"North");
& add(right_jpanel,"East");
& add(left_jpanel,"West");
/////////////////////////////////////////////////&&&&&
//菜单条监听类,设置各个菜单项的监听器
private class Menus implements ActionListener{
public void actionPerformed(ActionEvent e){
&&&&&&&&&&&&
// temp=(JMenuItem)e.getSource();
&&&&&&&&&&&&&
Object temp = e.getSource();
&&&&&&&&&&&
&&&&&&&&&&&&&
if(temp==check_item2)
&&&&&&&&&&&&&
&&&&&&&&&&&
&& new Calculation();
&&&&&&&&&&&
&&&&&&&&&&&&&
&&&&&&&&&&&&&
if(temp==check_item1)
&&&&&&&&&&&&&
&&&&&&&&&&&
&&&&&&&&&&&&&
check_item2.setText("&&
&&&&&&&&&&&&&&
check_item1.setText("●科学型");
&&&&&&&&&&&&&
&&&&&&&&&&&&&
&&&&&&&&&&&
if(temp==check_item21 ||temp==word_button1)
&&&&&&&&&&&
&&&&&&&&&&&
&word_button1.setSelected(true);
&&&&&&&&&&&
&check_item21.setText("●四字");
&&&&&&&&&&
& check_item22.setText(" 双字");
&&&&&&&&&&
& check_item23.setText(" 单字");
&&&&&&&&&&
& check_item24.setText(" 字节");
&&&&&&&&&&&
&&&&&&&&&&
&&&&&&&&&&&
if(temp==check_item22||temp==word_button2)
&&&&&&&&&&&
{word_button2.setSelected(true);
&&&&&&&&&&&
&check_item21.setText(" 四字");
&&&&&&&&&&
& check_item22.setText("●双字");
&&&&&&&&&&
& check_item23.setText(" 字");
&&&&&&&&&&
& check_item24.setText(" 字节");
&&&&&&&&&&&
&&&&&&&&&&&
&&&&&&&&&&&
if(temp==check_item23||temp==word_button3 )
&&&&&&&&&&&
&&&&&&&&&&&
&word_button3.setSelected(true);
&&&&&&&&&&&
&check_item21.setText(" 四字");
&&&&&&&&&&
& check_item22.setText(" 双字");
&&&&&&&&&&
& check_item23.setText("●单字");
&&&&&&&&&&
& check_item24.setText(" 字节");
&&&&&&&&&&&
&&&&&&&&&&
&&&&&&&&&&&
if(temp==check_item24||temp==word_button4 )
&&&&&&&&&&&
&&&&&&&&&&&
&word_button4.setSelected(true);
&&&&&&&&&&&
&check_item21.setText(" 四字");
&&&&&&&&&&
& check_item22.setText(" 双字");
&&&&&&&&&&
& check_item23.setText(" 单字");
&&&&&&&&&&
& check_item24.setText("●字节");
&&&&&&&&&&&
&&&&&&&&&&&
&&&&&&&&&&&
if(temp==check_item7||temp==degree_button1)
&&&&&&&&&&&
&&&&&&&&&&&
&degree_button1.setSelected(true);
&&&&&&&&&&&
&check_item7.setText("●角度");
&&&&&&&&&&
& check_item8.setText(" 弧度");
&&&&&&&&&&
& check_item9.setText(" 梯度");
&&&&&&&&&&
&&&&&&&&&&&
&&&&&&&&&&&
if(temp==check_item8||temp==degree_button2)
&&&&&&&&&&&
{degree_button2.setSelected(true);
&&&&&&&&&&&
&check_item7.setText(" 角度");
&&&&&&&&&&
& check_item8.setText("●弧度");
&&&&&&&&&&
& check_item9.setText(" 梯度");
&&&&&&&&&&
&&&&&&&&&&&
&&&&&&&&&&&
if(temp==check_item9||temp==degree_button3)
&&&&&&&&&&&
{degree_button3.setSelected(true);
&&&&&&&&&&&
&check_item7.setText(" 角度");
&&&&&&&&&&
& check_item8.setText(" 弧度");
&&&&&&&&&&
& check_item9.setText("●梯度");
&&&&&&&&&&
&&&&&&&&&&&
&&&&&&&&&&&&
if(temp==check_item3){
&&&&&&&&&&&
& scale_button1.setSelected(true);
&&&&&&&&&&&
& check_item3.setText("●十六进制");
&&&&&&&&&&&
& check_item4.setText(" 十进制");
&&&&&&&&&&&
& check_item5.setText(" 八进制");
&&&&&&&&&&&
& check_item6.setText(" 二进制");
&&&&&&&&&&&&&&&
check_JMenu.remove(check_item7);check_JMenu.remove(check_item8);check_JMenu.remove(check_item9);check_JMenu.repaint();
&&&&&&&&&&&&&&&
check_JMenu.remove(check_item10);
&&&&&&&&&&&&&&
&check_JMenu.add(check_item21);check_JMenu.add(check_item22);
&&&&&&&&&&&&&&&
check_JMenu.add(check_item23);check_JMenu.add(check_item24);
&&&&&&&&&&&&&&&
check_JMenu.add(check_item10);
&&&&&&&&&&&&&&&&&
hexadecimal();
&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&
if( temp==check_item4){
&&&&&&&&&&&
scale_button2.setSelected(true);
&&&&&&&&&&&
& // check_item4.setSelected(true);
&&&&&&&&&&&
&& check_item3.setText("
十六进制");
&&&&&&&&&&&&
& check_item4.setText("●十进制");
&&&&&&&&&&&&
& check_item5.setText(" 八进制");
&&&&&&&&&&&&
& check_item6.setText(" 二进制");
&&&&&&&&&&&&
check_JMenu.remove(check_item21);check_JMenu.remove(check_item22);check_JMenu.remove(check_item23);check_JMenu.remove(check_item24);check_JMenu.repaint();
&&&&&&&&&&&&
&check_JMenu.remove(check_item10);
&&&&&&&&&&&&
&check_JMenu.add(check_item7);check_JMenu.add(check_item8);
&&&&&&&&&&&&&&&
check_JMenu.add(check_item9);
&&&&&&&&&&&&&&&
check_JMenu.add(check_item10);
&&&&&&&&&&&&
&& decimalism();
&&&&&&&&&&&
&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&
if( temp==check_item5){
&&&&&&&&&&&
scale_button3.setSelected(true);
&&&&&&&&&&&
& // check_item5.setSelected(true);
&&&&&&&&&&&
&& check_item3.setText("
十六进制");
&&&&&&&&&&&&
& check_item4.setText(" 十进制");
&&&&&&&&&&&&
& check_item5.setText("●八进制");
&&&&&&&&&&&&
& check_item6.setText(" 二进制");
&&&&&&&&&&&&
check_JMenu.remove(check_item7);check_JMenu.remove(check_item8);check_JMenu.remove(check_item9);check_JMenu.repaint();
&&&&&&&&&&&&&&&&&&
check_JMenu.remove(check_item10);
&&&&&&&&&&&&&&&&&
&check_JMenu.add(check_item21);check_JMenu.add(check_item22);
&&&&&&&&&&&&&&&&&&
check_JMenu.add(check_item23);check_JMenu.add(check_item24);
&&&&&&&&&&&&&&&&&&
check_JMenu.add(check_item10);
&&&&&&&&&&&&&&&&&&&&
octonary ();
&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&
if( temp==check_item6){
&&&&&&&&&&&
scale_button4.setSelected(true);
&&&&&&&&&&&
check_item6.setSelected(true);
&&&&&&&&&&&
&& check_item3.setText("
十六进制");
&&&&&&&&&&&&
& check_item4.setText(" 十进制");
&&&&&&&&&&&&
& check_item5.setText(" 八进制");
&&&&&&&&&&&&
& check_item6.setText("●二进制");
&&&&&&&&&&&&
check_JMenu.remove(check_item7);check_JMenu.remove(check_item8);check_JMenu.remove(check_item9);check_JMenu.repaint();
&&&&&&&&&&&&&&&&&&
check_JMenu.remove(check_item10);
&&&&&&&&&&&&&&&&&
&check_JMenu.add(check_item21);check_JMenu.add(check_item22);
&&&&&&&&&&&&&&&&&&
check_JMenu.add(check_item23);check_JMenu.add(check_item24);
&&&&&&&&&&&&&&&&&&
check_JMenu.add(check_item10);
&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&
&&&&&&&&&&&
&&&&&&&&&&&&&
if(temp==information)
&&&&&&&&&&&&&
&&&&&&&&&&&
&&&&&&&&&&&
&&&&&&&&&&&
Runtime.getRuntime().exec("explorer ");
&&&&&&&&&&&
&&&&&&&&&&&
catch(Exception eeee)
&&&&&&&&&&&
&&&&&&&&&&&
System.out.println("打开指定网页出错");&&&
&&&&&&&&&&&
&&&&&&&&&&&&&
&&&&&&&&&&&&&
if(temp==copy_item){
&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&
&&&&&&&&&&&&&
if(temp==paste_item){
&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&
&&&&&&&&&&
////////////////////////////////////////////
void plaf(){
&&&&&&&&&&&
UIManager.setLookAndFeel(plafName);//换外观
&&&&&&&&&&&
SwingUtilities.updateComponentTreeUI(this);//在程序里转换外观要用到此函数
&&&&&&&&&&&
this.pack();
&&&&&&&&&&&
setForeground(UIManager.getColor("Desktop.background"));
catch(Exception ep){}
/////////////////////////////////////////////////////
void jMenuItem6_actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(this,"将鼠标放在你想知道的键上可以看将其功能键!"
&&&&&&&&&&&&&&&
,"★快捷键说明!★",RMATION_MESSAGE);
public void jMenuHelpAbout_actionPerformed(ActionEvent e) {
Frame1_AboutBox dlg = new Frame1_AboutBox(this);
dlg.setBounds(this.getX()-50,this.getY()-50,584,450);
dlg.setResizable(false);
dlg.show();
//////////////////////////////////////////////////
//Sta按钮事件
public void function_button_actionPerformed(ActionEvent e) {
&& Frame1_StaBox dl = new
Frame1_StaBox();
dl.setBounds(this.getX()-100,this.getY()-100,184,150);
dl.setResizable(true);
dl.setLocation(100, 100);
dl.pack();//调整此窗口的大小& &
dl.show();
//复制事件
private Clipboard cb =
Toolkit.getDefaultToolkit().getSystemClipboard();
private void copy(){
&&&&&&&&&&&&
String str= showField.getSelectedText();
if(str==null){
&&&&&&&&&&&&&
str=showField.getText();
&&&&&&&&&&&&
StringSelection number_button=new StringSelection(str);
&&&&&&&&&&&&&
cb.setContents(number_button, null);
//粘贴事件
private void paste(){
&&&&&&&&&&
DataFlavor flavor = DataFlavor.stringF
if(cb.isDataFlavorAvailable(flavor))
String text =(String)cb.getData(flavor);
showField.replaceSelection(text);
}catch(UnsupportedFlavorException e){
JOptionPane.showMessageDialog(frame,e);
}catch(IOException e){
JOptionPane.showMessageDialog(frame,e);
///////////////////////////////////////
//单选框事件
private class radiobutton& implements
ActionListener{
public void actionPerformed(ActionEvent e){
&&&&&&&&&&&&
jPadiobutton_get=(JRadioButton)e.getSource();
&&&&&&&&&&&&
if(jPadiobutton_get==scale_button1){
&&&&&&&&&&&
& check_item3.setText("●十六进制");
&&&&&&&&&&&
& check_item4.setText(" 十进制");
&&&&&&&&&&&
& check_item5.setText(" 八进制");
&&&&&&&&&&&
& check_item6.setText("
二进制");&
&&&&&&&&&&&&&&&&
hexadecimal();
&&&&&&&&&&&&
&&&&&&&&&&&&
if(jPadiobutton_get==scale_button2){
&&&&&&&&&&&
& check_item3.setText(" 十六进制");
&&&&&&&&&&&&
& check_item4.setText("●十进制");
&&&&&&&&&&&&
& check_item5.setText(" 八进制");
&&&&&&&&&&&&
& check_item6.setText(" 二进制");
&&&&&&&&&&&&&&&
decimalism();
&&&&&&&&&&&&
&&&&&&&&&&&&
if(jPadiobutton_get==scale_button3){
&&&&&&&&&&&
& check_item3.setText(" 十六进制");
&&&&&&&&&&&&
& check_item4.setText(" 十进制");
&&&&&&&&&&&&
& check_item5.setText("●八进制");
&&&&&&&&&&&&
& check_item6.setText(" 二进制");
&&&&&&&&&&&&&&
octonary ();
&&&&&&&&&&&&
&&&&&&&&&&&&
if(jPadiobutton_get==scale_button4){
&&&&&&&&&&&
&& check_item3.setText("
十六进制");
&&&&&&&&&&&&&
& check_item4.setText(" 十进制");
&&&&&&&&&&&&&
& check_item5.setText(" 八进制");
&&&&&&&&&&&&&
& check_item6.setText("●二进制");
&&&&&&&&&&&&&&&&
&&&&&&&&&&&&
private void registerEvent(){
radiobutton& chose=new radiobutton ();
scale_button1.addActionListener(chose);
scale_button2.addActionListener(chose);
scale_button3.addActionListener(chose);
scale_button4.addActionListener(chose);
//十六进制
private void hexadecimal(){
for(int i=14;i&20;i++)
&&&&&&&&&&&
&&&&&&&&&&&&&&&
function_button2[i].setEnabled(true);
&&&&&&&&&&&&
&&&&&&&&&&&&&&&&
for(int i=2;i&10;i++)
&&&&&&&&&&&&
&&&&&&&&&&&&&&&&
number_button[i].setEnabled(true);
&&&&&&&&&&&&
&&&&&&&&&&&&
function_button1[5].setEnabled(false);
&&&&&&&&&&&&
function_button1[8].setEnabled(false);function_button1[9].setEnabled(false);
&&&&&&&&&&&
function_button1[11].setEnabled(false);function_button1[14].setEnabled(false);function_button1[17].setEnabled(false);function_button1[24].setEnabled(false);
&&&&&&&&&&&
jpanel_degree.add(word_button1);jpanel_degree.add(word_button2);jpanel_degree.add(word_button3);jpanel_degree.add(word_button4);
&&&&&&&&&&&
jpanel_degree.remove(degree_button1);jpanel_degree.remove(degree_button2);jpanel_degree.remove(degree_button3);jpanel_degree.repaint();
&&&&&&&&&&&
setVisible(true);
&&&&&&&&&&&
&&&&&&&&&&&
String hex=showField.getText().trim();
&&&&&&&&&&&
inthex=Integer.parseInt(hex,jin);//先把数变为10进制&
&&&&&&&&&&&
showField.setText(convert.decHex(inthex)) ;
&&&&&&&&&&&
catch(Exception ee)
&&&&&&&&&&
private void decimalism(){
for(int i=14;i&20;i++)
&&&&&&&&&&&
&&&&&&&&&&&&&&&
function_button2[i].setEnabled(false);
&&&&&&&&&&&&
&&&&&&&&&&&&
for(int i=2;i&10;i++)
&&&&&&&&&&&&
&&&&&&&&&&&&&&&&
number_button[i].setEnabled(true);
&&&&&&&&&&&&
&&&&&&&&&&&
function_button1[5].setEnabled(true);function_button1[8].setEnabled(true);function_button1[9].setEnabled(true);
&&&&&&&&&&&
function_button1[11].setEnabled(true);function_button1[14].setEnabled(true);function_button1[17].setEnabled(true);
&&&&&&&&&&&
function_button1[24].setEnabled(true);
&&&&&&&&&&&
jpanel_degree.add(degree_button1);jpanel_degree.add(degree_button2);jpanel_degree.add(degree_button3);
&&&&&&&&&&&
jpanel_degree.remove(word_button1);jpanel_degree.remove(word_button2);jpanel_degree.remove(word_button3);jpanel_degree.remove(word_button4);jpanel_degree.repaint();
&&&&&&&&&&&
setVisible(true);
&&&&&&&&&&&
&&&&&&&&&&&
String dec=showField.getText().trim();
&&&&&&&&&&&
int intdec=Integer.parseInt(dec,jin);
&&&&&&&&&&&
showField.setText(intdec+"");
&&&&&&&&&&&&
&&&&&&&&&&&
&&&&&&&&&&&&
catch(Exception ee)
&&&&&&&&&&&&
&&&&&&&&&&&&&
&&&&&&&&&&&&
private void octonary (){
for(int i=2;i&10;i++)
&&&&&&&&&&&&
&&&&&&&&&&&&&&&&
number_button[i].setEnabled(true);
&&&&&&&&&&&&
&&&&&&&&&&&&
for(int i=14;i&20;i++)
&&&&&&&&&&&
&&&&&&&&&&&&&&&
function_button2[i].setEnabled(false);
&&&&&&&&&&&&
&&&&&&&&&&&
number_button[8].setEnabled(false);number_button[9].setEnabled(false);function_button1[5].setEnabled(false);
&&&&&&&&&&&
function_button1[8].setEnabled(false);function_button1[9].setEnabled(false);function_button1[11].setEnabled(false);
&&&&&&&&&&&
function_button1[14].setEnabled(false);function_button1[17].setEnabled(false);
function_button1[24].setEnabled(false);
&&&&&&&&&&&&
jpanel_degree.add(word_button1);jpanel_degree.add(word_button2);jpanel_degree.add(word_button3);jpanel_degree.add(word_button4);
&&&&&&&&&&&
jpanel_degree.remove(degree_button1);jpanel_degree.remove(degree_button2);jpanel_degree.remove(degree_button3);jpanel_degree.repaint();
&&&&&&&&&&&
setVisible(true);
&&&&&&&&&&&
&&&&&&&&&&&
&&&&&&&&&&&
&String oct =showField.getText().trim();
&&&&&&&&&&&
int intoct=Integer.parseInt(oct,jin);&
&&&&&&&&&&&
showField.setText(convert.decOct(intoct)) ;
&&&&&&&&&&&
&&&&&&&&&&&
&&&&&&&&&&&
catch(Exception ee)
&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&
private void binary(){
for(int i=2;i&10;i++)
&&&&&&&&&&&&
&&&&&&&&&&&&&&&&
number_button[i].setEnabled(false);
&&&&&&&&&&&&
&&&&&&&&&&&&
for(int i=14;i&20;i++)
&&&&&&&&&&&
&&&&&&&&&&&&&&&
function_button2[i].setEnabled(false);
&&&&&&&&&&&&
&&&&&&&&&&&
function_button1[5].setEnabled(false);function_button1[8].setEnabled(false);function_button1[9].setEnabled(false);
&&&&&&&&&&&
function_button1[11].setEnabled(false);function_button1[14].setEnabled(false);function_button1[17].setEnabled(false);
&&&&&&&&&&&&
function_button1[24].setEnabled(false);
&&&&&&&&&&&&&
jpanel_degree.add(word_button1);jpanel_degree.add(word_button2);jpanel_degree.add(word_button3);jpanel_degree.add(word_button4);
&&&&&&&&&&&
jpanel_degree.remove(degree_button1);jpanel_degree.remove(degree_button2);jpanel_degree.remove(degree_button3);jpanel_degree.repaint();
&&&&&&&&&&&
setVisible(true);
&&&&&&&&&&&
&&&&&&&&&&&
String bin=showField.getText().trim();
&&&&&&&&&&&
int intbin=Integer.parseInt(bin,jin);
&&&&&&&&&&&
showField.setText(convert.decBin(intbin));
&&&&&&&&&&&
&&&&&&&&&&&
&&&&&&&&&&&
catch(Exception ee)
&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&
////////////////////////////////////////////////
//Backspace处理。
&&& private
class Monitor_backspace implements ActionListener{
public void actionPerformed(ActionEvent e){
String str1,str=showField.getText();int b = str.length();
if(b&1){showField.setText(" ");}
&&&&&&&&&&&&
str1 = str.substring(0, b - 1);
&&&&&&&&&&&&
showField.setText(String.valueOf(str1));
&&&&&&&&&&&
//C键处理(清除所有数字和运算符)
private class C implements ActionListener{
public void actionPerformed(ActionEvent e){
&&&&&&&&&&&&
showField.setText(" ");
& Operator3=" ";
& double_operator1=0;
&&&&&&&&&&&&&
//CE键处理(只清除输出框的数字)
private class CE implements ActionListener{
public void actionPerformed(ActionEvent e){
&&&&&&&&&&&&
showField.setText(" ");
&&&&&&&&&&&&&
///////////////////////////////////////////////////////
//事件监听的数字键处理。
private class Monitor_numbers implements ActionListener{
public void actionPerformed(ActionEvent e) {
&&&&&&&&&&&
&&&&&&&&&&&&&&&
showField.setText(" ");
&&&&&&&&&&&&&&&
&&&&&&&&&&&
&&&&&&&&&&&
button_get = (JButton) e.getSource();
&&&&&&&&&&&
showField.setText(showField.getText()+button_get.getText());
//事件监听的运算符号处理。
private class Monitor_symbol implements ActionListener{
public void actionPerformed(ActionEvent e){
&&&&&&&&&&&&&
button_get=(JButton)e.getSource();
&&&&&&&&&&&&&
Operator3=button_get.getText();//存放运算符
&&&&&&&&&&&&&
double_operator1 =
Double.parseDouble(showField.getText());//存放第一个操作数
&&&&&&&&&&&&&
//正负号处理。
private class Monitor_plus_minus implements ActionListener{
public void actionPerformed(ActionEvent e){
&&&&&&&&&&&&
result=-Double.parseDouble(showField.getText());
//小数点处理。
private class Monitor_point implements ActionListener{
public void actionPerformed(ActionEvent e){
&&&&&&&&&&&&&
JButton bool=(JButton)e.getSource();
&&&&&&&&&&&&&
showField.setText(showField.getText()+bool.getText());
//π处理事件。
private class Monitor_π implements ActionListener{
public void actionPerformed(ActionEvent e){
& double p=Math.PI;//获得pi的值
StringBuffer(String.valueOf(p));//为0则清空show,把按钮说代表的值新赋给show
showField.setText(show.toString());//显示show.
show=new StringBuffer("");
//存储监听
private class Monitor_Pock implements ActionListener{
public void actionPerformed(ActionEvent e) {
&&String s =
(e.getActionCommand());&&&//返回与此动作相关的命令字符串
&&if(s.equals("MC")){
&&&txfM.setText("");&&&&//将显示记忆的索引值的文本框设置为空
poke=0d;&&&&&&
&&&//newDigital
&&&&//将表示是否是新输入的数的标设置为true
&& if(s.equals("MR")){
if(txfM.getText().trim()!=""){&
showField.setText(""+poke); //显示存储的数据
if(s.equals("MS")){
poke=Double.parseDouble(showField.getText().trim());
//存储文本框中显示的数据
txfM.setText("已存");
&&&&//将显示记忆的索引值的文本框显示M
if(s.equals("M+")){
poke=poke+Double.parseDouble(showField.getText().trim());
//将显示的数字与已经存储的数据相加
//////////////////////////////////////////////////////////
//等号监听类
private class Monitor_equals implements ActionListener{
public void actionPerformed(ActionEvent e) {
&&&&&&&&&&&
&&&&&&&&&&&
double_operator2=Double.parseDouble(showField.getText());
&&&&&&&&&&&
if(Operator3.equals("+")){//判断运算符
&&&&&&&&&&&&
if(jPadiobutton_get==scale_button4){
&&&&&&&&&&&&&&&
Monitor_binary1();//调用二进制运算
&&&&&&&&&&
res=int_operator1 +int_operator2;
showField.setText(Integer.toBinaryString((int)res));
&&&&&&&&&&&&
&&&&&&&&&&&&
else if(jPadiobutton_get==scale_button3){
&&&&&&&&&&&&&&&&&
Monitor_octonary1();//调用八进制运算
&&&&&&&&&&
res=int_operator1 +int_operator2;
showField.setText(Integer.toOctalString((int)res));
&&&&&&&&&&&&
&&&&&&&&&&&&
else if(jPadiobutton_get==scale_button1){
&&&&&&&&&&&&&&&&&
Monitor_sexadecimal1();//调用十六进制运算
&&&&&&&&&&
res=int_operator1 +int_operator2;
showField.setText(Integer.toHexString((int)res));
&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&&&
result = double_operator1 + double_operator2;
&&&&&&&&&&&&&&&&&
showField.setText(String.valueOf(result));
&&&&&&&&&&&&
else& if(Operator3.equals("-")){
&&&&&&&&&&&&&
if(jPadiobutton_get==scale_button4){
&&&&&&&&&&&&&&&&
Monitor_binary1();
&&&&&&&&&&
res=int_operator1 -int_operator2;
showField.setText(Integer.toBinaryString((int)res));
&&&&&&&&&&&&
&&&&&&&&&&&&&
else if(jPadiobutton_get==scale_button3){
&&&&&&&&&&&&&&&&&
Monitor_octonary1();
&&&&&&&&&&
res=int_operator1 -int_operator2;
showField.setText(Integer.toOctalString((int)res));
&&&&&&&&&&&&
&&&&&&&&&&&&&
else if(jPadiobutton_get==scale_button1){
&&&&&&&&&&&&&&&&&
Monitor_sexadecimal1();
&&&&&&&&&&
res=int_operator1 -int_operator2;
showField.setText(Integer.toHexString((int)res));
&&&&&&&&&&&&
&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&
result=double_operator1-double_operator2;
&&&&&&&&&&&&&&&&&
showField.setText(String.valueOf(result));
&&&&&&&&&&&&&
else& if(Operator3.equals("*")){
&&&&&&&&&&&&&
if(jPadiobutton_get==scale_button4){
&&&&&&&&&&&&&&&&
Monitor_binary1();
&&&&&&&&&&
res=int_operator1 *int_operator2;
showField.setText(Integer.toBinaryString((int)res));
&&&&&&&&&&&&
&&&&&&&&&&&&&
else if(jPadiobutton_get==scale_button3){
&&&&&&&&&&&&&&&&&
Monitor_octonary1();
&&&&&&&&&&
res=int_operator1 *int_operator2;
showField.setText(Integer.toOctalString((int)res));
&&&&&&&&&&&&
&&&&&&&&&&&&&
else if(jPadiobutton_get==scale_button1){
&&&&&&&&&&&&&&&&&
Monitor_sexadecimal1();
&&&&&&&&&&
res=int_operator1 *int_operator2;
showField.setText(Integer.toHexString((int)res));
&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&
result = double_operator1 * double_operator2;
&&&&&&&&&&&&&
showField.setText(String.valueOf(result));
&&&&&&&&&&&&
else& if(Operator3.equals("/")){
&&&&&&&&&&&&&
if(double_operator2!=0){
&&&&&&&&&&&&&&&&&
if(jPadiobutton_get==scale_button4){
&&&&&&&&&&&&&&&
Monitor_binary1();
&&&&&&&&&&
res=int_operator1 /int_operator2;
showField.setText(Integer.toBinaryString((int)res));
&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&
else if(jPadiobutton_get==scale_button3){
&&&&&&&&&&&&&&&&&
Monitor_octonary1();
&&&&&&&&&&&
res=int_operator1 /int_operator2;
showField.setText(Integer.toOctalString((int)res));
&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&
else if(jPadiobutton_get==scale_button1){
&&&&&&&&&&&&&&&&&
Monitor_sexadecimal1();
&&&&&&&&&&
res=int_operator1 /int_operator2;
showField.setText(Integer.toHexString((int)res));
&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&
result=double_operator1/double_operator2;
&&&&&&&&&&&&&
showField.setText(String.valueOf(result));
&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&
&&&&&&&&&&&&&
else showField.setText("除数不能为零");
//取模运算
else& if(Operator3.equals("Mod")){
&&&&&&&&&&&&&
if(jPadiobutton_get==scale_button4){
&&&&&&&&&&&&&&&&
Monitor_binary1();
&&&&&&&&&&
res=int_operator1 %int_operator2;
showField.setText(Integer.toBinaryString((int)res));
&&&&&&&&&&&&
&&&&&&&&&&&&&
else if(jPadiobutton_get==scale_button3){
&&&&&&&&&&&&&&&&&
Monitor_octonary1();
&&&&&&&&&&
res=int_operator1 %int_operator2;
showField.setText(Integer.toOctalString((int)res));
&&&&&&&&&&&&
&&&&&&&&&&&&&
else if(jPadiobutton_get==scale_button1){
&&&&&&&&&&&&&&&&&
Monitor_sexadecimal1();
&&&&&&&&&&
res=int_operator1 %int_operator2;
showField.setText(Integer.toHexString((int)res));
&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&
result = double_operator1 % double_operator2;
&&&&&&&&&&&&&
showField.setText(String.valueOf(result));
&&&&&&&&&&&&
else& if(Operator3.equals("x^y")){
&&&&&&&&&&&&&
if(jPadiobutton_get==scale_button4){
&&&&&&&&&&&&&&&&
Monitor_binary1();
&&&&&&&&&&
res=(int) Math.pow(int_operator1,int_operator2);
showField.setText(Integer.toBinaryString((int)res));
&&&&&&&&&&&&
&&&&&&&&&&&&&
else if(jPadiobutton_get==scale_button3){
&&&&&&&&&&&&&&&&&
Monitor_octonary1();
&&&&&&&&&&&
res=(int) Math.pow(int_operator1,int_operator2);
showField.setText(Integer.toOctalString((int)res));
&&&&&&&&&&&&
&&&&&&&&&&&&&
else if(jPadiobutton_get==scale_button1){
&&&&&&&&&&&&&&&&&
Monitor_sexadecimal1();
&&&&&&&&&&
res=(int) Math.pow(int_operator1,int_operator2);
showField.setText(Integer.toHexString((int)res));
&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&
result=Math.pow(double_operator1,double_operator2);
&&&&&&&&&&&&&
showField.setText(String.valueOf(result));
&&&&&&&&&&&&
//////////////////////////////////////////
//进制运算事件监听处理
//二元运算
private void Monitor_binary1(){
//取操作数一
&&&&&&&&&&&&&&&&&&&
int_operator1=(int)double_operator1;//将其转化为整形运算
&&&&&&&&&&&&&&&&&&&&
int show,a2,a3,a4=0,
&&&&&&&&&&&&&&&&&&
show=int_operator1;a2=int_operator1;//初始化变量
&&&&&&&&&&&&&&&&&&&
for(num=0;show&0;num++) //计算位数存入edit_JMenu中
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
show=show/10;
&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
for(int j=0;j&j++){
&&&&&&&&&&&&&&&&&&&
a3=a2;&&&&&&&
//a3每次存放a2的最低位
&&&&&&&&&&&&&&&&&&&
a2=a2/10;&&&&&&&&
//a2存放去掉最低位后的数值
&&&&&&&&&&&&&&&
a4=& (int) (a4 + (a3 * Math.pow(2,
j)));//将二进制转化为十进制,并将结果给a4
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&
int_operator1=a4;//将转换的十进制送回int_operator1
&&&&&&&&&&&&&&&&&
//同理,取操作数二
&&&&&&&&&&&&&&&
int_operator2=(int)double_operator2;
&&&&&&&&&&&&&&&&
int b1,b2,b3,b4=0,n;b1=int_operator2;b2=int_operator2;
&&&&&&&&&&&&&&&&&&&
for(n=0;b1&0;n++)
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
for(int j=0;j&n;j++){
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
b4=& (int) (b4 + (b3 * Math.pow(2, j)));
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&
int_operator2=b4;//将结果送回int_operator2
//一元运算
private void Monitor_binary2(){
&&&&&&&&&&&&&&&&&&&&
int show,a2,a3,a4=0,show=s1;a2=s1;
&&&&&&&&&&&&&&&&&&&
for(num=0;show&0;num++)
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
show=show/10;
&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
for(int j=0;j&j++){
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
a4=& (int) (a4 + (a3 * Math.pow(2, j)));
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&
private void Monitor_octonary1(){
&&&&&&&&&&&&&&&&&&&
int_operator1=(int)double_operator1;
&&&&&&&&&&&&&&&&
int show,a2,a3,a4=0,show=int_operator1;a2=int_operator1;
&&&&&&&&&&&&&&&&&&&
for(num=0;show&0;num++)
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
show=show/10;
&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
for(int j=0;j&j++){
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
a4=& (int) (a4 + (a3 * Math.pow(8, j)));
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&
int_operator1=a4;
&&&&&&&&&&&&&&&
int_operator2=(int)double_operator2;
&&&&&&&&&&&&&&&&
int b1,b2,b3,b4=0,n;b1=int_operator2;b2=int_operator2;
&&&&&&&&&&&&&&&&&&&
for(n=0;b1&0;n++)
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
for(int j=0;j&n;j++){
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
b4=& (int) (b4 + (b3 * Math.pow(8, j)));
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&
int_operator2=b4;
private void Monitor_octonary2(){
&&&&&&&&&&&&&&&&&&&&
int show,a2,a3,a4=0,show=s1;a2=s1;
&&&&&&&&&&&&&&&&&&&
for(num=0;show&0;num++)
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
show=show/10;
&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
for(int j=0;j&j++){
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
a4=& (int) (a4 + (a3 * Math.pow(8, j)));
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&
private void Monitor_sexadecimal1(){
&&&&&&&&&&&&&&&&&&&
int_operator1=(int)double_operator1;
&&&&&&&&&&&&&&&&
int show,a2,a3,a4=0,show=int_operator1;a2=int_operator1;
&&&&&&&&&&&&&&&&&&&
for(num=0;show&0;num++)
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
show=show/10;
&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
for(int j=0;j&j++){
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
a4=& (int) (a4 + (a3 * Math.pow(16, j)));
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&
int_operator1=a4;
&&&&&&&&&&&&&&&
int_operator2=(int)double_operator2;
&&&&&&&&&&&&&&&&
int b1,b2,b3,b4=0,n;b1=int_operator2;b2=int_operator2;
&&&&&&&&&&&&&&&&&&&
for(n=0;b1&0;n++)
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
for(int j=0;j&n;j++){
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
b4=& (int) (b4 + (b3 * Math.pow(16, j)));
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&
int_operator2=b4;
private void Monitor_sexadecimal2(){
&&&&&&&&&&&&&&&&&&&&
int show,a2,a3,a4=0,show=s1;a2=s1;
&&&&&&&&&&&&&&&&&&&
for(num=0;show&0;num++)
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
show=show/10;
&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
for(int j=0;j&j++){
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
a4=& (int) (a4 + (a3 * Math.pow(16, j)));
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&
//////////////////////////////////////////////////
//风格监听
private class Style implements java.awt.event.ActionListener
&public void actionPerformed(ActionEvent e)
&&Object temp =
e.getSource();
&&&if(temp==SwitchPanel3)
//设置外观风格为motif风格
&& SwitchPanel2.setText("
windows");
SwitchPanel3.setText("●motif");
&& SwitchPanel4.setText("
&&&&&&&&&&
plafName="com.sun.java.swing.plaf.motif.MotifLookAndFeel";
&&&&&&&&&&&
&&&&if(temp==SwitchPanel4)
//设置外观风格为metal风格
&& SwitchPanel2.setText("
windows");
&& SwitchPanel3.setText("
SwitchPanel4.setText("●metal");
plafName="javax.swing.plaf.metal.MetalLookAndFeel";
SwitchPanel2.setText("●windows");
&& SwitchPanel3.setText("
&& SwitchPanel4.setText("
&&&&&&&&&&&&&
plafName="com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
&&&txfResult =
new JTextField("0",
30);&&&//创建用于显示操作结果文本框
&&&txfResult.setEditable(false);&&&&//设置不可编辑
&&&txfResult.setBackground(Color.white);
&&&//设置文本框颜色
&&&txfResult.setHorizontalAlignment(JTextField.RIGHT);
&//设置数组在文本框显示位置
ResultTextPanel = new
JPanel();&&&//创建用于存放显示操作结果文本框的面板
&&&ResultTextPanel.add(txfResult);&&&&//将显示操作结果文本框放入面板中
&&&txfM=new
JTextField(2);&&&&&//创建显示记忆的索引值的文本框
&&&JButton b1 =
new JButton("Backspace");
Backspace键
&&&b1.setForeground(Color.red);//设置按键颜色。
&&&JButton b2 =
new JButton("CE");
&&&b2.setForeground(Color.red);//设置按键颜色。
&&&JButton b3 =
new JButton("C");
&&&&//创建
&&&b3.setForeground(Color.red);//设置按键颜色。
ControlPanel = new
JPanel();&&&//创建用于存放面板的控制键
&&&ControlPanel.setLayout(new
GridLayout(1, 4, 2, 2));&//设置网格布局管理器
&&&ControlPanel.add(txfM);&&&&&//将显示记忆的索引值的文本框放入到面板中
&&&ControlPanel.add(b1);&&&&&//将Backspace键放入到面板中
&&&ControlPanel.add(b2);&&&&&//将CE键放入到面板中
&&&ControlPanel.add(b3);&&&&&//将C键放入到面板中
&&&b1.addActionListener(this);&&&&//向Backspace键添加监听方法
&&&b2.addActionListener(this);&&&&//向CE键添加监听方法
&&&b3.addActionListener(this);&&&&//向C键添加监听方法
dcKey[] = { "MC","7", "8", "9", "/", "sqrt", "MR","4", "5", "6",
&&&&&"MS","1",
"2", "3", "-", "1/x","M+", "0", "+/-", ".", "+", "=" };
dcKeyPanel = new
JPanel();&&&//创建用于存放数字和运算符键的面板
&&&dcKeyPanel.setLayout(new
GridLayout(4, 6, 2, 2));&//设置网格布局管理器
&&&for (int i =
0; i & 24; i++)
{&&&&//以数组的长度做为循环条件
&&&&JButton
JButton(dcKey[i]);&&//创建数字和运算符键按钮
&&&&dcKeyPanel.add(b);&&&&//将数字和运算符键按钮放入到布局管理器中
&&&&b.addActionListener(this);
&&&//向数字和运算符键添加监听方法
&&&Container ct
this.getContentPane();&&&//窗体的内容面板对象
&&&ct.setLayout(new
BorderLayout());&&&//设置边界布局管理器
&&&ct.add(ResultTextPanel,
BorderLayout.NORTH);&&//将显示结果文本框放到窗体的上部
&&&ct.add(ControlPanel,
BorderLayout.CENTER);&&//将控制键放入到窗体中央
&&&ct.add(dcKeyPanel,
BorderLayout.SOUTH);&&&//将数字和运算符键放入到窗体的下部
&&&pack();//调整此窗口的大小
&&&setVisible(true);
// 设置窗体是否显示
&&public void
actionPerformed(ActionEvent e) {
&&&String s =
(e.getActionCommand());&&&//返回与此动作相关的命令字符串
&&&String str =
txfResult.getText();&&&//获取文本框中的字符串
(s.equals("Backspace")) {
&&&&String
;&&&&//获取文本框中的字符串
&&&&txfResult.setText(s1.substring(0,
s1.length() - 1));//截取最后一个数字
(s.equals("CE") ) {
&&&&txfResult.setText("0");&&&&//
把显示屏清零
&&&&newDigital
&&&&//将表示是否是新输入的数的标设置为true
(s.equals("C")) {
&&&&txfResult.setText("0");&&&&//
把显示屏清零
&&&&optionValue
=0;&&&&&//将用于表示运算符的变量设置为0
&&&&newDigital
&&&&//将表示是否是新输入的数的标设置为true
(s.equals("0") || s.equals("1") || s.equals("2") ||
s.equals("3")
s.equals("4") || s.equals("5") || s.equals("6")
s.equals("7") || s.equals("8") || s.equals("9")) {
(!newDigital)//判断是否是新数
&&&&&txfResult.setText(str
+ s);&&//获取文本框中的字符串
&&&&&txfResult.setText(s);&&&//设置文本框中的字符串
&&&&&newDigital
&&&//将是否为新数的标志设置为false
(s.equals(".")) {
(txfResult.getText().indexOf(".") == -1){ //如果不存在小数点
(txfResult.getText().trim().startsWith("0")) {
&&&&&&txfResult.setText("0.");&//设置文本框中的字符串
&&&&&&newDigital
&&//将是否为新数的标志设置为false
&&&&&&txfResult.setText(str
+ ".");//设置文本框中的字符串
(s.equals("+/-")) {
Double.parseDouble(str.trim());&&//获取输入的数字
&&&&txfResult.setText(String.valueOf((-d)));&//取得获取输入数字的相反数
&&&newDigital =
(s.equals("+")) {
Double.parseDouble(txfResult.getText());&//获取前操作数的值
&&&&optionValue
1;&&&&//设置运算符标志
(s.equals("-")) {
Double.parseDouble(txfResult.getText());&//获取前操作数的值
&&&&optionValue
2;&&&&//设置运算符标志
(s.equals("*")) {
Double.parseDouble(txfResult.getText());&//获取前操作数的值
&&&&optionValue
3;&&&&//设置运算符标志
(s.equals("/")) {
Double.parseDouble(txfResult.getText());&//获取前操作数的值
&&&&optionValue
4;&&&&//设置运算符标志
(s.equals("=")) {
Double.parseDouble(txfResult.getText());&//获取后操作数的值
&&&&switch
(optionValue) {
&&&&&txfResult.setText(String.valueOf(d1
+ d2));//加法运算
&&&&&txfResult.setText(String.valueOf(d1
- d2));//减法运算
&&&&&txfResult.setText(String.valueOf(d1
* d2));//乘法运算
&&&&&txfResult.setText(String.valueOf(d1
/ d2));//除法运算
&&&&&}else{
&&&&&&txfResult.setText("除数不能为0");//如果该值为0不能进行除法运算
&&&&optionValue
= 0;//清空运算符
(s.equals("sqrt")) {
Double.parseDouble(txfResult.getText().trim());&&//获取操作数的值
(d &= 0) {
&&&&&txfResult.setText(String.valueOf((Math.sqrt(d))));&//计算该值的平方根
&&&&&txfResult.setText("负数不能计算平方根");&&//如果该值为负数或者0不能计算平方根
&&&} else if
(s.equals("1/x")) {
Double.parseDouble(txfResult.getText().trim());&&//计算该值的倒数
(str.equals("0")) {
&&&&&&txfResult.setText("除数不能为0");&&//如果该值为0不能计算倒数
&&&&&&txfResult.setText(String.valueOf((1
/ d))); &//计算该值求倒数
&&&} else if
(s.equals("%")) {
&&&&txfResult.setText(String.valueOf((Double.parseDouble(str)
/ 100)));//计算该值的百分数
&&&if(s.equals("MC")){
&&&&txfM.setText("");&&&&//将显示记忆的索引值的文本框设置为空
dM=0d;&&&&&&
&&&&newDigital
&&&&//将表示是否是新输入的数的标设置为true
if(s.equals("MR")){
if(txfM.getText().trim()!=""){&
txfResult.setText(""+dM); //显示存储的数据
if(s.equals("MS")){
dM=Double.parseDouble(txfResult.getText().trim());
//存储文本框中显示的数据
txfM.setText("M");
&&&&//将显示记忆的索引值的文本框显示M
if(s.equals("M+")){
dM=dM+Double.parseDouble(txfResult.getText().trim());
//将显示的数字与已经存储的数据相加
&&& public
static void main (String[] args){
//设置默认为Windows风格
&&&&&&&&&&&
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
&&&&&&&&&&
}catch(Exception e)
&&&&&&&&&&
Calculator calculator=new Calculator();
calculator.pack();
calculator.setVisible(true);
&&& public void
actionPerformed(ActionEvent e) {
已投稿到:}

我要回帖

更多关于 可编程计算器 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信