当前位置:首页 > Calculator
package ch14;
import java.awt.BorderLayout; import java.awt.event.*;
import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Timer; import java.util.TimerTask; import java.sql.*; import javax.swing.*;
import java.awt.EventQueue;
import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField;
import javax.swing.border.EmptyBorder; import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JLabel; import java.awt.Font;
import javax.swing.SwingConstants; import java.awt.Color; import java.awt.Frame; import java.awt.Panel;
import java.awt.SystemColor; import javax.swing.UIManager;
import javax.swing.border.LineBorder; import javax.swing.text.JTextComponent;
import ch14.TimeFrame.JLabelTimerTask; import ch14.calculatorJPanel.CommandAction; import ch14.calculatorJPanel.InsertAction;
import java.awt.event.*;
public class Calculator extends JFrame { private JPanel contentPane; private JMenuItem open,exit,about,jtime; private boolean start=true; private boolean mid=true; private boolean flag=false; private boolean timeflag=false; private String lastCommand=\ private String time; double result;
private double num1,num2; private JLabel lblNewLabel; private JLabel lblNewLabel1; private JLabel lblNewLabel2;
private JLabel label; private String DEFAULT_TIME_FORMAT = \ HH:mm:ss\ private int ONE_SECOND = 1000;
JTextArea jta=new JTextArea(4,10); /** * Launch the application. */ public static void main(String[] args) { try { Calculator frame = new Calculator(); ImageIcon imageicon=new ImageIcon(\计算器.jpg\ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } /** * Create the frame. */ public Calculator() { setBackground(Color.LIGHT_GRAY); ImageIcon imageicon=new ImageIcon(\计算器.jpg\ setTitle(\个人计算器\ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 379, 700); contentPane = new JPanel(); contentPane.setBackground(Color.LIGHT_GRAY); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); //setContentPane(contentPane); add(contentPane,BorderLayout.CENTER); contentPane.setLayout(null); jta.setLineWrap(true); jta.setWrapStyleWord(true); JScrollPane pane=new JScrollPane(jta); add(pane,BorderLayout.PAGE_END); JMenuBar jmb=new JMenuBar(); setJMenuBar(jmb); JMenu fileMenu=new JMenu(\文件\ JMenu helpMenu=new JMenu(\帮助\ JMenu timeMenu=new JMenu(\时间\ jmb.add(fileMenu);//将菜单添加到菜单栏上 jmb.add(helpMenu); jmb.add(timeMenu); fileMenu.add(open=new JMenuItem(\打开\ fileMenu.add(exit=new JMenuItem(\退出\ helpMenu.add(about=new JMenuItem(\关于此简易计算器的使用\
timeMenu.add(jtime=new JMenuItem(\系统时间\
InsertAction insert=new InsertAction();
CommandAction command=new CommandAction();
open.addActionListener(command); exit.addActionListener(command); about.addActionListener(command); jtime.addActionListener(command);
JPanel panel = new JPanel();
panel.setBounds(10, 180, 343, 378); contentPane.add(panel);
panel.setLayout(new GridLayout(5, 4, 2, 2));
JButton btnNewButton_15 = new JButton(\btnNewButton_15.addActionListener(command);
btnNewButton_15.setFont(new Font(\楷体\panel.add(btnNewButton_15);
JButton btnNewButton_16 = new JButton(\btnNewButton_16.addActionListener(command);
btnNewButton_16.setFont(new Font(\楷体\panel.add(btnNewButton_16);
JButton btnNewButton_17 = new JButton(\btnNewButton_17.addActionListener(command);
btnNewButton_17.setFont(new Font(\楷体\panel.add(btnNewButton_17);
JButton btnNewButton_18 = new JButton(\一键还原\btnNewButton_18.addActionListener(command);
btnNewButton_18.setFont(new Font(\楷体\panel.add(btnNewButton_18);
JButton btnNewButton_7 = new JButton(\btnNewButton_7.addActionListener(insert);
btnNewButton_7.setFont(new Font(\楷体\panel.add(btnNewButton_7);
JButton btnNewButton_8 = new JButton(\btnNewButton_8.addActionListener(insert);
btnNewButton_8.setFont(new Font(\楷体\panel.add(btnNewButton_8);
JButton btnNewButton_9 = new JButton(\btnNewButton_9.addActionListener(insert);
btnNewButton_9.setFont(new Font(\楷体\panel.add(btnNewButton_9);
JButton btnNewButton_14 = new JButton(\btnNewButton_14.addActionListener(command);
btnNewButton_14.setFont(new Font(\楷体\panel.add(btnNewButton_14);
JButton btnNewButton_4 = new JButton(\btnNewButton_4.addActionListener(insert);
btnNewButton_4.setFont(new Font(\楷体\panel.add(btnNewButton_4);
JButton btnNewButton_5 = new JButton(\btnNewButton_5.addActionListener(insert);
btnNewButton_5.setFont(new Font(\楷体\panel.add(btnNewButton_5);
JButton btnNewButton_6 = new JButton(\btnNewButton_6.addActionListener(insert);
btnNewButton_6.setFont(new Font(\楷体\panel.add(btnNewButton_6);
JButton btnNewButton_13 = new JButton(\btnNewButton_13.addActionListener(command);
btnNewButton_13.setFont(new Font(\楷体\panel.add(btnNewButton_13);
JButton btnNewButton_1 = new JButton(\btnNewButton_1.addActionListener(insert);
btnNewButton_1.setFont(new Font(\楷体\panel.add(btnNewButton_1);
JButton btnNewButton_2 = new JButton(\btnNewButton_2.addActionListener(insert);
btnNewButton_2.setFont(new Font(\楷体\panel.add(btnNewButton_2);
JButton btnNewButton_3 = new JButton(\btnNewButton_3.addActionListener(insert);
btnNewButton_3.setFont(new Font(\楷体\panel.add(btnNewButton_3);
JButton btnNewButton_12 = new JButton(\btnNewButton_12.addActionListener(command);
btnNewButton_12.setFont(new Font(\楷体\panel.add(btnNewButton_12);
JButton btnNewButton_10 = new JButton(\btnNewButton_10.addActionListener(insert);
btnNewButton_10.setFont(new Font(\楷体\panel.add(btnNewButton_10);
JButton btnNewButton_0 = new JButton(\btnNewButton_0.addActionListener(insert);
btnNewButton_0.setFont(new Font(\楷体\panel.add(btnNewButton_0);
共分享92篇相关文档