简单计算机的设计(代码)
来源:互联网 发布:抱抱软件怎么赚钱 编辑:程序博客网 时间:2024/05/13 03:37
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */package javaapplicationcalculator;/** * * @author Administrator */public class NewJFramecalculator extends javax.swing.JFrame { /** * Creates new form NewJFramecalculator */ public NewJFramecalculator() { initComponents(); } public String result=""; public String result1=""; public double n1=0.0; public double n2=0.0; public String flag=""; /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jButton4 = new javax.swing.JButton(); jInternalFrame1 = new javax.swing.JInternalFrame(); jTextField1 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); jButton6 = new javax.swing.JButton(); jButton7 = new javax.swing.JButton(); jButton8 = new javax.swing.JButton(); jButton9 = new javax.swing.JButton(); jButton10 = new javax.swing.JButton(); jButton11 = new javax.swing.JButton(); jButton12 = new javax.swing.JButton(); jButton13 = new javax.swing.JButton(); jButton14 = new javax.swing.JButton(); jButton15 = new javax.swing.JButton(); jButton16 = new javax.swing.JButton(); jButton17 = new javax.swing.JButton(); jButton4.setText("jButton4"); jInternalFrame1.setVisible(true); javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane()); jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout); jInternalFrame1Layout.setHorizontalGroup( jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 0, Short.MAX_VALUE) ); jInternalFrame1Layout.setVerticalGroup( jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 0, Short.MAX_VALUE) ); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jTextField1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField1ActionPerformed(evt); } }); jButton1.setText("1"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setText("2"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jButton3.setText("3"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jButton5.setText("+"); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } }); jButton6.setText("4"); jButton6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton6ActionPerformed(evt); } }); jButton7.setText("5"); jButton7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton7ActionPerformed(evt); } }); jButton8.setText("6"); jButton8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton8ActionPerformed(evt); } }); jButton9.setText("7"); jButton9.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton9ActionPerformed(evt); } }); jButton10.setText("8"); jButton10.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton10ActionPerformed(evt); } }); jButton11.setText("9"); jButton11.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton11ActionPerformed(evt); } }); jButton12.setText("-"); jButton12.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton12ActionPerformed(evt); } }); jButton13.setText("*"); jButton13.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton13ActionPerformed(evt); } }); jButton14.setText("/"); jButton14.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton14ActionPerformed(evt); } }); jButton15.setText("C"); jButton15.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton15ActionPerformed(evt); } }); jButton16.setText("0"); jButton16.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton16ActionPerformed(evt); } }); jButton17.setText("="); jButton17.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton17ActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton5)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jButton6) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton7)) .addGroup(layout.createSequentialGroup() .addComponent(jButton9) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton10))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jButton8) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton12)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton11) .addComponent(jButton17)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton14) .addComponent(jButton13))))) .addGroup(layout.createSequentialGroup() .addComponent(jButton15) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton16)) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1) .addComponent(jButton2) .addComponent(jButton3) .addComponent(jButton5)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton6) .addComponent(jButton7) .addComponent(jButton8) .addComponent(jButton12)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton9) .addComponent(jButton10) .addComponent(jButton11) .addComponent(jButton13)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton14, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton15) .addComponent(jButton16) .addComponent(jButton17))) .addContainerGap(29, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: result=result+"1"; jTextField1.setText(result); } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: result=result+"2"; jTextField1.setText(result); } private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: result=result+"3"; jTextField1.setText(result); } private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: result=result+"4"; jTextField1.setText(result); } private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: result=result+"5"; jTextField1.setText(result); } private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: result=result+"6"; jTextField1.setText(result); } private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: result=result+"7"; jTextField1.setText(result); } private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: result=result+"8"; jTextField1.setText(result); } private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: result=result+"9"; jTextField1.setText(result); } private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: result=result+"0"; jTextField1.setText(result); } private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: n1=Double.parseDouble(result); result=result+"+"; flag = "+"; jTextField1.setText(result); } private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: n1=Double.parseDouble(result); result=result+"-"; flag = "-"; jTextField1.setText(result); } private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: n1=Double.parseDouble(result); result=result+"*"; flag = "*"; jTextField1.setText(result); } private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: n1=Double.parseDouble(result); result=result+"/"; flag = "/"; jTextField1.setText(result); } private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: result=""; jTextField1.setText(result); double n1=0.0; double n2=0.0; } private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) { // T ODO add your handling code here: result=result+"="; jTextField1.setText(result); int i=result.indexOf(flag); System.out.println(i); n2 = Double.parseDouble(result.substring(i+1,result.length()-1 )); switch(flag) { case "+":jTextField1.setText(Double.toString(n1+n2));break; case "-":jTextField1.setText(Double.toString(n1-n2));break; case "*":jTextField1.setText(Double.toString(n1*n2));break; case "/":jTextField1.setText(Double.toString(n1/n2));break; } } /** * * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(NewJFramecalculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(NewJFramecalculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(NewJFramecalculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(NewJFramecalculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new NewJFramecalculator().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton10; private javax.swing.JButton jButton11; private javax.swing.JButton jButton12; private javax.swing.JButton jButton13; private javax.swing.JButton jButton14; private javax.swing.JButton jButton15; private javax.swing.JButton jButton16; private javax.swing.JButton jButton17; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JButton jButton5; private javax.swing.JButton jButton6; private javax.swing.JButton jButton7; private javax.swing.JButton jButton8; private javax.swing.JButton jButton9; private javax.swing.JInternalFrame jInternalFrame1; private javax.swing.JTextField jTextField1; // End of variables declaration }
0 0
- 简单计算机的设计(代码)
- 简单的实现计算机功能代码如下
- 简单计算机c++代码
- 通过简单的汇编代码了解计算机的工作原理
- 几条简单的代码设计原则
- Java---设计模块(设计模块的简介及最简单的俩个单例代码加测试)
- 计算机的设计(1)
- 简单的计算机英语
- 简单的计算机英语
- 简单的人品计算机
- 最简单的计算机
- 安卓做的简单计算机
- 简单计算机的js
- 以简单的设计模式代码阐述如何设计委托
- 通过反汇编一个简单的C程序,分析汇编代码理解计算机是如何工作的(原创)
- 计算机是如何执行程序的(以汇编一个简单的C程序,分析汇编代码为例)
- 分析一个简单C程序的汇编代码,理解计算机是如何工作的
- 反汇编一个简单的C程序,分析汇编代码理解计算机是如何工作的
- Shiny应用基础(7):图像互动
- 杭电1236排名
- 利用手机距离感应器来切换是用扬声器听音乐还是听筒听音乐
- TCP/IP 教程(针对LINUX的网络基础请参看 《鸟哥的Linux私房菜 服务器架设篇(第三版) 》)
- log4j日志问题
- 简单计算机的设计(代码)
- huffman编码压缩算法
- System.arraycopy方法的使用
- 《炉石传说》架构设计赏析(7):使用Google.ProtocolBuffers处理网络消息
- ZOJ.2277 The Gate to Freedom【数论-海伦】 2015/09/16
- 例题:信使 最优乘车 最短路径 图论算法之Floyed 学习笔记
- lhgdialog简单弹出框解析
- string与十六进制byte互转
- 项目从想法到实现需要经历哪些过程