java运算器代码 java算术运算符代码( 三 )


mnuEdit.addMenuListener(this);
mnuCheck.addMenuListener(this);
mnuHelp.addMenuListener(this);
mnuCopy.addActionListener(this);
mnuPaste.addActionListener(this);
mnuVisit.addActionListener(this);
mnuAbout.addActionListener(this);
mnuNotepad.add(mnuEdit);
mnuNotepad.add(mnuCheck);
mnuNotepad.add(mnuHelp);
mnuEdit.add(mnuCopy);
mnuEdit.add(mnuPaste);
mnuEdit.add(sep);
mnuHelp.add(mnuVisit);
mnuHelp.add(sep);
mnuHelp.add(mnuAbout);
p1.add(mnuNotepad);
p1.add(jt1);
p2=new JPanel();
p2.setLayout(new FlowLayout(FlowLayout.CENTER));
bM = new JButton(" ");
bM.setEnabled(false);
p2.add(bM);
Button b25=new Button("Backspace");
b25.addActionListener(this);
Button b26=new Button("CE");
b26.addActionListener(this);
Button b27=new Button("C");
b27.addActionListener(this);
p2.add(b25);
p2.add(b26);
p2.add(b27);
p3=new JPanel();
p3.setLayout(new GridLayout(4,6));
Button button1=new Button("MC");
button1.addActionListener(this);
Button button2=new Button("7");
button2.addActionListener(this);
Button button3=new Button("8");
button3.addActionListener(this);
Button button4=new Button("9");
button4.addActionListener(this);
Button button5=new Button("/");
button5.addActionListener(this);
Button button6=new Button("sqrt");
button6.addActionListener(this);
Button button7=new Button("MR");
button7.addActionListener(this);
Button button8=new Button("4");
button8.addActionListener(this);
Button button9=new Button("5");
button9.addActionListener(this);
Button button10=new Button("6");
button10.addActionListener(this);
Button button11=new Button("*");
button11.addActionListener(this);
Button button12=new Button("%");
button12.addActionListener(this);
Button button13=new Button("MS");
button13.addActionListener(this);
Button button14=new Button("1");
button14.addActionListener(this);
Button button15=new Button("2");
button15.addActionListener(this);
Button button16=new Button("3");
button16.addActionListener(this);
Button button17=new Button("-");
button17.addActionListener(this);
Button button18=new Button("1/x");
button18.addActionListener(this);
Button button19=new Button("M+");
button19.addActionListener(this);
Button button20=new Button("0");
button20.addActionListener(this);
Button button21=new Button("+/-");
button21.addActionListener(this);
Button button22=new Button(".");
button22.addActionListener(this);
Button button23=new Button("+");
button23.addActionListener(this);
Button button24=new Button("=");
button24.addActionListener(this);
p3.add(button1);p3.add(button2);
p3.add(button3);p3.add(button4);
p3.add(button5);p3.add(button6);
p3.add(button7);p3.add(button8);
p3.add(button9);p3.add(button10);
p3.add(button11);p3.add(button12);
p3.add(button13);p3.add(button14);
p3.add(button15);p3.add(button16);
p3.add(button17);p3.add(button18);
p3.add(button19);p3.add(button20);
p3.add(button21);p3.add(button22);
p3.add(button23);p3.add(button24);
setSize(250,150);
mainp=new JPanel();
mainp.setLayout(new GridLayout(3,1));
mainp.add(p1);
mainp.add(p2);
mainp.add(p3);
setContentPane(mainp);
setTitle("计算器");
setSize(300,300);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
String s= e.getActionCommand();
if (s.equals("复制(C)")) {
String temp = jt1.getText().trim();
copyBoard.replace(0, copyBoard.length(), temp);
mnuPaste.setEnabled(true);

推荐阅读