//CalcGUI.java package Calculator; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.*; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.Rectangle; import java.awt.event.KeyEvent; import java.awt.event.KeyAdapter; public class CalcGUI extends JFrame { JPanel contentPane; JMenuBar jMenuBar1 = new JMenuBar(); JMenu menuFile = new JMenu(); JMenuItem menuQuit = new JMenuItem(); JTextField solution = new JTextField(); JButton num1 = new JButton(); JButton num2 = new JButton(); JButton num3 = new JButton(); JButton num5 = new JButton(); JButton num4 = new JButton(); JButton num6 = new JButton(); JButton num8 = new JButton(); JButton num9 = new JButton(); JButton num7 = new JButton(); JButton num0 = new JButton(); JButton minus = new JButton(); JButton multiply = new JButton(); JButton add = new JButton(); JButton divide = new JButton(); JButton equals = new JButton(); JButton clear = new JButton(); int n1 = 1; int n2 = 2; int n3 = 3; int n4 = 4; int n5 = 5; int n6 = 6; int n7 = 7; int n8 = 8; int n9 = 9; int n0 = 0; String temp = ""; public CalcGUI() { try { setDefaultCloseOperation(EXIT_ON_CLOSE); jbInit(); } catch (Exception exception) { exception.printStackTrace(); } } private void jbInit() throws Exception { contentPane = (JPanel) getContentPane(); this.setJMenuBar(jMenuBar1); setSize(new Dimension(268, 237)); setTitle("Calculator"); contentPane.setLayout(null); menuQuit.setText("Quit"); menuQuit.addActionListener(new CalcGUI_jMenuItem1_actionAdapter(this)); menuFile.setText("File"); solution.setForeground(Color.black); solution.setDisabledTextColor(Color.black); solution.setBackground(Color.white); solution.setEditable(false); solution.setBounds(new Rectangle(9, 13, 179, 19)); num1.setBounds(new Rectangle(9, 51, 51, 23)); num1.setText("1"); num1.addKeyListener(new CalcGUI_num1_keyAdapter(this)); num1.addActionListener(new CalcGUI_num1_actionAdapter(this)); num2.setBounds(new Rectangle(73, 51, 51, 23)); num2.setText("2"); num2.addActionListener(new CalcGUI_num2_actionAdapter(this)); num3.setBounds(new Rectangle(137, 51, 51, 23)); num3.setText("3"); num3.addActionListener(new CalcGUI_num3_actionAdapter(this)); num5.setBounds(new Rectangle(73, 83, 51, 23)); num5.setText("5"); num5.addActionListener(new CalcGUI_num5_actionAdapter(this)); num4.setBounds(new Rectangle(9, 83, 51, 23)); num4.setText("4"); num4.addActionListener(new CalcGUI_num4_actionAdapter(this)); num6.setBounds(new Rectangle(137, 83, 51, 23)); num6.setText("6"); num6.addActionListener(new CalcGUI_num6_actionAdapter(this)); num8.setBounds(new Rectangle(73, 115, 51, 23)); num8.setText("8"); num8.addActionListener(new CalcGUI_num8_actionAdapter(this)); num9.setBounds(new Rectangle(137, 115, 51, 23)); num9.setText("9"); num9.addActionListener(new CalcGUI_num9_actionAdapter(this)); num7.setBounds(new Rectangle(9, 115, 51, 23)); num7.setToolTipText(""); num7.setText("7"); num7.addActionListener(new CalcGUI_num7_actionAdapter(this)); num0.setBounds(new Rectangle(73, 147, 51, 23)); num0.setText("0"); num0.addActionListener(new CalcGUI_num0_actionAdapter(this)); minus.setBounds(new Rectangle(200, 83, 51, 23)); minus.setText("-"); multiply.setBounds(new Rectangle(200, 115, 51, 23)); multiply.setText("*"); add.setBounds(new Rectangle(200, 51, 51, 23)); add.setText("+"); add.addActionListener(new CalcGUI_jButton3_actionAdapter(this)); divide.setBounds(new Rectangle(200, 147, 51, 23)); divide.setToolTipText(""); divide.setText("/"); equals.setBounds(new Rectangle(200, 11, 51, 23)); equals.setText("="); clear.setBounds(new Rectangle(137, 147, 51, 23)); clear.setText("C"); clear.addActionListener(new CalcGUI_clear_actionAdapter(this)); jMenuBar1.add(menuFile); menuFile.add(menuQuit); contentPane.add(solution); contentPane.add(num1); contentPane.add(num2); contentPane.add(num3); contentPane.add(num4); contentPane.add(num5); contentPane.add(num6); contentPane.add(num7); contentPane.add(num8); contentPane.add(num9); contentPane.add(num0); contentPane.add(add); contentPane.add(minus); contentPane.add(multiply); contentPane.add(divide); contentPane.add(equals); contentPane.add(clear); } } public void menuQuit_actionPerformed(ActionEvent e) { System.exit(0); } public void num1_actionPerformed(ActionEvent e) { temp = temp + n1; solution.setText(temp); } public void num2_actionPerformed(ActionEvent e) { temp = temp + n2; solution.setText(temp); } public void num3_actionPerformed(ActionEvent e) { temp = temp + n3; solution.setText(temp); } public void num4_actionPerformed(ActionEvent e) { temp = temp + n4; solution.setText(temp); } public void num5_actionPerformed(ActionEvent e) { temp = temp + n5; solution.setText(temp); } public void num6_actionPerformed(ActionEvent e) { temp = temp + n6; solution.setText(temp); } public void num7_actionPerformed(ActionEvent e) { temp = temp + n7; solution.setText(temp); } public void num8_actionPerformed(ActionEvent e) { temp = temp + n8; solution.setText(temp); } public void num9_actionPerformed(ActionEvent e) { temp = temp + n9; solution.setText(temp); } public void num0_actionPerformed(ActionEvent e) { temp = temp + n0; solution.setText(temp); } public void clear_actionPerformed(ActionEvent e) { temp = ""; solution.setText(temp); }