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();//对计算器进行初始化
}
/**
* 初始化操作
* 添加按钮
推荐阅读
- pg提取安装包,ios如何提取安装包ipa
- 做学校公众号怎么变现的,学校公众号运营工作怎么做
- 网页里的东西怎么移到u盘,网页里的东西怎么移到u盘里面
- python函数的创建 python 创建函数
- 哔哩哔哩css3和canvas,哔哩哔哩html5播放器
- 盒子怎么安装电视机上,电视盒子怎么装软件教程
- c语言中函数能相加吗 c语言可以用函数作为参数吗
- jquerythis获取值,jquery获取属性的方法
- 显卡上的io挡板怎么拆,显卡挡板在哪