文件名称:java编的简单计算器
文件大小:6KB
文件格式:JAVA
更新时间:2014-07-27 09:43:32
计算器
一个java编译的最简单的计算器
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class jisuan extends JFrame implements ActionListener{
/**
*
*/
private static final long serialVersionUID = 5823423246304135749L;
JPanel cp=new JPanel();
JPanel cp1=new JPanel();
Double nu1,nu2;
ImageIcon ii=new ImageIcon("images/2_marcblue.jpg");
JPanel cp2=new JPanel();
JLabel jl=new JLabel();
String[] Jlabel = {"7","8","9","/","4","5","6","*","1","2","3","-","0",".","=","+"};//声明标签数组label1存放按钮上的标签
JButton[] b;
JButton h=new JButton("c");
//private JButton buttonWithTitle=new JButton("Button with Title",new ImageIcon("src/anwendung/tree.jpg"));
private JButton c=new JButton("后退",ii);
JButton pf=new JButton("x^y");
int j=0,n=0,a=0,g=0;
//Button[] b=new Button[10];
//JTextArea jt=new JTextArea(1,34);
JTextField jt=new JTextField("0",30);
//JLabel jt=new JLabel();
String st,st1,st2;
Boolean t=true;
public jisuan(){
setTitle("计算器");
setSize(220,220);
//this.setbackgroundImage = new ImageIcon("images/6.21.bmp");
cp=(JPanel)this.getContentPane();
//this.setExtendedState(HIDE_ON_CLOSE);
this.setUndecorated(false);
this.setResizable(false);//窗口固定不变。
//cp.setEnabled(false);
this.addWindowListener(new WindowAdapter(){//给窗口f添加窗口事件监听器
public void windowClosing(WindowEvent eve){
System.exit(0);
}
});
cp.setLayout(new BorderLayout());
cp.add(jt,BorderLayout.NORTH);
cp.add(cp1,BorderLayout.CENTER);
//cp.add(cp2,BorderLayout.SOUTH);
//cp1.setLayout(new GridLayout(3,4));
cp1.setLayout(null);
//cp.add(jt);
jt.setHorizontalAlignment(JTextField.RIGHT);//右边显示。
jt.setFont(new Font("Serif",Font.BOLD|Font.ITALIC,15));//设置字体的大小和显示方式;
jt.setBackground(Color.white);//背景白色
jt.setEditable(false);
//jt.setEnabled(true);
b = new JButton[Jlabel.length];
for(int i=0;i