📄 calculatorframe.java
字号:
package Cursor;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
/**
* <p>Title: calculatordemo</p>
* <p>Description: This is a calculatordemo</p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author 刘勋华
* @version 1.0
*/
public class calculatorFrame extends JFrame {
JPanel contentPane;
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();
JButton jButton5 = new JButton();
JButton jButton6 = new JButton();
JButton jButton7 = new JButton();
JButton jButton8 = new JButton();
JButton jButton9 = new JButton();
JButton jButton10 = new JButton();
JButton jButton11 = new JButton();
JButton jButton12 = new JButton();
JButton jButton13 = new JButton();
JButton jButton14 = new JButton();
JButton jButton15 = new JButton();
JButton jButton16 = new JButton();
JButton jButton17 = new JButton();
JButton jButton18 = new JButton();
double startnum;
double endnum;
double midnum;
int flag=0;
int point=0;
About aboutdlg=new About();
String ope,str;
boolean isresult=false;
String strValue=null;
JTextArea jTextArea1 = new JTextArea();
JButton jButton19 = new JButton();
JButton jButton20 = new JButton();
JButton jButton21 = new JButton();
JButton jButton22 = new JButton();
JButton jButton23 = new JButton();
JButton jButton24 = new JButton();
JButton jButton26 = new JButton();
JButton jButton27 = new JButton();
JButton jButton25 = new JButton();
JButton jButton29 = new JButton();
JButton jButton30 = new JButton();
JButton jButton31 = new JButton();
JButton jButton32 = new JButton();
JButton jButton33 = new JButton();
JLabel jLabel1 = new JLabel();
//Construct the frame
public calculatorFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jButton1.setBackground(Color.white);
jButton1.setBounds(new Rectangle(200, 205, 71, 25));
jButton1.setForeground(Color.blue);
jButton1.setToolTipText("");
jButton1.setText("%");
jButton1.addActionListener(new calculatorFrame_jButton1_actionAdapter(this));
contentPane.setLayout(null);
this.getContentPane().setBackground(SystemColor.control);
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
this.setFont(new java.awt.Font("Dialog", 0, 12));
this.setLocale(java.util.Locale.getDefault());
this.setSize(new Dimension(490, 354));
this.setState(Frame.NORMAL);
this.setFocusable(true);
this.addKeyListener(new calculatorFrame_this_keyAdapter(this));
this.setFocusableWindowState(true);
jButton2.setBackground(Color.white);
jButton2.setBounds(new Rectangle(200, 145, 71, 25));
jButton2.setForeground(Color.blue);
jButton2.setText("×");
jButton2.addActionListener(new calculatorFrame_jButton2_actionAdapter(this));
jButton3.setBackground(Color.white);
jButton3.setBounds(new Rectangle(75, 218, 53, 38));
jButton3.setForeground(SystemColor.activeCaption);
jButton3.setText(".");
jButton3.addActionListener(new calculatorFrame_jButton3_actionAdapter(this));
jButton4.setBackground(Color.white);
jButton4.setBounds(new Rectangle(355, 30, 109, 28));
jButton4.setForeground(Color.red);
jButton4.setToolTipText("");
jButton4.setActionCommand("C");
jButton4.setText("Backspace");
jButton4.addActionListener(new calculatorFrame_jButton4_actionAdapter(this));
jButton5.setBackground(Color.white);
jButton5.setBounds(new Rectangle(15, 173, 53, 38));
jButton5.setForeground(SystemColor.activeCaption);
jButton5.setText("7");
jButton5.addActionListener(new calculatorFrame_jButton5_actionAdapter(this));
jButton6.setBackground(Color.white);
jButton6.setBounds(new Rectangle(15, 130, 53, 38));
jButton6.setForeground(SystemColor.activeCaption);
jButton6.setText("4");
jButton6.addActionListener(new calculatorFrame_jButton6_actionAdapter(this));
jButton7.setBackground(Color.white);
jButton7.setBounds(new Rectangle(15, 85, 53, 38));
jButton7.setForeground(SystemColor.activeCaption);
jButton7.setDoubleBuffered(false);
jButton7.setActionCommand("1");
jButton7.setDisabledSelectedIcon(null);
jButton7.setFocusPainted(true);
jButton7.setText("1");
jButton7.addKeyListener(new calculatorFrame_jButton7_keyAdapter(this));
jButton7.addFocusListener(new calculatorFrame_jButton7_focusAdapter(this));
jButton7.addActionListener(new calculatorFrame_jButton7_actionAdapter(this));
jButton8.setBackground(Color.white);
jButton8.setBounds(new Rectangle(135, 130, 53, 38));
jButton8.setForeground(SystemColor.activeCaption);
jButton8.setText("6");
jButton8.addActionListener(new calculatorFrame_jButton8_actionAdapter(this));
jButton9.setBackground(Color.white);
jButton9.setBounds(new Rectangle(75, 173, 53, 38));
jButton9.setForeground(SystemColor.activeCaption);
jButton9.setText("8");
jButton9.addActionListener(new calculatorFrame_jButton9_actionAdapter(this));
jButton10.setBackground(Color.white);
jButton10.setBounds(new Rectangle(75, 130, 53, 38));
jButton10.setForeground(SystemColor.activeCaption);
jButton10.setText("5");
jButton10.addActionListener(new calculatorFrame_jButton10_actionAdapter(this));
jButton11.setBackground(Color.white);
jButton11.setBounds(new Rectangle(75, 85, 53, 38));
jButton11.setForeground(SystemColor.activeCaption);
jButton11.setText("2");
jButton11.addActionListener(new calculatorFrame_jButton11_actionAdapter(this));
jButton12.setBackground(Color.white);
jButton12.setBounds(new Rectangle(200, 175, 71, 25));
jButton12.setForeground(Color.blue);
jButton12.setText("/");
jButton12.addActionListener(new calculatorFrame_jButton12_actionAdapter(this));
jButton13.setBackground(Color.white);
jButton13.setBounds(new Rectangle(200, 115, 71, 25));
jButton13.setForeground(Color.blue);
jButton13.setText("-");
jButton13.addActionListener(new calculatorFrame_jButton13_actionAdapter(this));
jButton14.setBackground(Color.white);
jButton14.setBounds(new Rectangle(135, 85, 53, 38));
jButton14.setForeground(SystemColor.activeCaption);
jButton14.setText("3");
jButton14.addActionListener(new calculatorFrame_jButton14_actionAdapter(this));
jButton15.setBackground(Color.white);
jButton15.setBounds(new Rectangle(135, 173, 53, 38));
jButton15.setForeground(SystemColor.activeCaption);
jButton15.setText("9");
jButton15.addActionListener(new calculatorFrame_jButton15_actionAdapter(this));
jButton16.setBackground(Color.white);
jButton16.setBounds(new Rectangle(200, 235, 72, 25));
jButton16.setForeground(Color.blue);
jButton16.setText("=");
jButton16.addActionListener(new calculatorFrame_jButton16_actionAdapter(this));
jButton17.setBackground(Color.white);
jButton17.setBounds(new Rectangle(15, 218, 53, 38));
jButton17.setForeground(SystemColor.activeCaption);
jButton17.setText("0");
jButton17.addActionListener(new calculatorFrame_jButton17_actionAdapter(this));
jButton18.setBackground(Color.white);
jButton18.setBounds(new Rectangle(200, 85, 71, 25));
jButton18.setForeground(Color.blue);
jButton18.setText("+");
jButton18.addActionListener(new calculatorFrame_jButton18_actionAdapter(this));
contentPane.setBackground(Color.black);
contentPane.setFont(new java.awt.Font("Dialog", 1, 30));
contentPane.setForeground(Color.blue);
contentPane.setAlignmentX((float) 0.5);
contentPane.setBorder(BorderFactory.createEtchedBorder());
contentPane.setDebugGraphicsOptions(0);
contentPane.setDoubleBuffered(true);
contentPane.setMaximumSize(new Dimension(20, 20));
contentPane.setMinimumSize(new Dimension(20, 20));
contentPane.setNextFocusableComponent(this);
contentPane.setOpaque(true);
contentPane.setPreferredSize(new Dimension(20, 20));
contentPane.setToolTipText("");
contentPane.setInputVerifier(null);
contentPane.setVerifyInputWhenFocusTarget(false);
contentPane.addFocusListener(new calculatorFrame_contentPane_focusAdapter(this));
jTextArea1.setEnabled(false);
jTextArea1.setAlignmentX((float) 0.5);
jTextArea1.setBorder(BorderFactory.createEtchedBorder());
jTextArea1.setMaximumSize(new Dimension(20, 20));
jTextArea1.setMinimumSize(new Dimension(20, 20));
jTextArea1.setPreferredSize(new Dimension(20, 20));
jTextArea1.setToolTipText("");
jTextArea1.setDisabledTextColor(Color.darkGray);
jTextArea1.setSelectionStart(0);
jTextArea1.setText("");
jTextArea1.setTabSize(12);
jTextArea1.setBounds(new Rectangle(14, 30, 265, 29));
jButton19.setBackground(Color.white);
jButton19.setBounds(new Rectangle(134, 218, 53, 38));
jButton19.setForeground(UIManager.getColor("ToolBar.dockingForeground"));
jButton19.setText("+/-");
jButton19.addActionListener(new calculatorFrame_jButton19_actionAdapter(this));
jButton20.setBackground(Color.white);
jButton20.setBounds(new Rectangle(296, 30, 47, 28));
jButton20.setForeground(Color.red);
jButton20.setText("C");
jButton20.addActionListener(new calculatorFrame_jButton20_actionAdapter(this));
jButton21.setBackground(Color.white);
jButton21.setBounds(new Rectangle(281, 85, 92, 25));
jButton21.setForeground(Color.blue);
jButton21.setText("Sin ");
jButton21.addActionListener(new calculatorFrame_jButton21_actionAdapter(this));
jButton22.setBackground(Color.white);
jButton22.setBounds(new Rectangle(281, 145, 92, 25));
jButton22.setForeground(Color.blue);
jButton22.setText("Cos");
jButton22.addActionListener(new calculatorFrame_jButton22_actionAdapter(this));
jButton23.setBackground(Color.white);
jButton23.setBounds(new Rectangle(281, 205, 92, 25));
jButton23.setForeground(Color.blue);
jButton23.setText("Tan");
jButton23.addActionListener(new calculatorFrame_jButton23_actionAdapter(this));
jButton24.setBackground(Color.white);
jButton24.setBounds(new Rectangle(281, 115, 92, 25));
jButton24.setForeground(Color.blue);
jButton24.setText("arcSin ");
jButton24.addActionListener(new calculatorFrame_jButton24_actionAdapter(this));
jButton26.setText("arcCos ");
jButton26.addActionListener(new calculatorFrame_jButton26_actionAdapter(this));
jButton26.setBackground(Color.white);
jButton26.setBounds(new Rectangle(281, 175, 92, 25));
jButton26.setForeground(Color.blue);
jButton27.setBackground(Color.white);
jButton27.setBounds(new Rectangle(280, 235, 93, 25));
jButton27.setForeground(Color.blue);
jButton27.setText("arcTan ");
jButton27.addActionListener(new calculatorFrame_jButton27_actionAdapter(this));
jButton25.setBackground(Color.white);
jButton25.setBounds(new Rectangle(380, 85, 84, 25));
jButton25.setForeground(Color.blue);
jButton25.setText("EXP");
jButton25.addActionListener(new calculatorFrame_jButton25_actionAdapter(this));
jButton29.setBackground(Color.white);
jButton29.setBounds(new Rectangle(381, 145, 83, 25));
jButton29.setForeground(Color.blue);
jButton29.setText("1/X");
jButton29.addActionListener(new calculatorFrame_jButton29_actionAdapter(this));
jButton30.setBackground(Color.white);
jButton30.setBounds(new Rectangle(380, 114, 84, 25));
jButton30.setForeground(Color.blue);
jButton30.setText("Log");
jButton30.addActionListener(new calculatorFrame_jButton30_actionAdapter(this));
jButton31.setBackground(Color.white);
jButton31.setBounds(new Rectangle(381, 175, 83, 25));
jButton31.setForeground(Color.blue);
jButton31.setText("Sqrt");
jButton31.addActionListener(new calculatorFrame_jButton31_actionAdapter(this));
jButton32.setBackground(Color.white);
jButton32.setBounds(new Rectangle(380, 205, 84, 25));
jButton32.setForeground(Color.blue);
jButton32.setText("Abs");
jButton32.addActionListener(new calculatorFrame_jButton32_actionAdapter(this));
jButton33.setBackground(Color.white);
jButton33.setBounds(new Rectangle(380, 235, 84, 25));
jButton33.setForeground(Color.blue);
jButton33.setText("n !");
jButton33.addActionListener(new calculatorFrame_jButton33_actionAdapter(this));
jLabel1.setFont(new java.awt.Font("Dialog", 0, 15));
jLabel1.setForeground(Color.white);
jLabel1.setText(" CopyRight @ 03_Software Engineering2 Liu XunHua");
jLabel1.setBounds(new Rectangle(12, 271, 372, 40));
contentPane.add(jButton13, null);
contentPane.add(jButton2, null);
contentPane.add(jButton12, null);
contentPane.add(jButton1, null);
contentPane.add(jButton5, null);
contentPane.add(jButton9, null);
contentPane.add(jButton11, null);
contentPane.add(jButton14, null);
contentPane.add(jButton7, null);
contentPane.add(jButton10, null);
contentPane.add(jButton6, null);
contentPane.add(jButton8, null);
contentPane.add(jButton15, null);
contentPane.add(jButton18, null);
contentPane.add(jButton17, null);
contentPane.add(jButton3, null);
contentPane.add(jButton19, null);
contentPane.add(jButton16, null);
contentPane.add(jButton21, null);
contentPane.add(jButton24, null);
contentPane.add(jButton22, null);
contentPane.add(jButton26, null);
contentPane.add(jButton27, null);
contentPane.add(jButton23, null);
contentPane.add(jButton25, null);
contentPane.add(jButton30, null);
contentPane.add(jButton29, null);
contentPane.add(jButton31, null);
contentPane.add(jButton32, null);
contentPane.add(jButton33, null);
contentPane.add(jButton20, null);
contentPane.add(jTextArea1, null);
contentPane.add(jButton4, null);
contentPane.add(jLabel1, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
this.setFocusable(true);
jTextArea1.setText("0");
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);}
}
void jButton7_actionPerformed(ActionEvent e)
{
if(isresult){
jTextArea1.setText("0");
isresult=!isresult;
}
strValue=jTextArea1.getText();
if(strValue.equals("0")){
jTextArea1.setText(e.getActionCommand());}
else{
strValue=strValue+e.getActionCommand();
jTextArea1.setText(strValue);}
this.requestFocus();
}
void jButton11_actionPerformed(ActionEvent e) {
if(isresult){
jTextArea1.setText("0");
isresult=!isresult;
}
strValue=jTextArea1.getText();
if(strValue.equals("0")){
jTextArea1.setText(e.getActionCommand());}
else{
strValue=strValue+e.getActionCommand();
jTextArea1.setText(strValue);}
this.requestFocus();
}
void jButton14_actionPerformed(ActionEvent e) {
if(isresult){
jTextArea1.setText("0");
isresult=!isresult;
}
strValue=jTextArea1.getText();
if(strValue.equals("0")){
jTextArea1.setText(e.getActionCommand());}
else{
strValue=strValue+e.getActionCommand();
jTextArea1.setText(strValue);}
this.requestFocus();
}
void jButton6_actionPerformed(ActionEvent e) {
if(isresult){
jTextArea1.setText("0");
isresult=!isresult;
}
strValue=jTextArea1.getText();
if(strValue.equals("0")){
jTextArea1.setText(e.getActionCommand());}
else{
strValue=strValue+e.getActionCommand();
jTextArea1.setText(strValue);}
this.requestFocus();
}
void jButton10_actionPerformed(ActionEvent e) {
if(isresult){
jTextArea1.setText("0");
isresult=!isresult;
}
strValue=jTextArea1.getText();
if(strValue.equals("0")){
jTextArea1.setText(e.getActionCommand());}
else{
strValue=strValue+e.getActionCommand();
jTextArea1.setText(strValue);}
this.requestFocus();
}
void jButton8_actionPerformed(ActionEvent e) {
if(isresult){
jTextArea1.setText("0");
isresult=!isresult;
}
strValue=jTextArea1.getText();
if(strValue.equals("0")){
jTextArea1.setText(e.getActionCommand());}
else{
strValue=strValue+e.getActionCommand();
jTextArea1.setText(strValue);}
this.requestFocus();
}
void jButton5_actionPerformed(ActionEvent e) {
if(isresult){
jTextArea1.setText("0");
isresult=!isresult;
}
strValue=jTextArea1.getText();
if(strValue.equals("0")){
jTextArea1.setText(e.getActionCommand());}
else{
strValue=strValue+e.getActionCommand();
jTextArea1.setText(strValue);}
this.requestFocus();
}
void jButton9_actionPerformed(ActionEvent e) {
if(isresult){
jTextArea1.setText("0");
isresult=!isresult;
}
strValue=jTextArea1.getText();
if(strValue.equals("0")){
jTextArea1.setText(e.getActionCommand());}
else{
strValue=strValue+e.getActionCommand();
jTextArea1.setText(strValue);}
this.requestFocus();
}
void jButton15_actionPerformed(ActionEvent e) {
if(isresult){
jTextArea1.setText("0");
isresult=!isresult;
}
strValue=jTextArea1.getText();
if(strValue.equals("0")){
jTextArea1.setText(e.getActionCommand());}
else{
strValue=strValue+e.getActionCommand();
jTextArea1.setText(strValue); }
this.requestFocus();
}
void jButton17_actionPerformed(ActionEvent e) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -