首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

63685deb92d7a352fbc2bae374d805c5.zip

行业研究 8.48KB 31 需要积分: 1
立即下载

资源介绍:

63685deb92d7a352fbc2bae374d805c5.zip
package a; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.Toolkit; import java.awt.event.*; import javax.swing.*; public class Calculator extends JFrame implements ActionListener { private String currentNumber = ""; private int currentOperator = 0; JTextField txtUser =new JTextField(); public Calculator() { this.setTitle("计算器"); this.setSize(400, 260); JLabel bianji =new JLabel("编辑"); JLabel chakong1 =new JLabel(""); JLabel chakan =new JLabel("查看"); JLabel bangzhu =new JLabel("帮助"); JPanel panInput =new JPanel(); panInput.setLayout(new GridLayout(1,3)); panInput.add(bianji); panInput.add(chakan); panInput.add(bangzhu); JButton kong = new JButton(""); JButton MC = new JButton("MC"); JButton MR = new JButton("MR"); JButton MS = new JButton("MS"); JButton Mjia = new JButton("M+"); JButton one = new JButton("1"); JButton two = new JButton("2"); JButton three = new JButton("3"); JButton four = new JButton("4"); JButton five = new JButton("5"); JButton six = new JButton("6"); JButton seven = new JButton("7"); JButton eight = new JButton("8"); JButton nine = new JButton("9"); JButton zero = new JButton("0"); JButton chu = new JButton("/"); JButton cheng = new JButton("*"); JButton jian = new JButton("-"); JButton jia = new JButton("+"); JButton deng = new JButton("="); JButton sqrt = new JButton("sqrt"); JButton baifen =new JButton ("%"); JButton daoshu = new JButton("1/x"); JButton CE = new JButton("CE"); JButton C = new JButton("C"); JButton dian = new JButton("."); JButton delete = new JButton("backspace"); JButton x= new JButton("+/-"); kong.addActionListener(this); MC.addActionListener(this); MR.addActionListener(this); MS.addActionListener(this); Mjia.addActionListener(this); one.addActionListener(this); two.addActionListener(this); three.addActionListener(this); four.addActionListener(this); five.addActionListener(this); six.addActionListener(this); seven.addActionListener(this); eight.addActionListener(this); nine.addActionListener(this); zero.addActionListener(this); chu.addActionListener(this); cheng.addActionListener(this); jian.addActionListener(this); jia.addActionListener(this); deng.addActionListener(this); sqrt.addActionListener(this); baifen.addActionListener(this); daoshu.addActionListener(this); CE.addActionListener(this); C.addActionListener(this); dian.addActionListener(this); delete.addActionListener(this); x.addActionListener(this); JPanel panButton3 = new JPanel(); panButton3.setLayout(new GridLayout(1,3)); JPanel panButton1 = new JPanel(); panButton1.setLayout(new GridLayout(4,6)); panButton1.add(MC); panButton1.add(seven); panButton1.add(eight); panButton1.add(nine); panButton1.add(chu); panButton1.add(sqrt); panButton1.add(MR); panButton1.add(four); panButton1.add(five); panButton1.add(six); panButton1.add(cheng); panButton1.add(baifen); panButton1.add(MS); panButton1.add(one); panButton1.add(two); panButton1.add(three); panButton1.add(jian); panButton1.add(daoshu); panButton1.add(Mjia); panButton1.add(zero); panButton1.add(dian); panButton1.add(x); panButton1.add(jia); panButton1.add(deng); this.add(panButton1,BorderLayout.SOUTH); JPanel panButton2 = new JPanel(); panButton2.setLayout(new GridLayout(1,4)); panButton2.add(kong); panButton2.add(delete); panButton2.add(CE); panButton2.add(C); JPanel a =new JPanel(); a.setLayout(new GridLayout(4,1)); a.add(panInput); a.add(txtUser); a.add(panButton3); a.add(panButton2); this.add(a,BorderLayout.NORTH); } public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("1")) { txtUser.setText("1"); } else if(e.getActionCommand().equals("2")) { txtUser.setText("2"); } else if(e.getActionCommand().equals("3")) { txtUser.setText("3"); } else if(e.getActionCommand().equals("4")) { txtUser.setText("4"); } else if(e.getActionCommand().equals("5")) { txtUser.setText("5"); } else if(e.getActionCommand().equals("6")) { txtUser.setText("6"); } else if(e.getActionCommand().equals("7")) { txtUser.setText("7"); } else if(e.getActionCommand().equals("8")) { txtUser.setText("8"); } else if(e.getActionCommand().equals("9")) { txtUser.setText("9"); } else if(e.getActionCommand().equals("0")) { txtUser.setText("0"); } else if(e.getActionCommand().equals("+")) { txtUser.setText("+"); } else if(e.getActionCommand().equals("-")) { txtUser.setText("-"); } else if(e.getActionCommand().equals("/")) { txtUser.setText("/"); } else if(e.getActionCommand().equals("*")) { txtUser.setText("*"); } if (e.getSource() instanceof JButton) { JButton button = (JButton) e.getSource(); String buttonText = button.getText(); if (buttonText.equals("1") || buttonText.equals("2") || buttonText.equals("3") || buttonText.equals("4") || buttonText.equals("5") || buttonText.equals("6") || buttonText.equals("7") || buttonText.equals("8") || buttonText.equals("9") || buttonText.equals("0")) { if (currentOperator == 0) { currentNumber += buttonText; } else { currentNumber = currentNumber.concat(buttonText); } } else if (buttonText.equals("/")) { currentOperator = 3; } else if (buttonText.equals("*")) { currentOperator = 2; } else if (buttonText.equals("-")) { currentOperator = 1; } else if (buttonText.equals("+")) { currentOperator = 0; } else if (buttonText.equals("=")) { if (currentOperator == 0) { double num1 = Double.parseDouble(currentNumber.substring(0, currentNumber.length() - 1)); double num2 = Double.parseDouble(currentNumber.substring(currentNumber.length() - 1)); double result = num1 + num2; txtUser.setText(String.format("%.2f"+"+"+"%.2f"+"="+"%.2f", num1,num2, result)); } else if (currentOperator == 1)

资源文件列表:

63685deb92d7a352fbc2bae374d805c5.zip 大约有11个文件
  1. Calculator/
  2. Calculator/.classpath 301B
  3. Calculator/.project 386B
  4. Calculator/.settings/
  5. Calculator/.settings/org.eclipse.jdt.core.prefs 629B
  6. Calculator/bin/
  7. Calculator/bin/a/
  8. Calculator/bin/a/Calculator.class 6.98KB
  9. Calculator/src/
  10. Calculator/src/a/
  11. Calculator/src/a/Calculator.java 13.12KB
0评论
提交 加载更多评论
其他资源 2222222222222222222222222222222222222
222222222222222222222222222
数字媒体技术课终作业,基于HTML,css,JavaScript开发的打飞机小游戏
数字媒体技术课终作业,基于HTML,css,JavaScript开发的打飞机小游戏。可以流畅运行,涵盖背景音乐和分数系统,适合当作小作业提交。
content_1727226732355.zip
content_1727226732355.zip
JavaScript玩转机器学习-Tensorflow.js项目实战
JavaScript玩转机器学习-Tensorflow.js项目实战
JavaScript玩转机器学习-Tensorflow.js项目实战 JavaScript玩转机器学习-Tensorflow.js项目实战 JavaScript玩转机器学习-Tensorflow.js项目实战
数字图像处理MATLAB编程课件.zip
数字图像处理MATLAB编程课件.zip
什么语言--长尾词_1704535596_p网站行业关键字7.zip
什么语言--长尾词_1704535596_p网站行业关键字7.zip
说阿拉伯语--长尾词_1704536014_p网站行业关键字8.zip
说阿拉伯语--长尾词_1704536014_p网站行业关键字8.zip
说意大利语--长尾词_1704536394_p网站行业关键字4.zip
说意大利语--长尾词_1704536394_p网站行业关键字4.zip