📄 counter.java
字号:
package jisanqi;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Counter extends JFrame {
XYLayout xYLayout1 = new XYLayout();
JTextField t = new JTextField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();
JButton jButton5 = 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();
JButton jButton19 = new JButton();
JButton jButton20 = new JButton();
JButton jButton21 = new JButton();
JButton jButton22 = new JButton();
JButton jButton23 = new JButton();
JButton jButton24 = new JButton();
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenu1 = new JMenu();
JMenuItem jMenuItem1 = new JMenuItem();
JMenu jMenu2 = new JMenu();
JMenuItem jMenuItem2 = new JMenuItem();
JMenuItem jMenuItem3 = new JMenuItem();
JMenu jMenu3 = new JMenu();
JMenuItem jMenuItem4 = new JMenuItem();
public String a,b,c;
public boolean falg=true;
public Counter() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Counter counter = new Counter();
counter.show() ;
counter.pack() ;
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(xYLayout1);
t.setForeground(Color.pink);
t.setText("");
t.setHorizontalAlignment(SwingConstants.RIGHT);
jButton1.setText("8");
jButton1.addActionListener(new Counter_jButton1_actionAdapter(this));
jButton2.setText("7");
jButton2.addActionListener(new Counter_jButton2_actionAdapter(this));
jButton3.setText("9");
jButton3.addActionListener(new Counter_jButton3_actionAdapter(this));
jButton4.setText("/");
jButton4.addActionListener(new Counter_jButton4_actionAdapter(this));
jButton5.setText("backspace");
jButton5.addActionListener(new Counter_jButton5_actionAdapter(this));
jButton7.setText("4");
jButton7.addActionListener(new Counter_jButton7_actionAdapter(this));
jButton8.setText("5");
jButton8.addActionListener(new Counter_jButton8_actionAdapter(this));
jButton9.setText("6");
jButton9.addActionListener(new Counter_jButton9_actionAdapter(this));
jButton10.setText("*");
jButton10.addActionListener(new Counter_jButton10_actionAdapter(this));
jButton11.setText("CE");
jButton11.addActionListener(new Counter_jButton11_actionAdapter(this));
jButton12.setText("sin");
jButton12.addActionListener(new Counter_jButton12_actionAdapter(this));
jButton13.setText("1");
jButton13.addActionListener(new Counter_jButton13_actionAdapter(this));
jButton14.setText("2");
jButton14.addActionListener(new Counter_jButton14_actionAdapter(this));
jButton15.setText("3");
jButton15.addActionListener(new Counter_jButton15_actionAdapter(this));
jButton16.setText("-");
jButton16.addActionListener(new Counter_jButton16_actionAdapter(this));
jButton17.setText("cos");
jButton17.addActionListener(new Counter_jButton17_actionAdapter(this));
jButton18.setText("角度");
jButton18.addActionListener(new Counter_jButton18_actionAdapter(this));
jButton19.setText("0");
jButton19.addActionListener(new Counter_jButton19_actionAdapter(this));
jButton20.setText("+/-");
jButton20.addActionListener(new Counter_jButton20_actionAdapter(this));
jButton21.setText(".");
jButton21.addActionListener(new Counter_jButton21_actionAdapter(this));
jButton22.setText("+");
jButton22.addActionListener(new Counter_jButton22_actionAdapter(this));
jButton23.setText("=");
jButton23.addActionListener(new Counter_jButton23_actionAdapter(this));
jButton24.setText("弧度");
jButton24.addActionListener(new Counter_jButton24_actionAdapter(this));
jMenu1.setText("File");
jMenuItem1.setText("Exit");
jMenuItem1.addActionListener(new Counter_jMenuItem1_actionAdapter(this));
jMenu2.setText("Edit");
jMenuItem2.setText("Copy");
jMenuItem2.addActionListener(new Counter_jMenuItem2_actionAdapter(this));
jMenuItem3.setText("Paste");
jMenuItem3.addActionListener(new Counter_jMenuItem3_actionAdapter(this));
jMenu3.setText("Help");
jMenuItem4.setText("About");
jMenuItem4.addActionListener(new Counter_jMenuItem4_actionAdapter(this));
this.setJMenuBar(jMenuBar1);
this.getContentPane().add(t, new XYConstraints(8, 14, 380, 27));
this.getContentPane().add(jButton24, new XYConstraints(333, 218, 61, 41));
this.getContentPane().add(jButton23, new XYConstraints(268, 218, 56, 41));
this.getContentPane().add(jButton22, new XYConstraints(203, 218, 56, 41));
this.getContentPane().add(jButton21, new XYConstraints(138, 218, 56, 41));
this.getContentPane().add(jButton20, new XYConstraints(73, 218, 56, 41));
this.getContentPane().add(jButton19, new XYConstraints(8, 218, 56, 41));
this.getContentPane().add(jButton13, new XYConstraints(8, 160, 56, 41));
this.getContentPane().add(jButton14, new XYConstraints(73, 160, 56, 41));
this.getContentPane().add(jButton15, new XYConstraints(138, 160, 56, 41));
this.getContentPane().add(jButton16, new XYConstraints(203, 160, 56, 41));
this.getContentPane().add(jButton17, new XYConstraints(268, 160, 56, 41));
this.getContentPane().add(jButton18, new XYConstraints(333, 160, 60, 41));
this.getContentPane().add(jButton11, new XYConstraints(268, 103, 56, 41));
this.getContentPane().add(jButton10, new XYConstraints(203, 103, 56, 41));
this.getContentPane().add(jButton9, new XYConstraints(138, 103, 56, 41));
this.getContentPane().add(jButton8, new XYConstraints(73, 103, 56, 41));
this.getContentPane().add(jButton7, new XYConstraints(8, 103, 56, 41));
this.getContentPane().add(jButton12, new XYConstraints(333, 103, 58, 41));
this.getContentPane().add(jButton2, new XYConstraints(8, 45, 56, 41));
this.getContentPane().add(jButton5, new XYConstraints(268, 45, 117, 41));
this.getContentPane().add(jButton4, new XYConstraints(203, 45, 56, 41));
this.getContentPane().add(jButton3, new XYConstraints(138, 45, 56, 41));
this.getContentPane().add(jButton1, new XYConstraints(73, 45, 56, 41));
jMenuBar1.add(jMenu1);
jMenuBar1.add(jMenu2);
jMenuBar1.add(jMenu3);
jMenu1.add(jMenuItem1);
jMenu2.add(jMenuItem2);
jMenu2.add(jMenuItem3);
jMenu3.add(jMenuItem4);
}
void jButton19_actionPerformed(ActionEvent e) {
String str;
str=t.getText() ;
if(str.equals("0") )
t.setText("0") ;
else
t.setText(str + "0") ;
}
void jButton13_actionPerformed(ActionEvent e) {
String str;
str=t.getText() ;
if(str.equals("0") )
t.setText("1") ;
else
t.setText(str + "1") ;
}
void jButton14_actionPerformed(ActionEvent e) {
String str;
str=t.getText() ;
if(str.equals("0") )
t.setText("2") ;
else
t.setText(str + "2") ;
}
void jButton15_actionPerformed(ActionEvent e) {
String str;
str=t.getText() ;
if(str.equals("0") )
t.setText("3") ;
else
t.setText(str + "3") ;
}
void jButton7_actionPerformed(ActionEvent e) {
String str;
str=t.getText() ;
if(str.equals("0") )
t.setText("4") ;
else
t.setText(str + "4") ;
}
void jButton8_actionPerformed(ActionEvent e) {
String str;
str=t.getText() ;
if(str.equals("0") )
t.setText("5") ;
else
t.setText(str + "5") ;
}
void jButton9_actionPerformed(ActionEvent e) {
String str;
str=t.getText() ;
if(str.equals("0") )
t.setText("6") ;
else
t.setText(str + "6") ;
}
void jButton2_actionPerformed(ActionEvent e) {
String str;
str=t.getText() ;
if(str.equals("0") )
t.setText("7") ;
else
t.setText(str + "7") ;
}
void jButton1_actionPerformed(ActionEvent e) {
String str;
str=t.getText() ;
if(str.equals("0") )
t.setText("8") ;
else
t.setText(str + "8") ;
}
void jButton3_actionPerformed(ActionEvent e) {
String str;
str=t.getText() ;
if(str.equals("0") )
t.setText("9") ;
else
t.setText(str + "9") ;
}
void jButton21_actionPerformed(ActionEvent e) {
String str;
str=t.getText() ;
if(t.getText() .length() ==0)
falg=false;
for(int i=0;i<t.getText() .length();i++)
if('.'==t.getText() .charAt(i) ){
falg=false;
break;
}
if(falg==true){
t.setText(str+".") ;
}
}
void jMenuItem1_actionPerformed(ActionEvent e) {
System.exit(0) ;
}
void jMenuItem2_actionPerformed(ActionEvent e) {
t.copy() ;
}
void jMenuItem3_actionPerformed(ActionEvent e) {
t.paste() ;
}
void jButton22_actionPerformed(ActionEvent e) {
//+
a=t.getText() ;
c=jButton22.getText() ;
falg=true;
t.setText("") ;
}
void jButton16_actionPerformed(ActionEvent e) {
//-
a=t.getText() ;
c=jButton16.getText() ;
falg=true;
t.setText("") ;
}
void jButton10_actionPerformed(ActionEvent e) {
//*
a=t.getText() ;
c=jButton10.getText() ;
falg=true;
t.setText("") ;
}
void jButton4_actionPerformed(ActionEvent e) {
///
a=t.getText() ;
c=jButton4.getText() ;
falg=true;
t.setText("") ;
}
void jButton23_actionPerformed(ActionEvent e) {
double d ,f;
String m,n;
b=t.getText();
if(c.equals("+") )
{
d=Double.parseDouble(a)+Double.parseDouble(b) ;
m=Double.toString(d) ;
t.setText(m) ;
}
if(c.equals("-") )
{
d=Double.parseDouble(a)-Double.parseDouble(b) ;
m=Double.toString(d) ;
t.setText(m) ;
}
if(c.equals("*") )
{
d=Double.parseDouble(a)*Double.parseDouble(b) ;
m=Double.toString(d) ;
t.setText(m) ;
}
if(c.equals("/") )
{
if(b.equals("0") )
{
return;
}
else{
d=Double.parseDouble(a)/Double.parseDouble(b) ;
m=Double.toString(d) ;
}
t.setText(m) ;
}
}
void jButton11_actionPerformed(ActionEvent e) {
t.setText("0") ;
}
void jButton5_actionPerformed(ActionEvent e) {
String str;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -