Java课程设计计算器源程序代码.

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

j.gridx=210; i.setConstraints(b03,j; panel2.add(b03; j.gridx=280; i.setConstraints(b05,j; panel2.add(b05; c.gridy=120; c.gridheight=80; c.weighty=10.0; g.setConstraints(panel3,c; panel1.add(panel3; panel3.setLayout(new GridLayout(4,5;//pencel3面板设置为 4 行 5 列共 20 个网格 panel3.add(b1; panel3.add(b2; panel3.add(b3; panel3.add(b4; panel3.add(b5添;/加/ 按钮 panel3.add(b6; panel3.add(b7; panel3.add(b8; panel3.add(b9; panel3.add(b10; panel3.add(b11; panel3.add(b12; panel3.add(b13; panel3.add(b14; panel3.add(b15; panel3.add(b16; panel3.add(b17; panel3.add(b18; panel3.add(b19; panel3.add(b20; menuitem1.addActionListener(this; menuitem2.addActionListener(this; menuitem3.addActionListener(this;//注册菜单项的事件监听器
b03=new JButton("C"; b04=new JButton("ON"; b05=new JButton("OFF"; setSize(350,240; label.setBorder(BorderFactory.createBevelBorder(1;/建/ 立一个立体的边界 label.setOpaque(true;/设/ 置不透明 ,以便设置背景色 label.setBackground(Color.white;//设置背景色白色 label.setHorizontalAlignment(SwingConstants.RIGHT; label.setCursor(new Cursor(Cursor.TEXT_CURSOR; add(panel1; GridBagLayout g=new GridBagLayout(; GridBagConstraints c=new GridBagConstraints(; panel1.setSize(350,200; panel1.setLayout(g; c.gridx=0; c.gridy=0;// 这个属性是用来描述组件在布局时应处于那个网格位置 , 即描述网格开始的位置 .gridx=0,gridy=0 时放在 0 行 0 列 . c.gridwidth=350; c.gridheight=20;// 这两个属性用来描述组件在布局中的所占的 网格的个数 ,gridwidth 描述了该组件在横向上所占网格的个数 ,gridheight 描述了该组 件在纵向上所占网格的个数 c.fill=GridBagConstraints.BOTH;
package jisuanqi; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; public class JiSuanQi extends JFrame implements ActionListener{// JiSuanQ继i 承 Frame实现 ActionListener 接口 JMenuBar menubar;/定/ 义一个菜单 JMenu menu1,menu2,menu3;/定/ 义菜单组件各个部分的对象 JMenuItem menuitem1,menuitem2,menuitem3,menuitem4,menuitem5;定// 义对象 下的菜单项 JLabel label; JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b01,b02, b03,b04,b05; JPanel panel1,panel2,panel3;定// 义三个面板 String a="0"; boolean b,c; Double m=0.0,n=0.0,r=0.0; Integer h=0;
b1.addActionListener(this; b2.addActionListener(this; b3.addActionListener(this; b4.addActionListener(this; b5.addActionListener(this; b6.addActionListener(this; b7.addActionListener(this; b8.addActionListener(this; b9.addActionListener(this; b10.addActionListener(this; b11.addActionListener(this; b12.addActionListener(this; b13.addActionListener(this; b14.addActionListener(this; b15.addActionListener(this; b16.addActionListener(this; b17.addActionListener(this; b18.addActionListener(this; b19.addActionListener(this; b20.addActionListener(this; b01.addActionListener(this; b02.addActionListener(this; b03.addActionListener(this; b04.addActionListener(this; b05.addActionListener(this; }// 给按钮注册事件监视器 public void actionPerformed(ActionEvent e{// 处理按钮事件 if(e.getSource(==menuitem1{label.setText(a; b=true;} else if(e.getSource(==menuitem2{label.setText(""; b=false;} else if(e.getSource(==menuitem3{System.exit(0;} else if(e.getSource(==b04{label.setText(a; b=true;} else if(e.getSource(==b05{label.setText(""; b=false;} if(b{ if(e.getSource(==b1{ if(label.getText(.equals("0"{label.setText("7";}
int d; public JiSuanQi({ setTitle("jisuanqi"; panel1=new JPanel(; panel2=new JPanel(; panel3=new JPanel(; menubar=new JMenuBar(;//以下生成菜单组件对象 menu1=new JMenu("File"; menu2=new JMenu("Edit"; menu3=new JMenu("Help"; menuitem1=new JMenuItem("ON"; menuitem2=new JMenuItem("OFF"; menuitem3=new JMenuItem("Close"; menuitem4=new JMenuItem("Copy"; menuitem5=new JMenuItem("Help"; label=new JLabel(""; b1=new JButton("7"; b2=new JButton("8"; b3=new JButton("9";
Baidu Nhomakorabea
c.weighty=3.0; g.setConstraints(panel2,c; panel1.add(panel2; GridBagLayout i=new GridBagLayout(; GridBagConstraints j=new GridBagConstraints(; panel2.setLayout(i; j.gridx=0; j.gridy=0; j.gridwidth=68; j.gridheight=40; j.fill=GridBagConstraints.BOTH; j.insets=new Insets(1,1,1,1; j.weightx=3.0; j.weighty=3.0; i.setConstraints(b04,j; panel2.add(b04; j.gridx=70; i.setConstraints(b01,j; panel2.add(b01; j.gridx=140; i.setConstraints(b02,j; panel2.add(b02;
else{ if(!c{label.setText(label.getText(.concat("7";} else{label.setText("7"; c=false; n=0.0;} } } if(e.getSource(==b2{ if(label.getText(.equals("0"{label.setText("8";} else{ if(!c{label.setText(label.getText(.concat("8";} else{label.setText("8"; c=false; n=0.0;} } } if(e.getSource(==b3{ if(label.getText(.equals("0"{label.setText("9";} else{ if(!c{label.setText(label.getText(.concat("9";} else{label.setText("9"; c=false; n=0.0;} } }
c.insets=new Insets(1,1,1,1;//设置组件之间彼此的间距。 c.weightx=10.0; c.weighty=0.0; g.setConstraints(menubar,c; panel1.add(menubar; menubar.add(menu1; menubar.add(menu2; menubar.add(menu3; menu1.add(menuitem1; menu1.add(menuitem2; menu1.addSeparator(; menu1.add(menuitem3; menu2.add(menuitem4; menu3.add(menuitem5; c.gridy=20; c.gridheight=50; g.setConstraints(label,c; panel1.add(label; c.gridy=70; c.gridheight=50;
b4=new JButton("/"; b5=new JButton("sqrt"; b6=new JButton("4"; b7=new JButton("5"; b8=new JButton("6"; b9=new JButton("*"; b10=new JButton("%"; b11=new JButton("1"; b12=new JButton("2"; b13=new JButton("3"; b14=new JButton("-"; b15=new JButton("1/x"; b16=new JButton("0"; b17=new JButton("+/-"; b18=new JButton("."; b19=new JButton("+"; b20=new JButton("="; b01=new JButton("Backspace"; b02=new JButton("CE";
相关文档
最新文档