diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..fceb480 --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..d761300 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + GUICalc + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bin/Calculator$1.class b/bin/Calculator$1.class new file mode 100644 index 0000000..5136969 Binary files /dev/null and b/bin/Calculator$1.class differ diff --git a/bin/Calculator$2.class b/bin/Calculator$2.class new file mode 100644 index 0000000..b17ab32 Binary files /dev/null and b/bin/Calculator$2.class differ diff --git a/bin/Calculator$3.class b/bin/Calculator$3.class new file mode 100644 index 0000000..5112724 Binary files /dev/null and b/bin/Calculator$3.class differ diff --git a/bin/Calculator$4.class b/bin/Calculator$4.class new file mode 100644 index 0000000..1c7ec50 Binary files /dev/null and b/bin/Calculator$4.class differ diff --git a/bin/Calculator$5.class b/bin/Calculator$5.class new file mode 100644 index 0000000..b27ace8 Binary files /dev/null and b/bin/Calculator$5.class differ diff --git a/bin/Calculator$6.class b/bin/Calculator$6.class new file mode 100644 index 0000000..d0775db Binary files /dev/null and b/bin/Calculator$6.class differ diff --git a/bin/Calculator.class b/bin/Calculator.class new file mode 100644 index 0000000..e9ff2b7 Binary files /dev/null and b/bin/Calculator.class differ diff --git a/src/Calculator.java b/src/Calculator.java new file mode 100644 index 0000000..a0e3b7e --- /dev/null +++ b/src/Calculator.java @@ -0,0 +1,170 @@ +import java.awt.EventQueue; + +import javax.swing.JFrame; +import javax.swing.JButton; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import javax.swing.JLabel; +import javax.swing.SwingConstants; +import java.awt.Font; +import javax.swing.JTextField; +import java.awt.Color; + +public class Calculator { + + private JFrame frmCalculator; + + /** + * Launch the application. + */ + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + Calculator window = new Calculator(); + + window.frmCalculator.setVisible(true); + + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + /** + * Create the application. + */ + public Calculator() { + initialize(); + } + + /** + * Initialize the contents of the frame. + */ + private void initialize() { + frmCalculator = new JFrame(); + frmCalculator.getContentPane().setFont(new Font("Tahoma", Font.PLAIN, 18)); + frmCalculator.setTitle("Calculator"); + frmCalculator.setResizable(false); + frmCalculator.setBounds(100, 100, 293, 230); + frmCalculator.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frmCalculator.getContentPane().setLayout(null); + JLabel operator = new JLabel(""); + operator.setFont(new Font("Tahoma", Font.BOLD, 13)); + operator.setHorizontalAlignment(SwingConstants.CENTER); + operator.setBounds(126, 22, 36, 23); + frmCalculator.getContentPane().add(operator); + + JLabel answer = new JLabel(""); + answer.setHorizontalAlignment(SwingConstants.CENTER); + answer.setBounds(48, 161, 187, 23); + frmCalculator.getContentPane().add(answer); + + JTextField dtrpnNumber = new JTextField(); + dtrpnNumber.setFont(new Font("Tahoma", Font.PLAIN, 12)); + dtrpnNumber.setBounds(10, 22, 106, 23); + //Border b = null; + //b.paintBorder(dtrpnNumber, null, 0, 0, 1, 1); + //dtrpnNumber.setBorder(1); + frmCalculator.getContentPane().add(dtrpnNumber); + + JTextField dtrpnNumber_1 = new JTextField(); + dtrpnNumber_1.setBounds(170, 22, 106, 23); + frmCalculator.getContentPane().add(dtrpnNumber_1); + + + + JButton plus = new JButton("+"); + plus.setBackground(Color.LIGHT_GRAY); + plus.setFont(new Font("Tahoma", Font.PLAIN, 18)); + plus.setIcon(null); + plus.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + operator.setText("+"); + } + }); + plus.setBounds(10, 56, 106, 23); + frmCalculator.getContentPane().add(plus); + + JButton minus = new JButton("-"); + minus.setBackground(Color.LIGHT_GRAY); + minus.setFont(new Font("Tahoma", Font.PLAIN, 28)); + minus.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + operator.setText("-"); + } + }); + minus.setBounds(10, 93, 106, 23); + frmCalculator.getContentPane().add(minus); + + JButton multiply = new JButton("x"); + multiply.setBackground(Color.LIGHT_GRAY); + multiply.setFont(new Font("Tahoma", Font.PLAIN, 18)); + multiply.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + operator.setText("X"); + } + }); + multiply.setBounds(170, 56, 106, 23); + frmCalculator.getContentPane().add(multiply); + + JButton division = new JButton("/"); + division.setBackground(Color.LIGHT_GRAY); + division.setFont(new Font("Tahoma", Font.PLAIN, 18)); + division.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + operator.setText("/"); + } + }); + division.setBounds(170, 93, 106, 23); + frmCalculator.getContentPane().add(division); + + JButton equal = new JButton("="); + equal.setBackground(new Color(192, 192, 192)); + equal.setFont(new Font("Tahoma", Font.PLAIN, 18)); + equal.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if(dtrpnNumber.getText().isEmpty()) + { + dtrpnNumber.setText("0"); + } + if(dtrpnNumber_1.getText().isEmpty()) + { + dtrpnNumber_1.setText("0"); + } + Float ans = new Float(0); + if(operator.getText() == "+") + { + ans= Float.valueOf(dtrpnNumber.getText())+Float.valueOf(dtrpnNumber_1.getText()); + answer.setText("Answer = "+ans.toString()); + } + else + if(operator.getText() == "-") + { + ans= Float.valueOf(dtrpnNumber.getText())-Float.valueOf(dtrpnNumber_1.getText()); + answer.setText("Answer = "+ans.toString()); + } + else + if(operator.getText() == "X") + { + ans= Float.valueOf(dtrpnNumber.getText())*Float.valueOf(dtrpnNumber_1.getText()); + answer.setText("Answer = "+ans.toString()); + } + else + if(operator.getText() == "/") + { + ans= Float.valueOf(dtrpnNumber.getText())/Float.valueOf(dtrpnNumber_1.getText()); + answer.setText("Answer = "+ans.toString()); + } + else + answer.setText("No Operator is Selected!!!"); + + } + }); + equal.setBounds(114, 127, 61, 23); + frmCalculator.getContentPane().add(equal); + + + } +}