文档详情

java实现的计算器窗口生成器.doc

发布:2017-07-04约12.57万字共13页下载文档
文本预览下载声明
import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import java.awt.GridBagLayout; import javax.swing.JButton; import java.awt.GridBagConstraints; import java.awt.Insets; import javax.swing.JTextField; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; /*** * 简易计算器,只能完成一次运算,不能连续输入,连续计算 * @author admin * */ public class CalcuatorSimple extends JFrame { private JPanel contentPane; private JTextField textField; private double operand1;//操作数 private double operand2; private String operator;//运算符 private String express; //表达式 /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { CalcuatorSimple frame = new CalcuatorSimple(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public CalcuatorSimple() { setResizable(false); setTitle(\u8BA1\u7B97\u5668); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 271, 191); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); GridBagLayout gbl_contentPane = new GridBagLayout(); gbl_contentPane.columnWidths = new int[]{0, 0, 0, 0, 0, 0}; gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0, 0, 0}; gbl_contentPane.columnWeights = new double[]{1.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; gbl_contentPane.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; contentPane.setLayout(gbl_contentPane); textField = new JTextField(); GridBagConstraints gbc_textField = new GridBagConstraints(); gbc_textField.gridwidth = 5; gbc_textField.insets = new Insets(0, 0, 5, 0); gbc_textField.fill = GridBagConstraints.HORIZONTAL; gbc_textField.gridx = 0; gbc_textField.gridy = 0; contentPane.add(textField, gbc
显示全部
相似文档