预览加载中,请您耐心等待几秒...
1/7
2/7
3/7
4/7
5/7
6/7
7/7

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

importjava.awt.BorderLayout; importjava.awt.Color; importjava.awt.GridLayout; importjava.awt.event.ActionEvent; importjava.awt.event.ActionListener; importjava.awt.event.KeyEvent; importjava.awt.event.KeyListener; importjavax.swing.JButton; importjavax.swing.JFrame; importjavax.swing.JPanel; importjavax.swing.JTextField; /*使用java语言开发一个简易计算器 * * */ publicclassTestJsqextendsJFrameimplementsActionListener,KeyListener{ privateJTextFieldjtf; privateJButtonjb_bk,jb_ce,jb_c; privateStringxs=""; privatedoublesum=0; privateintfh; publicstaticvoidmain(String[]args){ newTestJsq().creatCUI(); } publicvoidcreatCUI(){ JFramejf=newJFrame(); jf.setTitle("计算器"); jtf=newJTextField("0."); jtf.setHorizontalAlignment(JTextField.RIGHT); jf.add(jtf,BorderLayout.NORTH); JPaneljp_main=newJPanel(newBorderLayout()); jf.add(jp_main); JPaneljp1=newJPanel(newGridLayout(1,3,1,1)); jb_bk=newJButton("Backspace"); jb_bk.setForeground(Color.RED); jb_bk.addActionListener(this); jb_ce=newJButton("CE"); jb_ce.setForeground(Color.RED); jb_ce.addActionListener(this); jb_c=newJButton("C"); jb_c.setForeground(Color.RED); jb_c.addActionListener(this); jp1.add(jb_bk); jp1.add(jb_ce); jp1.add(jb_c); jp_main.add(jp1,BorderLayout.NORTH); JPaneljp2=newJPanel(newGridLayout(4,5,1,1)); Stringstr[]={"7","8","9","/","sqrt","4","5","6","*","%", "1","2","3","-","1/x","0","+/-",".","+","="}; for(inti=0;i<20;i++){ JButtonjb=newJButton(str[i]); jb.addActionListener(this); jb.setForeground(Color.blue); if(i==3||i==8||i==13||i==18||i==19){ jb.setForeground(Color.RED); } jp2.add(jb); } jp_main.add(jp2,BorderLayout.CENTER); jf.setResizable(false); jf.setBounds(50,50,350,350); jf.setVisible(true); } @Override publicvoidactionPerformed(ActionEvente){ Strings=e.getActionCommand(); if(s.equals("CE")||s.equals("C")){ xs=""; jtf.setText("0."); }elseif(s.equals("Backspace")){ Stringstr=xs.substring(0,xs.length()-1)