欢迎来到冰点文库! | 帮助中心 分享价值,成长自我!
冰点文库
全部分类
  • 临时分类>
  • IT计算机>
  • 经管营销>
  • 医药卫生>
  • 自然科学>
  • 农林牧渔>
  • 人文社科>
  • 工程科技>
  • PPT模板>
  • 求职职场>
  • 解决方案>
  • 总结汇报>
  • ImageVerifierCode 换一换
    首页 冰点文库 > 资源分类 > DOCX文档下载
    分享到微信 分享到微博 分享到QQ空间

    Java计算器源代码.docx

    • 资源ID:9687611       资源大小:34.71KB        全文页数:37页
    • 资源格式: DOCX        下载积分:1金币
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录
    二维码
    微信扫一扫登录
    下载资源需要1金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP,免费下载
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    Java计算器源代码.docx

    1、Java计算器源代码Java计算器源代码该计算器有两个主要部分,标准计算器和科学计算器,科学计算器功能尚未完成。用的知识:按钮,菜单,布局,面板,窗口,事件,对话框,标签,单选钮。有兴趣的读者可以完成剩下的功能。组成:三个源程序:Cal.java,BPanel.java,KPanel.java/ / Cal.java /package cal;import java.awt.CardLayout;import java.awt.Color;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.Font;impo

    2、rt java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.InputEvent;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.KeyEvent;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;impor

    3、t javax.swing.ButtonGroup;import javax.swing.ImageIcon;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JPanel;import javax.swing.JRadioButtonMenuItem;import javax.swing

    4、.KeyStroke;public class Cal extends JFrame /* * */ private static final long serialVersionUID = 1L; private JMenuBar mb=null; private JMenu m1=null; private JMenu m2=null; private JMenu m4=null; private JMenuItem mt1=null; public static JMenuItem mt2=null; private JRadioButtonMenuItem mt3=null; priv

    5、ate JRadioButtonMenuItem mt4=null; private JMenuItem mt6=null; private JMenuItem mt7=null; private BPanel bp=new BPanel(); private KPanel kp=new KPanel(); private JPanel p=new JPanel(); private static boolean card=true; public static boolean fz=false; public static String str=new String(); private J

    6、Panel p1=new JPanel(); private CardLayout c1=new CardLayout(); private JLabel b=new JLabel(); static Cal calc; final JDialog d1=new JDialog(); final JDialog d2=new JDialog(); public static Color bc=new Color(255,204,204); public static Color qc=Color.cyan; private Font f=new Font(宋体, Font.BOLD, 15);

    7、 private Cal() super( 计算器 ); this.setLocation(400, 250); this.setForeground(qc); this.setBackground(bc); this.setIconImage(new ImageIcon(jsq.jpg).getImage(); JFrame.setDefaultLookAndFeelDecorated(true); p=(JPanel) this.getContentPane(); p.setLayout(new FlowLayout(); p.add(b); p.add(p1); p1.setLayout

    8、(c1); p1.add(card1,bp); p1.add(card2,kp); this.setJMenuBar(getMb(); initDialog1(); initDialog2(); this.pack(); this.setResizable(false); this.setVisible(true); protected void processWindowEvent(WindowEvent e) if(e.getID()=WindowEvent.WINDOW_CLOSING) System.exit(0); private JMenuBar getMb() mb=new JM

    9、enuBar(); mb.setPreferredSize(new Dimension(110, 35); mb.setForeground(qc); mb.setBackground(bc); mb.add(getM1(); mb.add(getM2(); mb.add(getM4(); return mb; private JMenu getM1() m1=new JMenu( 编辑(F) ); m1.setFont(f); m1.setBackground(bc); m1.add(getMt1(); m1.add(getMt2(); return m1; private JMenu ge

    10、tM2() m2=new JMenu( 类型(L) ); m2.setFont(f); m2.setBackground(bc); m2.add(getMt3(); m2.add(getMt4(); ButtonGroup bg=new ButtonGroup(); bg.add(mt3); mt3.setSelected(true); bg.add(mt4); return m2; private JMenu getM4() m4=new JMenu( 帮助(H) ); m4.setFont(f); m4.setBackground(bc); m4.add(getMt6(); m4.add(

    11、getMt7(); return m4; private JMenuItem getMt1() mt1=new JMenuItem( 复制 ); mt1.setFont(f); mt1.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_C,InputEvent.CTRL_MASK); mt1.setPreferredSize(new Dimension(130, 30); mt1.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e)

    12、try if(card) if(bp.getTextField().getSelectedText().isEmpty() str=bp.getTextField().getText(); else str=bp.getTextField().getSelectedText(); catch(Exception tx) str=bp.getTextField().getText(); if(!str.isEmpty()&!str.equals(0) mt2.setEnabled(true); BPanel.jp2.setEnabled(true); ); return mt1; private

    13、 JMenuItem getMt2() mt2=new JMenuItem( 粘贴 ); mt2.setFont(f); mt2.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_V,InputEvent.CTRL_MASK); mt2.setPreferredSize(new Dimension(130, 30); mt2.setEnabled(false); mt2.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) if(ca

    14、rd) bp.getTextField().setText(str); fz=true; /esle /kp.getTextField().setText(str); ); return mt2; private JRadioButtonMenuItem getMt3() mt3=new JRadioButtonMenuItem(标准计算器); mt3.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_B,InputEvent.CTRL_MASK); mt3.setFont(f); mt3.setPreferredSize(new Dimen

    15、sion(130, 30); mt3.addItemListener(new ItemListener() public void itemStateChanged(ItemEvent e) c1.first(p1); ); return mt3; private JRadioButtonMenuItem getMt4() mt4=new JRadioButtonMenuItem(科学计算器); mt4.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_K,InputEvent.CTRL_MASK); mt4.setFont(f); mt4.

    16、setPreferredSize(new Dimension(130, 30); mt4.addItemListener(new ItemListener() public void itemStateChanged(ItemEvent e) c1.last(p1); ); return mt4; private JMenuItem getMt6() mt6=new JMenuItem(关于计算器); mt6.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_G,InputEvent.CTRL_MASK); mt6.setFont(f); m

    17、t6.setPreferredSize(new Dimension(130, 30); mt6.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) d1.setVisible(true); ); return mt6; private JMenuItem getMt7() mt7=new JMenuItem( 帮助 ); mt7.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_H,InputEvent.CTRL_MASK); mt

    18、7.setFont(f); mt7.setPreferredSize(new Dimension(130, 30); mt7.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) d2.setVisible(true); ); return mt7; public void initDialog1() d1.setTitle( 关于计算器 ); JDialog.setDefaultLookAndFeelDecorated(true); String s1=计算器由标准计算器和科学计算器

    19、组成; String s2=j2se版本:jdk1.6。本人QQ:1286908118; Font font=new Font(宋体,Font.BOLD,20); JLabel l1=new JLabel(s1); JLabel l2=new JLabel(s2); JPanel dp=(JPanel) d1.getContentPane(); dp.setLayout(new GridLayout(2,1); dp.setBackground(Color.pink); dp.setForeground(Color.pink); l1.setForeground(Color.blue); l1

    20、.setFont(font); dp.add(l1); l2.setForeground(Color.red); l2.setFont(font); dp.add(l2); d1.setSize(400,200); d1.setFont(f); d1.setLocation(500, 300); d1.setResizable(false); d1.addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) d1.setVisible(false); ); public void initDial

    21、og2() d2.setTitle( 帮助 ); String s1=复制快捷键为ctrl+c; String s2=粘贴快捷键为ctrl+v; Font font=new Font(宋体,Font.BOLD,20); JLabel l1=new JLabel(s1); JLabel l2=new JLabel(s2); JPanel dp=(JPanel)d2.getContentPane(); dp.setLayout(new GridLayout(2,1); dp.setBackground(Color.pink); dp.setForeground(Color.pink); l1.se

    22、tFont(font); l1.setForeground(Color.blue); dp.add(l1); l2.setFont(font); l1.setForeground(Color.blue); dp.add(l2); d2.setSize(new Dimension(400,240); d2.setResizable(false); d2.setFont(f); d2.setLocation(500, 300); JDialog.setDefaultLookAndFeelDecorated(true); d2.addWindowListener(new WindowAdapter(

    23、) public void windowClosing(WindowEvent e) d2.setVisible(false); ); public static void main(String args) calc=new Cal(); / /BPanel.java/package cal;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.GridLayout;import java.awt.event.Actio

    24、nEvent;import java.awt.event.ActionListener;import java.awt.event.InputEvent;import java.awt.event.KeyEvent;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import javax.swing.JButton;import javax.swing.JMenuItem;import javax.swing.JPanel;import javax.swing.JPopupMenu;import javax

    25、.swing.JTextField;import javax.swing.KeyStroke;import javax.swing.SwingUtilities;public class BPanel extends JPanel implements ActionListener /* * */ private static final long serialVersionUID = 1L; JTextField tf=null; private JButton s1=null; private JButton s2=null; private JButton s3=null; privat

    26、e JButton s4=null; private JButton s5=null; private JButton s6=null; private JButton s7=null; private JButton s8=null; private JButton s9=null; private JButton s0=null; private JButton f1=null; private JButton f2=null; private JButton f3=null; private JButton f4=null; private JButton f5=null; privat

    27、e JButton f6=null; private JButton c1=null; private JButton c2=null; private JButton d1=null; private JButton d2=null; private JPopupMenu jpm=null; private JMenuItem jp1=null; public static JMenuItem jp2=null; private JPanel pp=new JPanel(); private static boolean add=false, sub=false,mul=false, div

    28、=false,qy=false,sz=false,jg=false, v1=false,v2=false; private static double value1=0d; private static double value2=0d; private int num=0; private Font f=new Font(宋体, Font.BOLD, 16); private Font sign=new Font(宋体, Font.BOLD, 15); private Color c=new Color(10,170,10); public BPanel()/BPanel的构造方法 initButton(); initPopupMenu(); initTextField(); this.setLayout(new BorderLayout(); this.add(North,tf); this.a


    注意事项

    本文(Java计算器源代码.docx)为本站会员主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2023 冰点文库 网站版权所有

    经营许可证编号:鄂ICP备19020893号-2


    收起
    展开