📄 frame1.java~157~
字号:
package calculator;import java.io.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border.*;import com.borland.jbcl.layout.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author unascribed * @version 1.0 */public class Frame1 extends JFrame { private JPanel contentPane; private JMenuBar jMenuBar1 = new JMenuBar(); private JMenu jMenuFile = new JMenu(); private JMenuItem jMenuFileExit = new JMenuItem(); private JMenu jMenuHelp = new JMenu(); private JPanel skin1 = new JPanel(); private CardLayout cardLayout2 = new CardLayout(); private JPanel skin2 = new JPanel(); private JPanel jPanel1 = new JPanel(); private JPanel jPanel2 = new JPanel(); private JPanel jPanel3 = new JPanel(); private BorderLayout borderLayout1 = new BorderLayout(); private JTextField result1 = new JTextField(); private JButton qingling11 = new JButton(); private GridLayout gridLayout1 = new GridLayout(); private JButton jb17 = new JButton(); private JButton jb1chu = new JButton(); private JButton jb1fu = new JButton(); private JButton jb1deng = new JButton(); private JButton jb1dian = new JButton(); private JButton jb10 = new JButton(); private JButton jb1cheng = new JButton(); private JButton jb1back = new JButton(); private JButton jb13 = new JButton(); private JButton jb12 = new JButton(); private JButton jb11 = new JButton(); private JButton jb1jian = new JButton(); private JButton jb1cos = new JButton(); private JButton jb16 = new JButton(); private JButton jb15 = new JButton(); private JButton jb14 = new JButton(); private JButton jb1jia = new JButton(); private JButton jb1sin = new JButton(); private JButton jb19 = new JButton(); private JButton jb18 = new JButton(); private JTextField status1 = new JTextField(); private JLabel jLabel1 = new JLabel(); private Border border1; private JPanel jPanel4 = new JPanel(); private JPanel jPanel5 = new JPanel(); private JPanel jPanel6 = new JPanel(); private GridLayout gridLayout2 = new GridLayout(); private JTextField result2 = new JTextField(); private JButton qingling2 = new JButton(); private JButton jb27 = new JButton(); private JButton jb2chu = new JButton(); private JButton jb2fu = new JButton(); private JButton jb2deng = new JButton(); private JButton jb2dian = new JButton(); private JButton jb20 = new JButton(); private JButton jb2cheng = new JButton(); private JButton jb2back = new JButton(); private JButton jb23 = new JButton(); private JButton jb22 = new JButton(); private JButton jb21 = new JButton(); private JButton jb2jian = new JButton(); private JButton jb2cos = new JButton(); private JButton jb26 = new JButton(); private JButton jb25 = new JButton(); private JButton jb24 = new JButton(); private JButton jb2jia = new JButton(); private JButton jb2sin = new JButton(); private JButton jb29 = new JButton(); private JButton jb28 = new JButton(); private BorderLayout borderLayout2 = new BorderLayout(); private JLabel jLabel2 = new JLabel(); private JTextField status2 = new JTextField(); private Border border2; //定义变量startnum double startnum; //定义显示标记 boolean isResult=false; //定义加标记 boolean flagAdd=false; //定义减标记 boolean flagSub=false; //定义乘标记 boolean flagMul=false; //定义除标记 boolean flagDiv=false; //定义变量endnum double endnum; String str=null; private JMenu jMenu1 = new JMenu(); private JMenuItem jMenuItem1 = new JMenuItem(); private JMenuItem jMenuItem2 = new JMenuItem(); private JMenu jMenu2 = new JMenu(); private JMenuItem jMenuItem3 = new JMenuItem(); private JPanel skin3 = new JPanel(); private JPanel jPanel7 = new JPanel(); private JPanel jPanel8 = new JPanel(); private BorderLayout borderLayout4 = new BorderLayout(); private GridLayout gridLayout3 = new GridLayout(); private JTextField result3 = new JTextField(); private JButton jButton1 = new JButton(); private Button jb32 = new Button(); private Button jb3cheng = new Button(); private Button jb37 = new Button(); private Button jb33 = new Button(); private Button jb38 = new Button(); private Button jb3fu = new Button(); private Button jb39 = new Button(); private Button button5 = new Button(); private Button jb30 = new Button(); private Button jb34 = new Button(); private Button jb3dian = new Button(); private Button jb3cos = new Button(); private Button jb3deng = new Button(); private Button jb3jia = new Button(); private Button jb3sin = new Button(); private Button jb35 = new Button(); private Button jb36 = new Button(); private Button jb3jian = new Button(); private Button jb31 = new Button(); private Button jb3c = new Button(); private JButton jb3back = new JButton(); private FlowLayout flowLayout1 = new FlowLayout(); private JPanel jPanel9 = new JPanel(); private JLabel status3 = new JLabel(); //Construct the frame public Frame1() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { //setIconImage(Toolkit.getDefaultToolkit().createImage //(Frame1.class.getResource("[Your Icon]"))); contentPane = (JPanel) this.getContentPane(); border1 = BorderFactory.createEmptyBorder(); border2 = BorderFactory.createEmptyBorder(); contentPane.setLayout(cardLayout2); this.setResizable(false); this.setSize(new Dimension(431, 350)); this.setTitle("计算器"); jMenuFile.setText("文件"); jMenuFileExit.setText("退出"); jMenuFileExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jMenuFileExit_actionPerformed(e); } }); jMenuHelp.setText("视图"); skin1.setLayout(borderLayout1); result1.setBackground(Color.white); result1.setFont(new java.awt.Font("SansSerif", 1, 20)); result1.setEditable(false); result1.setColumns(18); result1.setHorizontalAlignment(SwingConstants.RIGHT); result1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { result1_actionPerformed(e); } }); qingling11.setBackground(Color.black); qingling11.setFont(new java.awt.Font("Dialog", 1, 15)); qingling11.setForeground(Color.red); qingling11.setActionCommand("qingling11"); qingling11.setText("清零"); qingling11.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { qingling11_actionPerformed(e); } }); jPanel2.setLayout(gridLayout1); gridLayout1.setColumns(5); gridLayout1.setHgap(5); gridLayout1.setRows(4); gridLayout1.setVgap(5); jb17.setBackground(Color.black); jb17.setFont(new java.awt.Font("Dialog", 1, 30)); jb17.setForeground(Color.white); jb17.setText("7"); jb17.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb17_actionPerformed(e); } }); jb1chu.setBackground(Color.black); jb1chu.setFont(new java.awt.Font("Dialog", 1, 25)); jb1chu.setForeground(Color.red); jb1chu.setText("/"); jb1chu.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb1chu_actionPerformed(e); } }); jb1fu.setBackground(Color.black); jb1fu.setFont(new java.awt.Font("Dialog", 1, 25)); jb1fu.setForeground(Color.red); jb1fu.setText("+/-"); jb1fu.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb1fu_actionPerformed(e); } }); jb1deng.setBackground(Color.black); jb1deng.setFont(new java.awt.Font("Dialog", 1, 30)); jb1deng.setForeground(Color.white); jb1deng.setText("="); jb1deng.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb1deng_actionPerformed(e); } }); jb1dian.setBackground(Color.black); jb1dian.setFont(new java.awt.Font("Dialog", 1, 30)); jb1dian.setForeground(Color.white); jb1dian.setText("."); jb1dian.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb1dian_actionPerformed(e); } }); jb10.setBackground(Color.black); jb10.setFont(new java.awt.Font("Dialog", 1, 30)); jb10.setForeground(Color.white); jb10.setText("0"); jb10.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb10_actionPerformed(e); } }); jb1cheng.setBackground(Color.black); jb1cheng.setFont(new java.awt.Font("Dialog", 1, 25)); jb1cheng.setForeground(Color.red); jb1cheng.setText("*"); jb1cheng.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb1cheng_actionPerformed(e); } }); jb1back.setBackground(Color.black); jb1back.setFont(new java.awt.Font("Dialog", 1, 13)); jb1back.setForeground(Color.red); jb1back.setText("BACK"); jb1back.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb1back_actionPerformed(e); } }); jb13.setBackground(Color.black); jb13.setFont(new java.awt.Font("Dialog", 1, 30)); jb13.setForeground(Color.white); jb13.setText("3"); jb13.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb13_actionPerformed(e); } }); jb12.setBackground(Color.black); jb12.setFont(new java.awt.Font("Dialog", 1, 30)); jb12.setForeground(Color.white); jb12.setText("2"); jb12.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb12_actionPerformed(e); } }); jb11.setBackground(Color.black); jb11.setFont(new java.awt.Font("Dialog", 1, 30)); jb11.setForeground(Color.white); jb11.setText("1"); jb11.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb11_actionPerformed(e); } }); jb1jian.setBackground(Color.black); jb1jian.setFont(new java.awt.Font("Dialog", 1, 25)); jb1jian.setForeground(Color.red); jb1jian.setText("-"); jb1jian.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb1jian_actionPerformed(e); } }); jb1cos.setBackground(Color.black); jb1cos.setFont(new java.awt.Font("Dialog", 1, 20)); jb1cos.setForeground(Color.red); jb1cos.setText("cos"); jb1cos.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb1cos_actionPerformed(e); } }); jb16.setBackground(Color.black); jb16.setFont(new java.awt.Font("Dialog", 1, 30)); jb16.setForeground(Color.white); jb16.setText("6"); jb16.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb16_actionPerformed(e); } }); jb15.setBackground(Color.black); jb15.setFont(new java.awt.Font("Dialog", 1, 30)); jb15.setForeground(Color.white); jb15.setText("5"); jb15.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb15_actionPerformed(e); } }); jb14.setBackground(Color.black); jb14.setFont(new java.awt.Font("Dialog", 1, 30)); jb14.setForeground(Color.white); jb14.setText("4"); jb14.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb14_actionPerformed(e); } }); jb1jia.setBackground(Color.black); jb1jia.setFont(new java.awt.Font("Dialog", 1, 25)); jb1jia.setForeground(Color.red); jb1jia.setText("+"); jb1jia.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb1jia_actionPerformed(e); } }); jb1sin.setBackground(Color.black); jb1sin.setFont(new java.awt.Font("Dialog", 1, 20)); jb1sin.setForeground(Color.red); jb1sin.setText("sin"); jb1sin.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb1sin_actionPerformed(e); } }); jb19.setBackground(Color.black); jb19.setFont(new java.awt.Font("Dialog", 1, 30)); jb19.setForeground(Color.white); jb19.setText("9"); jb19.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb19_actionPerformed(e); } }); jb18.setBackground(Color.black); jb18.setFont(new java.awt.Font("Dialog", 1, 30)); jb18.setForeground(Color.white); jb18.setText("8"); jb18.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb18_actionPerformed(e); } }); status1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { status1_actionPerformed(e); } }); status1.setBackground(Color.lightGray); status1.setFont(new java.awt.Font("SansSerif", 1, 15)); status1.setForeground(Color.blue); status1.setBorder(border1); status1.setDisabledTextColor(Color.lightGray); status1.setEditable(false); status1.setColumns(25); borderLayout1.setVgap(10); jPanel5.setLayout(gridLayout2); gridLayout2.setColumns(5); gridLayout2.setHgap(5); gridLayout2.setRows(4); gridLayout2.setVgap(5); result2.setBackground(Color.white); result2.setFont(new java.awt.Font("SansSerif", 1, 20)); result2.setToolTipText("请输入字符!"); result2.setEditable(false); result2.setColumns(18); result2.setHorizontalAlignment(SwingConstants.RIGHT); qingling2.setFont(new java.awt.Font("Dialog", 1, 15)); qingling2.setForeground(UIManager.getColor("ProgressBar.selectionBackground")); qingling2.setText("清零"); qingling2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { qingling2_actionPerformed(e); } }); jb27.setFont(new java.awt.Font("Dialog", 1, 30)); jb27.setForeground(UIManager.getColor("InternalFrame.activeTitleBackground")); jb27.setHorizontalTextPosition(SwingConstants.CENTER); jb27.setIcon(new ImageIcon(new java.net.URL("file:///C:/Calculator/pic/KEY.GIF"))); jb27.setText("7"); jb27.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb27_actionPerformed(e); } }); jb2chu.setFont(new java.awt.Font("Dialog", 1, 25)); jb2chu.setForeground(UIManager.getColor("InternalFrame.activeTitleBackground")); jb2chu.setHorizontalTextPosition(SwingConstants.CENTER); jb2chu.setIcon(new ImageIcon(new java.net.URL("file:///C:/Calculator/pic/KEY.GIF"))); jb2chu.setText("/"); jb2chu.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb2chu_actionPerformed(e); } }); jb2fu.setFont(new java.awt.Font("Dialog", 1, 20)); jb2fu.setForeground(UIManager.getColor("InternalFrame.activeTitleBackground")); jb2fu.setHorizontalTextPosition(SwingConstants.CENTER); jb2fu.setIcon(new ImageIcon(new java.net.URL("file:///C:/Calculator/pic/KEY.GIF"))); jb2fu.setText("+/-"); jb2fu.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb2fu_actionPerformed(e); } }); jb2deng.setFont(new java.awt.Font("Dialog", 1, 30)); jb2deng.setForeground(UIManager.getColor("InternalFrame.activeTitleBackground")); jb2deng.setHorizontalTextPosition(SwingConstants.CENTER); jb2deng.setIcon(new ImageIcon(new java.net.URL("file:///C:/Calculator/pic/KEY.GIF"))); jb2deng.setText("="); jb2deng.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb2deng_actionPerformed(e); } }); jb2dian.setFont(new java.awt.Font("Dialog", 1, 30)); jb2dian.setForeground(UIManager.getColor("InternalFrame.activeTitleBackground")); jb2dian.setHorizontalTextPosition(SwingConstants.CENTER); jb2dian.setIcon(new ImageIcon(new java.net.URL("file:///C:/Calculator/pic/KEY.GIF"))); jb2dian.setText("."); jb2dian.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb2dian_actionPerformed(e); } }); jb20.setFont(new java.awt.Font("Dialog", 1, 30)); jb20.setForeground(UIManager.getColor("InternalFrame.activeTitleBackground")); jb20.setHorizontalTextPosition(SwingConstants.CENTER); jb20.setIcon(new ImageIcon(new java.net.URL("file:///C:/Calculator/pic/KEY.GIF"))); jb20.setText("0"); jb20.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb20_actionPerformed(e); } }); jb2cheng.setFont(new java.awt.Font("Dialog", 1, 25)); jb2cheng.setForeground(UIManager.getColor("InternalFrame.activeTitleBackground")); jb2cheng.setHorizontalTextPosition(SwingConstants.CENTER); jb2cheng.setIcon(new ImageIcon(new java.net.URL("file:///C:/Calculator/pic/KEY.GIF"))); jb2cheng.setText("*"); jb2cheng.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jb2cheng_actionPerformed(e); } }); jb2back.setFont(new java.awt.Font("Dialog", 1, 13)); jb2back.setForeground(UIManager.getColor("InternalFrame.activeTitleBackground")); jb2back.setHorizontalTextPosition(SwingConstants.CENTER); jb2back.setIcon(new ImageIcon(new java.net.URL("file:///C:/Calculator/pic/KEY.GIF")));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -