1、private JButton dian=new JButton(.private JButton kai=new JButton(sqrtprivate JButton diao=new JButton(1/xprivate JButton aa=new JButton(Aprivate JButton bb=new JButton(Bprivate JButton cc=new JButton(Cprivate JButton dd=new JButton(Dprivate JButton ee=new JButton(Eprivate JButton ff=new JButton(Fpr
2、ivate TextField k1=new TextField();private objConversion convert = new objConversion();JMenuItem copy,paste,s,t,about,me;JRadioButton sixteen,ten,eight,two;JButton backspace,ce,num0,num1,num2,num3,num4,num5,num6,num7,num8,num9;Container cp;JTextField text;String copycontent=;boolean clickable=true,c
3、lear=true;int all=0;double qian;String fuhao;int jin=10,first=1;public calculator()setTitle(计算器李铀制作setSize(400,300);setLocation(250,200);text=new JTextField(25);text.setText(0.text.setHorizontalAlignment(JTextField.RIGHT);JPanel cp1=new JPanel();JPanel cp2=new JPanel();JPanel cp3=new JPanel();cp=get
4、ContentPane();cp.add(cp1,Northcp.add(cp2,Centercp.add(cp3,Southcp1.setLayout(new GridLayout(1,6);cp2.setLayout(new GridLayout(2,4);cp3.setLayout(new GridLayout(6,6);sixteen=new JRadioButton(十六进制sixteen.setVisible(false);ten=new JRadioButton(十进制,true);ten.setVisible(false);eight=new JRadioButton(八进制e
5、ight.setVisible(false);two=new JRadioButton(二进制two.setVisible(false);sixteen.addActionListener(this);ten.addActionListener(this);eight.addActionListener(this);two.addActionListener(this);ButtonGroup btg=new ButtonGroup();btg.add(sixteen);btg.add(ten);btg.add(eight);btg.add(two);JTextField t3=new JTe
6、xtField(25);cp1.add(text);text.setEditable(false);text.setBackground(new Color(255, 255, 255);cp2.add(sixteen);cp2.add(ten);cp2.add(eight);cp2.add(two);backspace=new JButton(Backspacebackspace.setForeground(new Color(255,0,0);backspace.addActionListener(this);ce=new JButton(CEce.setForeground(new Co
7、lor(255,0,0);ce.addActionListener(this);k1.setVisible(false);cp2.add(k1);cp2.add(backspace);cp2.add(ce);num0=new JButton(0num1=new JButton(1num2=new JButton(2num3=new JButton(3num4=new JButton(4num5=new JButton(5num6=new JButton(6num7=new JButton(7num8=new JButton(8num9=new JButton(9cp3.add(num7);nu
8、m7.addActionListener(this);cp3.add(num8);num8.addActionListener(this);cp3.add(num9);num9.addActionListener(this);cp3.add(chu);chu.setForeground(new Color(255,0,0);chu.addActionListener(this);cp3.add(kai);kai.addActionListener(this);cp3.add(num4);num4.addActionListener(this);cp3.add(num5);num5.addAct
9、ionListener(this);cp3.add(num6);num6.addActionListener(this);cp3.add(cheng);cheng.setForeground(new Color(255,0,0);cheng.addActionListener(this);cp3.add(qiuyi);qiuyi.addActionListener(this);cp3.add(num1);num1.addActionListener(this);cp3.add(num2);num2.addActionListener(this);cp3.add(num3);num3.addAc
10、tionListener(this);cp3.add(jian);jian.setForeground(new Color(255,0,0);jian.addActionListener(this);cp3.add(diao);diao.addActionListener(this);cp3.add(num0);num0.addActionListener(this);cp3.add(fu);fu.addActionListener(this);cp3.add(dian);dian.addActionListener(this);cp3.add(jia);jia.setForeground(n
11、ew Color(255,0,0);jia.addActionListener(this);cp3.add(deng);deng.setForeground(new Color(255,0,0);deng.addActionListener(this);cp3.add(aa);aa.addActionListener(this);cp3.add(bb);bb.addActionListener(this);cp3.add(cc);cc.addActionListener(this);cp3.add(dd);dd.addActionListener(this);cp3.add(ee);ee.ad
12、dActionListener(this);cp3.add(ff);ff.addActionListener(this);aa.setVisible(false);bb.setVisible(false);cc.setVisible(false);dd.setVisible(false);ee.setVisible(false);ff.setVisible(false);JMenuBar mainMenu = new JMenuBar();setJMenuBar(mainMenu);JMenu editMenu = new JMenu(编辑JMenu viewMenu = new JMenu(
13、查看JMenu helpMenu = new JMenu(帮助mainMenu.add(editMenu);mainMenu.add(viewMenu);mainMenu.add(helpMenu);copy = new JMenuItem( 复制paste = new JMenuItem( 粘贴KeyStroke copyks=KeyStroke.getKeyStroke(KeyEvent.VK_C,Event.CTRL_MASK);copy.setAccelerator(copyks);KeyStroke pasteks=KeyStroke.getKeyStroke(KeyEvent.VK_V,Event.CTRL_MASK);paste.setAccelerator(pasteks);/设置退出菜单选项加上快捷键editMenu.add(copy);editMenu.add(paste);copy.addActionListener(this);paste.addActio
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1