版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、太原理工大學 白婭玲/我不知道計算器的%是什么意思。在這里,我認為1%=0.01public class Apublic static void main(String argsFrame f=new Frame("計算器"JTextField t=new JTextField(;t.setHorizontalAlignment(JTextField.RIGHT;/從右往左輸入f.setSize(300,300;f.setLayout(new BorderLayout(5,5;f.setBackground(Color.cyan;f.setLocation(500,400;
2、 Panel p= new Panel(; Panel h= new Panel(;MenuBar mb=new MenuBar(;f.setMenuBar(mb;Menu m1=new Menu("菜單"Menu m2=new Menu("查看"Menu m3=new Menu("編輯"Menu m4=new Menu("幫助"mb.add(m1;mb.add(m2;mb.add(m3;mb.setHelpMenu(m4;MenuItem m11=new MenuItem("文件"MenuIt
3、em m12=new MenuItem("保存"MenuItem m13=new MenuItem("退出"MenuItem m14=new MenuItem("打開"MenuItem m15=new MenuItem("復制"MenuItem m16=new MenuItem("粘貼"MenuItem m17=new MenuItem("關于"MenuItem m18=new MenuItem("介紹"m1.add(m11;m1.add(m12;m1.a
4、ddSeparator(;m1.add(m13;m2.add(m14;m3.add(m15;m3.add(m16;m4.add(m17;m4.add(m18;h.setLayout(new GridLayout(1,3,3,3;Button a1=new Button("CE"Button a2=new Button("C"Button a3=new Button("Backspace"h.add(a1; h.add(a2; h.add(a3;a1.setBackground(new Color(251,74,103;a2.setBa
5、ckground(new Color(251,74,103;a3.setBackground(new Color(251,74,103;/按鈕顏色p.setLayout(new GridLayout(4,5,3,3;Button b1=new Button("7"Button b2=new Button("8"Button b3=new Button("9"Button b4=new Button("/"Button b5=new Button("sprt"Button b6=new Butto
6、n("4"Button b7=new Button("5"Button b8=new Button("6"Button b9=new Button("*"Button b10=new Button("%"Button b11=new Button("1"Button b12=new Button("2"Button b13=new Button("3"Button b14=new Button("-"Button b
7、15=new Button("1/x"Button b16=new Button("0"Button b17=new Button("+/-"Button b18=new Button("+"Button b19=new Button("."Button b20=new Button("="p.add(b1; p.add(b2; p.add(b3;p.add(b4; p.add(b5; p.add(b6;p.add(b7; p.add(b8; p.add(b9;p.add(b
8、10; p.add(b11; p.add(b12;p.add(b13; p.add(b14; p.add(b15;p.add(b16; p.add(b17; p.add(b18;p.add(b19; p.add(b20;b1.setBackground(new Color(249,248,158;b2.setBackground(new Color(249,248,158;b3.setBackground(new Color(249,248,158;b4.setBackground(new Color(205,221,236;b5.setBackground(new Color(205,221
9、,236;b6.setBackground(new Color(249,248,158;b7.setBackground(new Color(249,248,158;b8.setBackground(new Color(249,248,158;b9.setBackground(new Color(205,221,236;b10.setBackground(new Color(205,221,236;b11.setBackground(new Color(249,248,158;b12.setBackground(new Color(249,248,158;b13.setBackground(n
10、ew Color(249,248,158;b14.setBackground(new Color(205,221,236;b15.setBackground(new Color(205,221,236;b16.setBackground(new Color(249,248,158;b17.setBackground(new Color(249,248,158;b18.setBackground(new Color(249,248,158;b19.setBackground(new Color(205,221,237;b20.setBackground(new Color(205,221,236
11、;Monitor bb1=new Monitor(t;a1.addActionListener(bb1;a2.addActionListener(bb1;a3.addActionListener(bb1;b1.addActionListener(bb1;b2.addActionListener(bb1;b3.addActionListener(bb1;b4.addActionListener(bb1;b5.addActionListener(bb1; b6.addActionListener(bb1;b7.addActionListener(bb1;b8.addActionListener(b
12、b1; b9.addActionListener(bb1;b10.addActionListener(bb1; b11.addActionListener(bb1;b12.addActionListener(bb1;b13.addActionListener(bb1; b14.addActionListener(bb1;b15.addActionListener(bb1;b16.addActionListener(bb1;b17.addActionListener(bb1;b18.addActionListener(bb1;b19.addActionListener(bb1;b20.addAc
13、tionListener(bb1;Monitor2 m=new Monitor2(f;f.addWindowListener(m; t.setText("0"f.add(t,BorderLayout.NORTH; f.add(p,BorderLayout.SOUTH; f.add(h,BorderLayout.CENTER;f.pack(;f.setVisible(true; class Monitor implements ActionListenerJTextField t;int flge;double add1;int i=0;String s="&quo
14、t;Monitor (JTextField tthis.t=t;public void actionPerformed(ActionEvent eif(e.getActionCommand(. equals("1"if(t.getText(.trim(.equals("0"t.setText("" String s=t.getText(;s=s+"1"t.setText(s;elseString s=t.getText(;s=s+"1"t.setText(s;else if(e.getActio
15、nCommand(.equals("2"if(t.getText(.trim(.equals("0"t.setText("" String s=t.getText(;s=s+"2"t.setText(s;elseString s=t.getText(;s=s+"2"t.setText(s;else if(e.getActionCommand(.equals("3"if(t.getText(.trim(.equals("0"t.setText("&
16、quot; String s=t.getText(;s=s+"3"t.setText(s;elseString s=t.getText(;s=s+"3"t.setText(s; else if(e.getActionCommand(.equals("4"if(t.getText(.trim(.equals("0"t.setText("" String s=t.getText(;s=s+"4"t.setText(s;elseString s=t.getText(;s=s+&qu
17、ot;4"t.setText(s;else if(e.getActionCommand(.equals("5"if(t.getText(.trim(.equals("0"t.setText("" String s=t.getText(;s=s+"5"t.setText(s;elseString s=t.getText(;s=s+"5"t.setText(s;else if(e.getActionCommand(.equals("6"if(t.getText(.tri
18、m(.equals("0"t.setText("" String s=t.getText(;s=s+"6"t.setText(s;elseString s=t.getText(;s=s+"6"t.setText(s;else if(e.getActionCommand(.equals("7"if(t.getText(.trim(.equals("0"t.setText("" String s=t.getText(;s=s+"7"t.se
19、tText(s;elseString s=t.getText(;s=s+"7"t.setText(s;else if(e.getActionCommand(.equals("8"if(t.getText(.trim(.equals("0"t.setText("" String s=t.getText(;s=s+"8"t.setText(s;elseString s=t.getText(;s=s+"8"t.setText(s;else if(e.getActionCommand
20、(.equals("9" if(t.getText(.trim(.equals("0"t.setText("" String s=t.getText(;s=s+"9"t.setText(s;elseString s=t.getText(;s=s+"9"t.setText(s;else if(e.getActionCommand(.equals("0"if(t.getText(.trim(.equals("0"/0的問題,0在第一位則不顯示t.setText
21、("" String s=t.getText(;s=s+"0"t.setText(s;elseString s=t.getText(;s=s+"0"t.setText(s;else if(e.getActionCommand(.equals("+/-"s=t.getText(;add1=Double.parseDouble(s;double re=-add1;t.setText(re+""/ int a=Integer.valueOf(s;/ a=a*(-1;/ s=String.valueOf
22、(a; 沒問題/ t.setText(s;else if(e.getActionCommand(.equals("." int index = s.indexOf('.'/該方法的作用是查找特定字符或字符串在當前字符串中的起始位置,如果不存在則返回-1if(index=-1/小數(shù)點只能按一次s=s+"."elset.setText(s;if(e.getActionCommand(.equals("+" flge=1;s=t.getText(;add1=Double.parseDouble(s ;t.setText(&q
23、uot;"if(e.getActionCommand(.equals("-"flge=2;s=t.getText(;t.setText(""add1=Double.parseDouble(s ;if(e.getActionCommand(.equals("*"flge=3;s=t.getText(;t.setText(""add1=Double.parseDouble(s ;if(e.getActionCommand(.equals("/"flge=4;s=t.getText(; t.
24、setText(""add1=Double.parseDouble(s ;if(e.getActionCommand(.equals("sprt"flge=5;s=t.getText(;add1=Double.parseDouble(s ;if(e.getActionCommand(.equals("%"flge=6;s=t.getText(;add1=Double.parseDouble(s ;if(e.getActionCommand(.equals("1/x"flge=7;s=t.getText(;add1=
25、Double.parseDouble(s ; if(e.getActionCommand(.equals("C"add1=0;t.setText("0"if(e.getActionCommand(.equals("CE"add1=0;t.setText("0"if(e.getActionCommand(.equals("Backspace"int count;count=s.length(-1; /該方法的作用是返回字符串的長度,也就是返回字符串中字符的個數(shù)if(count>=0s=s.substring(0,count;t.setText(s;elset.setText("0" if(e.getActionCommand(.equals("=" s=t.getText(;double add2=Double.parseDouble(s;double re;if(flge=0re=add2;t.setText(re+""else if(flge=1re=add1+ad
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 智能化教育模式研究-深度研究
- 2025至2030年中國非升桿式法蘭閘閥數(shù)據(jù)監(jiān)測研究報告
- 農藥質量檢測方法-深度研究
- 2025至2030年中國潤版添加液數(shù)據(jù)監(jiān)測研究報告
- 2025至2030年中國支架組件數(shù)據(jù)監(jiān)測研究報告
- 2025至2030年中國微噴霧系統(tǒng)數(shù)據(jù)監(jiān)測研究報告
- 2025至2030年中國夜用棉面護翼衛(wèi)生巾數(shù)據(jù)監(jiān)測研究報告
- 2025至2030年中國吹瓶機左右模板數(shù)據(jù)監(jiān)測研究報告
- 2025至2030年中國全不銹鋼過濾器數(shù)據(jù)監(jiān)測研究報告
- 2025年中國錦綸捆綁器市場調查研究報告
- 2024-2025學年山東省濰坊市高一上冊1月期末考試數(shù)學檢測試題(附解析)
- 江蘇省揚州市蔣王小學2023~2024年五年級上學期英語期末試卷(含答案無聽力原文無音頻)
- 數(shù)學-湖南省新高考教學教研聯(lián)盟(長郡二十校聯(lián)盟)2024-2025學年2025屆高三上學期第一次預熱演練試題和答案
- 決勝中層:中層管理者的九項修煉-記錄
- 幼兒園人民幣啟蒙教育方案
- 臨床藥師進修匯報課件
- 軍事理論(2024年版)學習通超星期末考試答案章節(jié)答案2024年
- 《無人機法律法規(guī)知識》課件-第1章 民用航空法概述
- 政治丨廣東省2025屆高中畢業(yè)班8月第一次調研考試廣東一調政治試卷及答案
- 2020-2024年安徽省初中學業(yè)水平考試中考物理試卷(5年真題+答案解析)
- 銀行卡凍結怎么寫申請書
評論
0/150
提交評論