⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newapplet.java

📁 用netbean的applet形式编写的计算器
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * NewApplet.java * * Created on 2008年11月2日, 上午9:42 */package javaapplication9;/** * * @author  Administrator */public class NewApplet extends java.applet.Applet {    /** Initializes the applet NewApplet */    public void init() {        try {            java.awt.EventQueue.invokeAndWait(new Runnable() {                public void run() {                    initComponents();                }            });        } catch (Exception ex) {            ex.printStackTrace();        }    }    /*自定义变量*/        private String firstSign="=";//保存+,-,*,/,=命令    private double result=0;//保存计算结果    private double lastResult=0; //保存前一运算结果    private boolean numStart=false;//判断是否为数字的开始    private boolean point=false;//判断是否按下小数点键    private boolean pi=false;//判断是否按下PI键    private boolean smP=false;//判断是否按下"说明"键    private int i=0;    private String signCopy=firstSign;    private double xCopy=0;        /** This method is called from within the init() method to     * initialize the form.     * WARNING: Do NOT modify this code. The content of this method is     * always regenerated by the Form Editor.     */    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents    private void initComponents() {        jTextField1 = new javax.swing.JTextField();        jButton1 = new javax.swing.JButton();        jButton2 = new javax.swing.JButton();        jButton3 = new javax.swing.JButton();        jButton4 = 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();        jButton18 = new javax.swing.JButton();        jButton19 = new javax.swing.JButton();        jButton20 = new javax.swing.JButton();        jButton21 = new javax.swing.JButton();        jButton22 = new javax.swing.JButton();        jButton23 = new javax.swing.JButton();        jButton24 = new javax.swing.JButton();        jButton25 = new javax.swing.JButton();        jLabel1 = new javax.swing.JLabel();        jButton26 = new javax.swing.JButton();        jButton27 = new javax.swing.JButton();        jButton28 = new javax.swing.JButton();        setBackground(new java.awt.Color(204, 255, 255));        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());        jTextField1.setBackground(new java.awt.Color(204, 255, 204));        jTextField1.setEditable(false);        jTextField1.setForeground(new java.awt.Color(0, 0, 255));        jTextField1.setText("0");        add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 30, 260, 30));        jButton1.setText("1");        jButton1.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton1ActionPerformed(evt);            }        });        add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 170, 90, -1));        jButton2.setText("2");        jButton2.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton2ActionPerformed(evt);            }        });        add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 170, 70, -1));        jButton3.setText("3");        jButton3.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton3ActionPerformed(evt);            }        });        add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 170, 60, -1));        jButton4.setText("4");        jButton4.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton4ActionPerformed(evt);            }        });        add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 140, 90, -1));        jButton5.setText("5");        jButton5.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton5ActionPerformed(evt);            }        });        add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 140, 70, -1));        jButton6.setText("6");        jButton6.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton6ActionPerformed(evt);            }        });        add(jButton6, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 140, 60, -1));        jButton7.setText("7");        jButton7.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton7ActionPerformed(evt);            }        });        add(jButton7, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 110, 90, -1));        jButton8.setText("8");        jButton8.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton8ActionPerformed(evt);            }        });        add(jButton8, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 110, 70, -1));        jButton9.setText("9");        jButton9.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton9ActionPerformed(evt);            }        });        add(jButton9, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 110, 60, -1));        jButton10.setText("0");        jButton10.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton10ActionPerformed(evt);            }        });        add(jButton10, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 200, 90, -1));        jButton11.setText("+/-");        jButton11.setActionCommand("jButton11");        jButton11.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton11ActionPerformed(evt);            }        });        add(jButton11, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 200, 70, -1));        jButton12.setText(".");        jButton12.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton12ActionPerformed(evt);            }        });        add(jButton12, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 200, 60, -1));        jButton13.setText("+");        jButton13.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton13ActionPerformed(evt);            }        });        add(jButton13, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 110, 60, -1));        jButton14.setText("-");        jButton14.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton14ActionPerformed(evt);            }        });        add(jButton14, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 140, 60, -1));        jButton15.setText("x");        jButton15.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton15ActionPerformed(evt);            }        });        add(jButton15, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 170, 60, -1));        jButton16.setText("÷");        jButton16.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton16ActionPerformed(evt);            }        });        add(jButton16, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 200, 60, -1));        jButton17.setText("开方");        jButton17.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton17ActionPerformed(evt);            }        });        add(jButton17, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 230, 90, -1));        jButton18.setText("立方");        jButton18.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton18ActionPerformed(evt);            }        });        add(jButton18, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 260, 70, -1));        jButton19.setText("平方");        jButton19.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton19ActionPerformed(evt);            }        });        add(jButton19, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 230, 70, -1));        jButton20.setText("1/x");        jButton20.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton20ActionPerformed(evt);            }        });        add(jButton20, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 230, 60, -1));        jButton21.setText("=");        jButton21.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton21ActionPerformed(evt);            }        });        add(jButton21, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 260, 60, -1));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -