package bean;
import java.awt.*;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.util.*;
public class Calculate extends JFrame implements ActionListener {
// 10 11 12 13 14 15 16 17 18
String bn[]={"0","1","2","3","4","5","6","7","8","9","+","-","*","/",".","CE","C","=","+/-"};
JButton btn[]=new JButton[19];
Panel p[]=new Panel[6];
TextField text;
Box box;
FlowLayout fv;
Calculate(String title)
{
super(title);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
box=Box.createVerticalBox();
fv=new FlowLayout();
fv.setVgap(20);
/*
//下面是设置计算器图标的方法:
java.net.URL imgURL = Calculate.class.getResource("images/icon.jpg"); // 绝 对 路
径:"./images/icon.jpg",相对路径:"images/icon.jpg"
ImageIcon imgIcon = new ImageIcon(imgURL);
Image img = imgIcon.getImage();
this.setIconImage(img);
*/
this.setLocationRelativeTo(null);
for(int i=0;i<bn.length;i++)
{
btn[i]=new JButton(bn[i]);
btn[i].addActionListener(this);
if(i!=15&&i!=16)
{
btn[i].setPreferredSize(new Dimension(55,35));
}
else
{
评论5