香山风乘.docx
- 文档编号:27935602
- 上传时间:2023-07-06
- 格式:DOCX
- 页数:24
- 大小:23.16KB
香山风乘.docx
《香山风乘.docx》由会员分享,可在线阅读,更多相关《香山风乘.docx(24页珍藏版)》请在冰豆网上搜索。
香山风乘
本文是JavaSE实现的一个计算器框架,基本实现加减乘除,copy进Eclipse平台即可运行。
如果有读者想扩展自行添加算法方法,本程序没有实现面向对象编程。
前面一个类,是视图类,后一个是算法类。
——香山風乘
/*
*Counter.java
*
*Createdon__DATE__,__TIME__
*/
packageambow.counter;
importjava.awt.Toolkit;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
/**
*
*@author__USER__
*/
publicclassCounterextendsjavax.swing.JFrame{
/**CreatesnewformCounter*/
publicCounter(){
initComponents();
}
//GEN-BEGIN:
initComponents
//
privatevoidinitComponents(){
finalBackstagestage=newBackstage();
left_Up=newjavax.swing.JPanel();
leftUp_MR=newjavax.swing.JButton();
leftUp_MC=newjavax.swing.JButton();
leftUp_MS=newjavax.swing.JButton();
leftUp_M_jia=newjavax.swing.JButton();
right_down=newjavax.swing.JPanel();
rightDown7=newjavax.swing.JButton();
rightDown8=newjavax.swing.JButton();
rightDown9=newjavax.swing.JButton();
rightDown_chu=newjavax.swing.JButton();
rightDown_sqrt=newjavax.swing.JButton();
rightDown4=newjavax.swing.JButton();
rightDown5=newjavax.swing.JButton();
rightDown6=newjavax.swing.JButton();
rightDown_cheng=newjavax.swing.JButton();
rightDown_quyu=newjavax.swing.JButton();
rightDown1=newjavax.swing.JButton();
rightDown2=newjavax.swing.JButton();
rightDown3=newjavax.swing.JButton();
rightDown_jian=newjavax.swing.JButton();
rightDown_fenzhi=newjavax.swing.JButton();
rightDown0=newjavax.swing.JButton();
rightDown_jia_jian=newjavax.swing.JButton();
rightDown_xiaoshu=newjavax.swing.JButton();
rightDown_jia=newjavax.swing.JButton();
rightDown_dengyu=newjavax.swing.JButton();
right_center=newjavax.swing.JPanel();
rightUp_Backspace=newjavax.swing.JButton();
rightUp_CE=newjavax.swing.JButton();
rightUp_C=newjavax.swing.JButton();
left_Space=newjavax.swing.JButton();
up_text=newjavax.swing.JTextField();
//设置居中
Toolkittit=Toolkit.getDefaultToolkit();
setLocation((tit.getScreenSize().height)/2,
(tit.getScreenSize().width)/2);
//设置默认关闭方式
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
//设置大小
setMinimumSize(newjava.awt.Dimension(260,237));
//设置窗口是否可变的大小
setResizable(false);
//设置布局管理
getContentPane().setLayout(null);
//设置左上的布局方式
left_Up.setLayout(newjava.awt.GridLayout(4,2,2,2));
//MR
leftUp_MR.setBackground(newjava.awt.Color(153,255,204));
leftUp_MR.setText("MR");
leftUp_MR.setBorder(newjavax.swing.border.SoftBevelBorder(
javax.swing.border.BevelBorder.RAISED));
left_Up.add(leftUp_MR);
//MC
leftUp_MC.setBackground(newjava.awt.Color(153,255,204));
leftUp_MC.setText("MC");
leftUp_MC.setBorder(newjavax.swing.border.SoftBevelBorder(
javax.swing.border.BevelBorder.RAISED));
left_Up.add(leftUp_MC);
//MS
leftUp_MS.setBackground(newjava.awt.Color(153,255,204));
leftUp_MS.setText("MS");
leftUp_MS.setBorder(newjavax.swing.border.SoftBevelBorder(
javax.swing.border.BevelBorder.RAISED));
left_Up.add(leftUp_MS);
//M+
leftUp_M_jia.setBackground(newjava.awt.Color(153,255,204));
leftUp_M_jia.setText("M+");
leftUp_M_jia.setBorder(newjavax.swing.border.SoftBevelBorder(
javax.swing.border.BevelBorder.RAISED));
left_Up.add(leftUp_M_jia);
//加载到JFrame
getContentPane().add(left_Up);
left_Up.setBounds(10,80,40,130);
//设置右下的布局管理器
right_down.setLayout(newjava.awt.GridLayout(4,2,2,2));
//7
rightDown7.setBackground(newjava.awt.Color(153,255,204));
rightDown7.setText("7");
rightDown7.setBorder(newjavax.swing.border.SoftBevelBorder(
javax.swing.border.BevelBorder.RAISED));
right_down.add(rightDown7);
rightDown7.addActionListener(newActionListener(){
@Override
publicvoidactionPerformed(ActionEvente){
//TODOAuto-generatedmethodstub
stage.input("7");
up_text.setText(stage.output());
System.out.println(stage.output());
}
});
//8
rightDown8.setBackground(newjava.awt.Color(153,255,204));
rightDown8.setText("8");
rightDown8.setBorder(newjavax.swing.border.SoftBevelBorder(
javax.swing.border.BevelBorder.RAISED));
rightDown8.addActionListener(newActionListener(){
@Override
publicvoidactionPerformed(ActionEvente){
//TODOAuto-generatedmethodstub
stage.input("8");
up_text.setText(stage.output());
System.out.println(stage.output());
}
});
right_down.add(rightDown8);
//9
rightDown9.setBackground(newjava.awt.Color(153,255,204));
rightDown9.setText("9");
rightDown9.setBorder(newjavax.swing.border.SoftBevelBorder(
javax.swing.border.BevelBorder.RAISED));
right_down.add(rightDown9);
rightDown9.addActionListener(newActionListener(){
@Override
publicvoidactionPerformed(ActionEvente){
//TODOAuto-generatedmethodstub
stage.input("9");
up_text.setText(stage.output());
System.out.println(stage.output());
}
});
///
rightDown_chu.setBackground(newjava.awt.Color(153,255,204));
rightDown_chu.setText("/");
rightDown_chu.setBorder(newjavax.swing.border.SoftBevelBorder(
javax.swing.border.BevelBorder.RAISED));
right_down.add(rightDown_chu);
rightDown_chu.addActionListener(newActionListener(){
@Override
publicvoidactionPerformed(ActionEvente){
//TODOAuto-generatedmethodstub
stage.setInputFlag(false);
stage.couter();
stage.record(4);
stage.setText(true);
up_text.setText(stage.output());
}
});
//sqrt
rightDown_sqrt.setBackground(newjava.awt.Color(153,255,204));
rightDown_sqrt.setText("sqrt");
rightDown_sqrt.setBorder(newjavax.swing.border.SoftBevelBorder(
javax.swing.border.BevelBorder.RAISED));
right_down.add(rightDown_sqrt);
//4
rightDown4.setBackground(newjava.awt.Color(153,255,204));
rightDown4.setText("4");
rightDown4.setBorder(newjavax.swing.border.SoftBevelBorder(
javax.swing.border.BevelBorder.RAISED));
right_down.add(rightDown4);
rightDown4.addActionListener(newActionListener(){
@Override
publicvoidactionPerformed(ActionEvente){
//TODOAuto-generatedmethodstub
stage.input("4");
up_text.setText(stage.output());
System.out.println(stage.output());
}
});
//5
rightDown5.setBackground(newjava.awt.Color(153,255,204));
rightDown5.setText("5");
rightDown5.setBorder(newjavax.swing.border.SoftBevelBorder(
javax.swing.border.BevelBorder.RAISED));
right_down.add(rightDown5);
rightDown5.addActionListener(newActionListener(){
@Override
publicvoidactionPerformed(ActionEvente){
//TODOAuto-generatedmethodstub
stage.input("5");
up_text.setText(stage.output());
System.out.println(stage.output());
}
});
//6
rightDown6.setBackground(newjava.awt.Color(153,255,204));
rightDown6.setText("6");
rightDown6.setBorder(newjavax.swing.border.SoftBevelBorder(
javax.swing.border.BevelBorder.RAISED));
right_down.add(rightDown6);
rightDown6.addActionListener(newActionListener(){
@Override
publicvoidactionPerformed(ActionEvente){
//TODOAuto-generatedmethodstub
stage.input("6");
up_text.setText(stage.output());
System.out.println(stage.output());
}
});
//*
rightDown_cheng.setBackground(newjava.awt.Color(153,255,204));
rightDown_cheng.setText("*");
rightDown_cheng.setBorder(newjavax.swing.border.SoftBevelBorder(
javax.swing.border.BevelBorder.RAISED));
right_down.add(rightDown_cheng);
rightDown_cheng.addActionListener(newActionListener(){
@Override
publicvoidactionPerformed(ActionEvente){
//TODOAuto-generatedmethodstub
stage.setInputFlag(false);
stage.couter();
stage.record(3);
stage.setText(true);
up_text.setText(stage.output());
}
});
//%
rightDown_quyu.setBackground(newjava.awt.Color(153,255,204));
rightDown_quyu.setText("%");
rightDown_quyu.setBorder(newjavax.swing.border.SoftBevelBorder(
javax.swing.border.BevelBorder.RAISED));
right_down.add(rightDown_quyu);
//1
rightDown1.setBackground(newjava.awt.Color(153,255,204));
rightDown1.setText("1");
rightDown1.setBorder(newjavax.swing.border.SoftBevelBorder(
javax.swing.border.BevelBorder.RAISED));
right_down.add(rightDown1);
rightDown1.addActionListener(newActionListener(){
@Override
publicvoidactionPerformed(ActionEvente){
//TODOAuto-generatedmethodstub
stage.input("1");
up_text.setText(stage.output());
System.out.println(stage.output());
}
});
//2
rightDown2.setBackground(newjava.awt.Color(153,255,204));
rightDown2.setText("2");
rightDown2.setBorder(newjavax.swing.border.SoftBevelBorder(
javax.swing.border.BevelBorder.RAISED));
right_down.add(rightDown2);
rightDown2.addActionListener(newActionListener(){
@Override
publicvoidactionPerformed(ActionEvente){
//TODOAuto-generatedmethodstub
stage.input("2");
up_text.setText(stage.output());
System.out.println(stage.output());
}
});
//3
rightDown3.setBackground(newjava.awt.Color(153,255,204));
rightDown3.setText("3");
rightDown3.setBorder(newjavax.swing.border.SoftBevelBorder(
javax.swing.border.BevelBorder.RAISED));
right_down.add(rightDown3);
rightDown3.addActionListener(newActionListener(){
@Override
publicvoidactionPerformed(ActionEvente){
//TODOAuto-generatedmethodstub
stage.input("3");
up_text.setText(stage.output());
System.out.println(stage.output());
}
});
//-
rightDown_jian.setBackground(new
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 香山