java实现编辑器的代码 java代码编辑器有哪些( 二 )


displayField.setEditable(true);
start=true;
result=0;
lastCommand = "=";
JPanel panel0=new JPanel();
panel0.setLayout(new GridLayout(1,4,4,4));
JPanel panel1=new JPanel();
panel1.setLayout(new GridLayout(1,5,4,4));
this.add(panel1);
button_sqrt=new JButton("sqrt");
button_plusminus=new JButton("+/-");
button_exp=new JButton("exp");
button_CE=new JButton("退格");
button_cancel=new JButton("C");
JPanel panel2=newJPanel();
panel2.setLayout(new GridLayout(1,5,4,4));
this.add(panel2);
button_7=new JButton("7");
button_8=new JButton("8");
button_9=new JButton("9");
button_log=new JButton("log");
button_divide=new JButton("/");
JPanel panel3=new JPanel();
panel3.setLayout(new GridLayout(1,5,4,4));
this.add(panel3);
button_4=new JButton("4");
button_5=new JButton("5");
button_6=new JButton("6");
button_tan=new JButton("tan");
button_multiply=new JButton("*");
JPanel panel4=newJPanel();
panel4.setLayout(new GridLayout(1,5,4,4));
this.add(panel4);
button_1=new JButton("1");
button_2=new JButton("2");
button_3=new JButton("3");
button_cos=new JButton("cos");
button_minus=new JButton("-");
JPanel panel5=newJPanel();
panel5.setLayout(new GridLayout(1,5,4,4));
this.add(panel5);
button_0=new JButton("0");
button_point=new JButton(".");
button_equal=new JButton("=");
button_sin=new JButton("sin");
button_plus=new JButton("+");
panel1.add(button_sqrt);
panel1.add(button_plusminus);
panel1.add(button_exp);
panel1.add(button_CE);
panel1.add(button_cancel);
panel2.add(button_7);
panel2.add(button_8);
panel2.add(button_9);
panel2.add(button_log);
panel2.add(button_divide);
panel3.add(button_4);
panel3.add(button_5);
panel3.add(button_6);
panel3.add(button_tan);
panel3.add(button_multiply);
panel4.add(button_1);
panel4.add(button_2);
panel4.add(button_3);
panel4.add(button_cos);
panel4.add(button_minus);
panel5.add(button_0);
panel5.add(button_point);
panel5.add(button_equal);
panel5.add(button_sin);
panel5.add(button_plus);
button_sqrt.addActionListener(this);
button_plusminus.addActionListener(this);
button_exp.addActionListener(this);
button_CE.addActionListener(this);
button_cancel.addActionListener(this);
button_7.addActionListener(this);
button_8.addActionListener(this);
button_9.addActionListener(this);
button_log.addActionListener(this);
button_divide.addActionListener(this);
button_4.addActionListener(this);
button_5.addActionListener(this);
button_6.addActionListener(this);
button_tan.addActionListener(this);
button_multiply.addActionListener(this);
button_1.addActionListener(this);
button_2.addActionListener(this);
button_3.addActionListener(this);
button_cos.addActionListener(this);
button_minus.addActionListener(this);
button_0.addActionListener(this);
button_point.addActionListener(this);
button_equal.addActionListener(this);
button_sin.addActionListener(this);
button_plus.addActionListener(this);
this.addWindowListener(new WinClose());//注册窗口监听器
this.setVisible(true);
}
private void addmyMenu()//菜单的添加
{
JMenuBar menubar=new JMenuBar();
this.add(menubar);
JMenu m1=new JMenu("选项");
JMenu m2=new JMenu("进制转换");
JMenuItem m1_exit=new JMenuItem("退出");
m1_exit.addActionListener(this);
JMenuItem m2_ejz=new JMenuItem("二进制");
m2_ejz.addActionListener(this);
JMenuItem m2_bjz=new JMenuItem("八进制");
m2_bjz.addActionListener(this);

推荐阅读