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

📄 frame1.java

📁 我自己编写的科学计算器
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
package calculator;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
/**
 * <p>Title:Neutron calculator </p>
 * <p>Description:计算器 </p>
 * <p>Copyright: Copyright (c) 2006</p>
 * <p>Company:Neutron Studio </p>
 * @author lanner
 * @version L-1.0
 */
public class Frame1 extends JFrame {
  /**赋值变量,用于显示于屏幕的变量*/
  StringBuffer a1=new StringBuffer();
  /**外观风格的名字*/
  String plafName;
  /**定义存取记忆的M*/
  String M;
  /**运算判断变量,初始值为0,代表无运算法则,当加、减、乘、除等运算键按下时会赋予b1不同的值,各运算符键根据b1的值来判断运算法则*/
  int b1=0;
  /**等号的运算符判断*/
  int d1=0;
  /**判断科学计算版面是否打开*/
  int d2=0;
  /**小数点输入判断变量*/
  boolean b2=false;
  /**记忆M判断变量*/
  boolean b3=false;
  /**该变量是判断计算内容清空的第一次运算*/
  boolean b4=false;
  /**该变量判断按下运算符号键后按数字键有否按等于号*/
  boolean b5=false;
  /**用于判断等号是否连续不间断按下,false为否*/
  boolean b6=false;
  /**浮点型变量c1,用于缓存运算第一个数的值*/
  float c1;
  /**浮点型变量c2,用于缓存运算第二个数的值*/
  float c2;
  /**浮点型变量c3,用于缓存运算运算后答案的值*/
  float c3;



  JPanel contentPane;
  JMenuBar jMenuBar1 = new JMenuBar();
  JMenu jMenuFile = new JMenu();
  JMenuItem jMenuFileExit = new JMenuItem();
  BorderLayout borderLayout1 = new BorderLayout();
  JMenuItem jMenuItem1 = new JMenuItem();
  JMenu jMenu1 = new JMenu();
  JMenu jMenu3 = new JMenu();
  JMenuItem jMenuItem3 = new JMenuItem();
  JMenuItem jMenuItem4 = new JMenuItem();
  JMenuItem jMenuItem5 = new JMenuItem();
  JMenuItem jMenuHelpAbout = new JMenuItem();
  JMenu jMenuHelp = new JMenu();
  JMenuItem jMenuItem6 = new JMenuItem();
  JLabel jLabel2 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JLabel jLabel4 = new JLabel();
  JLabel jLabel5 = new JLabel();
  JPanel jPanel1 = new JPanel();
  BorderLayout borderLayout2 = new BorderLayout();
  JButton jButton2 = new JButton();
  JButton jBa_Opequal = new JButton();
  JButton jBa_Num3 = new JButton();
  JButton jBa_Num5 = new JButton();
  JPanel jPanel4 = new JPanel();
  JButton jButton7 = new JButton();
  JButton jBa_Opmultiply = new JButton();
  JLabel jLabel1 = new JLabel();
  JPanel jPanel3 = new JPanel();
  JButton jButton8 = new JButton();
  GridLayout gridLayout1 = new GridLayout();
  BorderLayout borderLayout4 = new BorderLayout();
  JButton jBb_CE = new JButton();
  JButton jBa_Opdel = new JButton();
  JButton jBa_Opadd = new JButton();
  GridLayout gridLayout2 = new GridLayout();
  JButton jBa_Num9 = new JButton();
  JPanel jPanel2 = new JPanel();
  JButton jButton3 = new JButton();
  JPanel jPanel5 = new JPanel();
  JButton jBa_Num2 = new JButton();
  JButton jBa_Num7 = new JButton();
  JButton jBa_Num8 = new JButton();
  JButton jButton6 = new JButton();
  GridLayout gridLayout3 = new GridLayout();
  JButton jBb_VE = new JButton();
  BorderLayout borderLayout6 = new BorderLayout();
  BorderLayout borderLayout3 = new BorderLayout();
  JButton jBa_Opminus = new JButton();
  JPanel jPanel7 = new JPanel();
  JButton jBa_Opdivision = new JButton();
  JButton jBa_Num4 = new JButton();
  JPanel jPanel8 = new JPanel();
  JButton jButton4 = new JButton();
  JButton jBa_Num6 = new JButton();
  JPanel jPanel6 = new JPanel();
  JButton jBa_Num1 = new JButton();
  BorderLayout borderLayout5 = new BorderLayout();
  JTextField jTshow = new JTextField();
  JButton jBa_Num0 = new JButton();
  JPanel jPanel9 = new JPanel();
  BorderLayout borderLayout7 = new BorderLayout();
  JPanel jPanel10 = new JPanel();
  JLabel jLabel6 = new JLabel();
  JLabel jLabel7 = new JLabel();
  JLabel jLabel8 = new JLabel();
  BorderLayout borderLayout8 = new BorderLayout();
  JPanel jPanel11 = new JPanel();
  BorderLayout borderLayout9 = new BorderLayout();
  JLabel jLabel9 = new JLabel();
  JPanel jPanel12 = new JPanel();
  BorderLayout borderLayout10 = new BorderLayout();
  JButton jButton31 = new JButton();
  JButton jButton30 = new JButton();
  GridLayout gridLayout4 = new GridLayout();
  JButton jButton28 = new JButton();
  JButton jButton33 = new JButton();
  JButton jButton27 = new JButton();
  JButton jButton29 = new JButton();
  JButton jButton36 = new JButton();
  JButton jButton26 = new JButton();
  JButton jButton35 = new JButton();
  JPanel jPanel13 = new JPanel();
  JButton jButton25 = new JButton();
  JButton jButton34 = new JButton();
  JButton jButton32 = new JButton();
  JButton jButton37 = new JButton();
  JButton jButton38 = new JButton();
  JButton jButton39 = new JButton();
  JLabel jLabel11 = new JLabel();
  JLabel jLabel12 = new JLabel();
  JLabel jLabel13 = new JLabel();
  JLabel jLabel14 = new JLabel();
  JPopupMenu jPopupMenu1 = new JPopupMenu();
  JMenuItem jMenuItem9 = new JMenuItem();
  JMenuItem jMenuItem122 = new JMenuItem();


  //Construct the frame
  public Frame1() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

  //Component initialization
  private void jbInit() throws Exception  {

//窗体的构成
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(borderLayout1);
    this.getContentPane().setBackground(SystemColor.control);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setResizable(false);
    this.setSize(new Dimension(403, 344));
    this.setTitle("Calculator");
    jMenuFile.setText("系统");
    jMenuFileExit.setHorizontalAlignment(SwingConstants.LEADING);
    jMenuFileExit.setText("退出");
    jMenuFileExit.addActionListener(new Frame1_jMenuFileExit_ActionAdapter(this));
    borderLayout1.setHgap(0);
    borderLayout1.setVgap(0);
    jMenu1.setText("设置");
    jMenuItem122.setHorizontalAlignment(SwingConstants.LEADING);
    jMenuItem122.setText("面板切换");
    jMenu3.setHorizontalAlignment(SwingConstants.LEADING);
    jMenu3.setText("外观风格");
    jMenuItem3.setHorizontalAlignment(SwingConstants.LEADING);
    jMenuItem3.setText("Windows风格");
    jMenuItem3.addActionListener(new Frame1_jMenuItem3_actionAdapter(this));
    jMenuItem4.setHorizontalAlignment(SwingConstants.LEADING);
    jMenuItem4.setText("Motif风格");
    jMenuItem4.addActionListener(new Frame1_jMenuItem4_actionAdapter(this));
    jMenuItem5.setHorizontalAlignment(SwingConstants.LEADING);
    jMenuItem5.setText("Metal风格");
    jMenuItem5.addActionListener(new Frame1_jMenuItem5_actionAdapter(this));
    jMenuHelpAbout.setHorizontalAlignment(SwingConstants.LEADING);
    jMenuHelpAbout.setText("关于计算器");
    jMenuHelpAbout.addActionListener(new Frame1_jMenuHelpAbout_ActionAdapter(this));
    jMenuHelp.setHorizontalAlignment(SwingConstants.LEADING);
    jMenuHelp.setText("帮助");
    jMenuItem6.setHorizontalAlignment(SwingConstants.LEADING);
    jMenuItem6.setText("快捷键说明");
    jMenuItem6.addActionListener(new Frame1_jMenuItem6_actionAdapter(this));
    jLabel2.setOpaque(true);
    jLabel2.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel2.setText("  ");
    jLabel3.setFont(new java.awt.Font("Dialog", 0, 9));
    jLabel3.setOpaque(true);
    jLabel3.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel3.setText("  ");
    jLabel3.setForeground(this.getBackground());
    jLabel2.setFont(new java.awt.Font("Dialog", 0, 9));
    jLabel2.setForeground(this.getBackground());
    jLabel4.setBackground(SystemColor.control);
    jLabel4.setFont(new java.awt.Font("Dialog", 0, 8));
    jLabel4.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel4.setForeground(this.getBackground());
    jLabel4.setText("   ");
    jLabel5.setForeground(this.getBackground());
    jLabel5.setText("  ");
    jLabel5.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel5.setOpaque(true);
    jLabel5.setFont(new java.awt.Font("Dialog", 0, 9));

    jPanel1.setLayout(borderLayout2);
    jButton2.setText("←");
    jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this));
    jButton2.setForeground(Color.red);
    jButton2.setToolTipText("键盘BackSpace");
    jButton2.setFont(new java.awt.Font("Dialog", 1, 14));
    jBa_Opequal.setText("=");
    jBa_Opequal.addActionListener(new Frame1_jBa_Opequal_actionAdapter(this));
    jBa_Opequal.setForeground(Color.blue);
    jBa_Opequal.setFont(new java.awt.Font("Dialog", 1, 12));
    jBa_Num3.setText("3");
    jBa_Num3.addActionListener(new Frame1_jBa_Num3_actionAdapter(this));
    jBa_Num3.setFont(new java.awt.Font("Dialog", 1, 12));
    jBa_Num5.setText("5");
    jBa_Num5.addActionListener(new Frame1_jBa_Num5_actionAdapter(this));
    jBa_Num5.setFont(new java.awt.Font("Dialog", 1, 12));
    jPanel4.setLayout(borderLayout4);
    jButton7.setFont(new java.awt.Font("Dialog", 1, 9));
    jButton7.setForeground(Color.red);
    jButton7.setToolTipText("键盘F1");
    jButton7.setSelected(false);
    jButton7.setText("<");
    jButton7.addActionListener(new Frame1_jButton7_actionAdapter(this));
    jBa_Opmultiply.setFont(new java.awt.Font("Dialog", 1, 13));
    jBa_Opmultiply.setForeground(Color.blue);
    jBa_Opmultiply.setText("*");
    jBa_Opmultiply.addActionListener(new Frame1_jBa_Opmultiply_actionAdapter(this));
    jLabel1.setFont(new java.awt.Font("Arial", 1, 11));
    jLabel1.setForeground(UIManager.getColor("Desktop.background"));
    jLabel1.setOpaque(true);
    jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel1.setText("Neutron Calculator L-1.0");
    jPanel3.setLayout(gridLayout1);
    jButton8.setFont(new java.awt.Font("Dialog", 0, 10));
    jButton8.setForeground(Color.blue);
    jButton8.setToolTipText("键盘%");
    jButton8.setText("%");
    jButton8.addActionListener(new Frame1_jButton8_actionAdapter(this));
    borderLayout4.setVgap(8);
    jBb_CE.setFont(new java.awt.Font("Dialog", 1, 10));
    jBb_CE.setForeground(Color.red);
    jBb_CE.setToolTipText("键盘C");
    jBb_CE.setText("CE");
    jBb_CE.addActionListener(new Frame1_jBb_CE_actionAdapter(this));
    jBa_Opdel.setFont(new java.awt.Font("Dialog", 1, 16));
    jBa_Opdel.setText("·");
    jBa_Opdel.addActionListener(new Frame1_jBa_Opdel_actionAdapter(this));
    jBa_Opadd.setFont(new java.awt.Font("Dialog", 1, 13));
    jBa_Opadd.setForeground(Color.blue);
    jBa_Opadd.setText("+");
    jBa_Opadd.addActionListener(new Frame1_jBa_Opadd_actionAdapter(this));
    gridLayout2.setColumns(4);
    gridLayout2.setHgap(3);
    gridLayout2.setRows(2);
    gridLayout2.setVgap(3);
    jBa_Num9.setFont(new java.awt.Font("Dialog", 1, 12));
    jBa_Num9.setText("9");
    jBa_Num9.addActionListener(new Frame1_jBa_Num9_actionAdapter(this));
    jPanel2.setLayout(borderLayout3);
    jButton3.setFont(new java.awt.Font("Dialog", 1, 9));
    jButton3.setForeground(Color.red);
    jButton3.setToolTipText("N");
    jButton3.setText("M-");
    jButton3.addActionListener(new Frame1_jButton3_actionAdapter(this));
    jPanel5.setLayout(gridLayout2);
    jPanel5.setBorder(null);
    jBa_Num2.setFont(new java.awt.Font("Dialog", 1, 12));
    jBa_Num2.setText("2");
    jBa_Num2.addActionListener(new Frame1_jBa_Num2_actionAdapter(this));
    jBa_Num7.setFont(new java.awt.Font("Dialog", 1, 12));
    jBa_Num7.setText("7");
    jBa_Num7.addActionListener(new Frame1_jBa_Num7_actionAdapter(this));
    jBa_Num8.setFont(new java.awt.Font("Dialog", 1, 12));
    jBa_Num8.setText("8");
    jBa_Num8.addActionListener(new Frame1_jBa_Num8_actionAdapter(this));
    jButton6.setFont(new java.awt.Font("Dialog", 1, 10));
    jButton6.setForeground(Color.blue);
    jButton6.setToolTipText("键盘F");
    jButton6.setText("±");
    jButton6.addActionListener(new Frame1_jButton6_actionAdapter(this));
    gridLayout3.setColumns(4);
    gridLayout3.setHgap(3);
    gridLayout3.setRows(4);
    gridLayout3.setVgap(3);
    jBb_VE.setFont(new java.awt.Font("Dialog", 1, 11));
    jBb_VE.setToolTipText("键盘E");
    jBb_VE.setText("E");
    jBb_VE.addActionListener(new Frame1_jBb_VE_actionAdapter(this));
    borderLayout6.setHgap(0);
    borderLayout6.setVgap(0);
    borderLayout3.setHgap(0);
    borderLayout3.setVgap(0);
    jBa_Opminus.setFont(new java.awt.Font("Dialog", 1, 18));
    jBa_Opminus.setForeground(Color.blue);
    jBa_Opminus.setText("-");
    jBa_Opminus.addActionListener(new Frame1_jBa_Opminus_actionAdapter(this));
    jPanel7.setLayout(borderLayout5);
    jPanel7.setBorder(null);
    jBa_Opdivision.setFont(new java.awt.Font("Dialog", 1, 12));
    jBa_Opdivision.setForeground(Color.blue);
    jBa_Opdivision.setText("/");
    jBa_Opdivision.addActionListener(new Frame1_jBa_Opdivision_actionAdapter(this));
    jBa_Num4.setFont(new java.awt.Font("Dialog", 1, 12));
    jBa_Num4.setText("4");
    jBa_Num4.addActionListener(new Frame1_jBa_Num4_actionAdapter(this));
    jPanel8.setLayout(borderLayout6);
    jButton4.setFont(new java.awt.Font("Dialog", 1, 10));
    jButton4.setToolTipText("键盘M");
    jButton4.setText("M");
    jButton4.addActionListener(new Frame1_jButton4_actionAdapter(this));
    jBa_Num6.setFont(new java.awt.Font("Dialog", 1, 12));
    jBa_Num6.setText("6");
    jBa_Num6.addActionListener(new Frame1_jBa_Num6_actionAdapter(this));
    jPanel6.setLayout(gridLayout3);
    jBa_Num1.setFont(new java.awt.Font("Dialog", 1, 12));
    jBa_Num1.setText("1");
    jBa_Num1.addActionListener(new Frame1_jBa_Num1_actionAdapter(this));
    borderLayout5.setHgap(3);
    borderLayout5.setVgap(3);
    jTshow.setBackground(Color.white);
    jTshow.setEnabled(true);
    jTshow.setFont(new java.awt.Font("Dialog", 1, 13));
    jTshow.setDisabledTextColor(Color.black);
    jTshow.setEditable(false);
    jTshow.setText("0.");
    jTshow.setHorizontalAlignment(SwingConstants.RIGHT);
    jTshow.addMouseListener(new Frame1_jTshow_mouseAdapter(this));
    jBa_Num0.setFont(new java.awt.Font("Dialog", 1, 12));
    jBa_Num0.setText("0");
    jBa_Num0.addActionListener(new Frame1_jBa_Num0_actionAdapter(this));
    jPanel9.setLayout(borderLayout7);
    jPanel10.setLayout(borderLayout8);
    jLabel6.setFont(new java.awt.Font("Dialog", 0, 9));
    jLabel6.setOpaque(true);
    jLabel6.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel6.setText("  ");
    jLabel6 .setForeground(this.getBackground());

⌨️ 快捷键说明

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