![簡(jiǎn)易型科學(xué)計(jì)算器_第1頁(yè)](http://file2.renrendoc.com/fileroot_temp3/2021-11/23/79f22892-ee03-4da5-b4cf-a369f3b3974b/79f22892-ee03-4da5-b4cf-a369f3b3974b1.gif)
![簡(jiǎn)易型科學(xué)計(jì)算器_第2頁(yè)](http://file2.renrendoc.com/fileroot_temp3/2021-11/23/79f22892-ee03-4da5-b4cf-a369f3b3974b/79f22892-ee03-4da5-b4cf-a369f3b3974b2.gif)
![簡(jiǎn)易型科學(xué)計(jì)算器_第3頁(yè)](http://file2.renrendoc.com/fileroot_temp3/2021-11/23/79f22892-ee03-4da5-b4cf-a369f3b3974b/79f22892-ee03-4da5-b4cf-a369f3b3974b3.gif)
![簡(jiǎn)易型科學(xué)計(jì)算器_第4頁(yè)](http://file2.renrendoc.com/fileroot_temp3/2021-11/23/79f22892-ee03-4da5-b4cf-a369f3b3974b/79f22892-ee03-4da5-b4cf-a369f3b3974b4.gif)
![簡(jiǎn)易型科學(xué)計(jì)算器_第5頁(yè)](http://file2.renrendoc.com/fileroot_temp3/2021-11/23/79f22892-ee03-4da5-b4cf-a369f3b3974b/79f22892-ee03-4da5-b4cf-a369f3b3974b5.gif)
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、簡(jiǎn)易型科學(xué)計(jì)算器import java.awt.BorderLayout;import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.text.DecimalFormat;import javax.swing.AbstractButton;import javax.swing.BorderFactor
2、y;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JPanel;import javax.swing.JTextField;import java.lang.Math;public class myCalucator extends JFrameprivate JPanel panel1,panel2,panel3,panel4;pri
3、vate JTextField tf;private JMenu menu1,menu2;private JMenuItem seeItem1,seeItem2,help1,help2;private JMenuBar myBar;private JButton Backspace,CE,C,sin,ercifang,cos,sancifang,tan,jiecheng,lg,pai,zero,one,two,three,four,five,six,seven,eight,nine,jia,jian,cheng,chu,dot,equal;String s;int x;double num1,
4、num2,num3;public myCalucator()super("簡(jiǎn)易型科學(xué)計(jì)算器");this.setLayout(new BorderLayout(10,5);panel1=new JPanel(new GridLayout(1,3,10,10);panel2=new JPanel(new GridLayout(4,2,5,5);panel3=new JPanel(new GridLayout(4,4,5,5);panel4=new JPanel(new BorderLayout(5,5);/* * 菜單欄 */myBar=new JMenuBar();menu
5、1=new JMenu("查看");menu2=new JMenu("幫助");menu1.setFont(new Font("宋體",Font.PLAIN,12);menu2.setFont(new Font("宋體",Font.PLAIN,12);/* * 查看欄 */seeItem1=new JMenuItem("標(biāo)準(zhǔn)型");seeItem2=new JMenuItem("科學(xué)型");seeItem1.setFont(new Font("宋體",Fo
6、nt.PLAIN,12);seeItem2.setFont(new Font("宋體",Font.PLAIN,12);/* * 幫助欄 */help1=new JMenuItem("查看幫助");help2=new JMenuItem("關(guān)于計(jì)算器");help1.setFont(new Font("宋體",Font.PLAIN,12);help2.setFont(new Font("宋體",Font.PLAIN,12);menu1.add(seeItem1);menu1.add(seeItem
7、2);menu2.add(help1);menu2.add(help1);myBar.add(menu1);myBar.add(menu2);this.setJMenuBar(myBar);/* * 文本域 */tf=new JTextField();tf.setEditable(false);tf.setBackground(Color.white);tf.setText("");tf.setHorizontalAlignment(JTextField.RIGHT);tf.setBorder(BorderFactory.createLoweredBevelBorder()
8、;init();/對(duì)計(jì)算器進(jìn)行初始化public void init()Backspace=new JButton("");Backspace.setForeground(Color.blue);CE=new JButton("CE");CE.setForeground(Color.blue);C=new JButton("C");C.setForeground(Color.blue);panel1.add(Backspace);panel1.add(CE);panel1.add(C);sin=new JButton("si
9、n");sin.setForeground(Color.red);ercifang=new JButton("x2");ercifang.setForeground(Color.red);cos=new JButton("cos");cos.setForeground(Color.red);sancifang=new JButton("x3");sancifang.setForeground(Color.red);tan=new JButton("tan");tan.setForeground(Color
10、.red);jiecheng=new JButton("n!");jiecheng.setForeground(Color.red);lg=new JButton("lg");lg.setForeground(Color.red);pai=new JButton("");pai.setForeground(Color.red);panel2.add(sin);panel2.add(ercifang);panel2.add(cos);panel2.add(sancifang);panel2.add(tan);panel2.add(jie
11、cheng);panel2.add(lg);panel2.add(pai);seven=new JButton("7");seven.setForeground(Color.blue);eight=new JButton("8");eight.setForeground(Color.blue);nine=new JButton("9");nine.setForeground(Color.blue);jia=new JButton("+");jia.setForeground(Color.blue);four=new
12、 JButton("4");four.setForeground(Color.blue);five=new JButton("5");five.setForeground(Color.blue);six=new JButton("6");six.setForeground(Color.blue);jian=new JButton("-");jian.setForeground(Color.blue);one=new JButton("1");one.setForeground(Color.blu
13、e);two=new JButton("2");two.setForeground(Color.blue);three=new JButton("3");three.setForeground(Color.blue);cheng=new JButton("*");cheng.setForeground(Color.blue);zero=new JButton("0");zero.setForeground(Color.blue);dot=new JButton(".");dot.setForeg
14、round(Color.blue);equal=new JButton("=");equal.setForeground(Color.blue);chu=new JButton("/");chu.setForeground(Color.blue);panel3.add(seven);panel3.add(eight);panel3.add(nine);panel3.add(jia);panel3.add(four);panel3.add(five);panel3.add(six);panel3.add(jian);panel3.add(one);pane
15、l3.add(two);panel3.add(three);panel3.add(cheng);panel3.add(zero);panel3.add(dot);panel3.add(equal);panel3.add(chu);/添加按鈕事件監(jiān)聽(tīng)jianting number=new jianting();jianting_sf suanfa=new jianting_sf();seven.addActionListener(number);eight.addActionListener(number);nine.addActionListener(number);jia.addAction
16、Listener(suanfa);four.addActionListener(number);five.addActionListener(number);six.addActionListener(number);jian.addActionListener(suanfa);one.addActionListener(number);two.addActionListener(number);three.addActionListener(number);cheng.addActionListener(suanfa);zero.addActionListener(number);dot.a
17、ddActionListener(number);equal.addActionListener(suanfa);chu.addActionListener(suanfa);C.addActionListener(number);CE.addActionListener(number);sin.addActionListener(suanfa);cos.addActionListener(suanfa);tan.addActionListener(suanfa);ercifang.addActionListener(suanfa);sancifang.addActionListener(sua
18、nfa);jiecheng.addActionListener(suanfa);lg.addActionListener(suanfa);pai.addActionListener(suanfa);Backspace.addActionListener(number);JButton btns=new JButton("計(jì)算器");btns.setEnabled(false);/按鈕不可被按btns.setPreferredSize(new Dimension(10,10);panel1.add(btns);panel4.add(panel1,BorderLayout.NO
19、RTH);panel4.add(panel2,BorderLayout.WEST);panel4.add(panel3,BorderLayout.CENTER);this.add(panel4);this.add(tf,BorderLayout.NORTH);pack();this.setResizable(true);this.setSize(500,250);this.setDefaultCloseOperation(EXIT_ON_CLOSE);/窗口可關(guān)閉class jianting implements ActionListenerpublic void actionPerforme
20、d(ActionEvent e)String str=e.getActionCommand();if(str.equals("C")tf.setText("");if(str.equals("CE")tf.setText("");if(str.equals("")s=tf.getText();int i=s.length();if(i>0) tf.setText(tf.getText().substring(0,i-1);if(e.getSource()=seven)tf.setText(
21、tf.getText()+"7");if(e.getSource()=eight)tf.setText(tf.getText()+"8");if(e.getSource()=nine)tf.setText(tf.getText()+"9");if(e.getSource()=four)tf.setText(tf.getText()+"4");if(e.getSource()=five)tf.setText(tf.getText()+"5");if(e.getSource()=six)tf.set
22、Text(tf.getText()+"6");if(e.getSource()=one)tf.setText(tf.getText()+"1");if(e.getSource()=two)tf.setText(tf.getText()+"2");if(e.getSource()=three)tf.setText(tf.getText()+"3");if(e.getSource()=zero)tf.setText(tf.getText()+"0");if(e.getSource()=dot)tf.
23、setText(tf.getText()+".");class jianting_sf implements ActionListenerpublic void actionPerformed(ActionEvent e)String str=e.getActionCommand();if(str.equals("+")s=tf.getText();/獲取文本框的值num1=Double.parseDouble(s);/String類型轉(zhuǎn)換為double型tf.setText("");/賦值x=0;else if(str.equals
24、("-")s=tf.getText();num1=Double.parseDouble(s);tf.setText("");x=1;else if(str.equals("*")s=tf.getText();num1=Double.parseDouble(s);tf.setText("");x=2;else if(str.equals("/")s=tf.getText();num1=Double.parseDouble(s);tf.setText("");x=3;else i
25、f(str.equals("sin")s=tf.getText();num1=Double.parseDouble(s);x=4;else if(str.equals("cos")s=tf.getText();num1=Double.parseDouble(s);x=5;else if(str.equals("tan")s=tf.getText();num1=Double.parseDouble(s);x=6;else if(str.equals("n!")s=tf.getText();num1=Double.pa
26、rseDouble(s);num3=1;for(double start=1;start<=num1;start+)num3=start*num3;x=7;else if(str.equals("x2")s=tf.getText();num1=Double.parseDouble(s);x=8;else if(str.equals("x3")s=tf.getText();num1=Double.parseDouble(s);x=9;else if(str.equals("") tf.setText(String.valueOf(Math.PI);x=10;else if(str.equa
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 研究歷程與成果
- DB61T-市場(chǎng)監(jiān)管行風(fēng)建設(shè)指南地方標(biāo)準(zhǔn)編制說(shuō)明
- 初級(jí)銀行業(yè)法律法規(guī)與綜合能力-2020年初級(jí)銀行從業(yè)資格考試《法律法規(guī)與綜合能力》真題匯編
- 壓力容器考試審核考試題庫(kù)(容標(biāo)委氣體協(xié)會(huì)聯(lián)合)
- 企業(yè)數(shù)據(jù)轉(zhuǎn)換管理規(guī)范制度
- DB2201-T 23-2022 農(nóng)安籽鵝標(biāo)準(zhǔn)規(guī)范
- DB2113-T 0008-2023 地理標(biāo)志產(chǎn)品 龍?zhí)毒G豆粉絲
- 2024-2025學(xué)年安徽省合肥市高一上學(xué)期期末復(fù)習(xí)綜合素養(yǎng)提升訓(xùn)練(三)物理試題(解析版)
- 2025年春季學(xué)期學(xué)校德育工作計(jì)劃及安排表
- 2024年05月浙江金華成泰農(nóng)商銀行員工招考筆試歷年參考題庫(kù)附帶答案詳解
- 帶看協(xié)議書(shū)范本(2篇)
- 2025-2030年中國(guó)科教玩具行業(yè)發(fā)展動(dòng)態(tài)及前景趨勢(shì)分析報(bào)告新版
- 馬匹寄養(yǎng)協(xié)議書(shū)
- 股權(quán)投資項(xiàng)目建議書(shū)
- 2025年北京廣播電視臺(tái)招聘(140人)歷年高頻重點(diǎn)提升(共500題)附帶答案詳解
- (主城一診)重慶市2025年高2025屆高三學(xué)業(yè)質(zhì)量調(diào)研抽測(cè) (第一次)物理試卷(含答案)
- 2025年高考作文專練(25道真題+審題立意+范文)- 2025年高考語(yǔ)文作文備考總復(fù)習(xí)
- 四年級(jí)數(shù)學(xué)脫式計(jì)算練習(xí)題100道
- 第一課 追求向上向善的道德(課時(shí)1)(課件)
評(píng)論
0/150
提交評(píng)論