java简单计算器

java简单计算器

package dianzijisuanqi;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.plaf.nimbus.NimbusLookAndFeel;

public class MainFrame extends JFrame implements ActionListener{

	private JPanel contentPane;
	private static final String[] KEYS={
		"CE","C","BACK","%",
		"7","8","9","/",
		"4","5","6","*",
		"1","2","3","+",
		"0",".","=","-"
	};
	private JButton[] buttons=new JButton [KEYS.length];
	private boolean firstNum=true;
	private double result;
	private String operator="=";
	private boolean operatorFlag=false;
	private JTextField resultText;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					UIManager.setLookAndFeel(new NimbusLookAndFeel());
					MainFrame frame = new MainFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MainFrame() {
		super();
	
		setResizable(false);
		setTitle("简易计算器hwn");
		getContentPane().setLayout(new BorderLayout());
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(500, 50, 280, 230);
		resultText=new JTextField();
		resultText.setHorizontalAlignment(SwingConstants.RIGHT);
		resultText.setText("0");
		resultText.setEditable(false);
		getContentPane().add(resultText,BorderLayout.NORTH);
		JPanel calcPanel=new JPanel();
		getContentPane().add(calcPanel,BorderLayout.CENTER);
		final GridLayout gridLayout=new GridLayout(5,4,3,3);
		calcPanel.setLayout(gridLayout);
		for(int i = 0; i 


你可能感兴趣的:(java,development)