└── MainClass.java /MainClass.java: -------------------------------------------------------------------------------- 1 | package UI; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.EventQueue; 5 | 6 | import javax.swing.JFrame; 7 | import javax.swing.JOptionPane; 8 | import javax.swing.JPanel; 9 | import javax.swing.border.EmptyBorder; 10 | import javax.swing.JTextField; 11 | import javax.swing.JButton; 12 | import java.awt.event.ActionListener; 13 | import java.awt.event.ActionEvent; 14 | import javax.swing.JLabel; 15 | import java.awt.Toolkit; 16 | import java.awt.Color; 17 | import javax.swing.SwingConstants; 18 | import java.awt.Font; 19 | 20 | public class MainClass extends JFrame { 21 | 22 | private JPanel contentPane; 23 | private JTextField textField; 24 | double FIRSTNUM; 25 | double SECONDNUM; 26 | double RESULT; 27 | String ANSWER; 28 | String OPERATION; 29 | 30 | /** 31 | * Launch the application. 32 | */ 33 | public static void main(String[] args) { 34 | EventQueue.invokeLater(new Runnable() { 35 | public void run() { 36 | try { 37 | MainClass frame = new MainClass(); 38 | frame.setVisible(true); 39 | } catch (Exception e) { 40 | e.printStackTrace(); 41 | } 42 | } 43 | }); 44 | } 45 | public MainClass() { 46 | setResizable(false); 47 | setTitle("HANCIE CALCULATOR"); 48 | setBackground(Color.WHITE); 49 | setIconImage(Toolkit.getDefaultToolkit().getImage("nitesh.png")); 50 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 51 | setLocationRelativeTo(null); 52 | setSize(281,480); 53 | setVisible(true); 54 | 55 | contentPane = new JPanel(); 56 | contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); 57 | contentPane.setLayout(new BorderLayout(0, 0)); 58 | setContentPane(contentPane); 59 | 60 | JPanel CONTAINER = new JPanel(); 61 | CONTAINER.setBackground(Color.WHITE); 62 | contentPane.add(CONTAINER, BorderLayout.CENTER); 63 | CONTAINER.setLayout(null); 64 | 65 | textField = new JTextField(); 66 | textField.setFont(new Font("Tahoma", Font.PLAIN, 14)); 67 | textField.setHorizontalAlignment(SwingConstants.RIGHT); 68 | textField.setBounds(10, 11, 234, 47); 69 | CONTAINER.add(textField); 70 | textField.setColumns(10); 71 | 72 | JButton ONE = new JButton("1"); 73 | ONE.addActionListener(new ActionListener() { 74 | public void actionPerformed(ActionEvent arg0) { 75 | 76 | String ENTERVALUE = textField.getText() + ONE.getText(); 77 | textField.setText(ENTERVALUE); 78 | 79 | } 80 | }); 81 | ONE.setBackground(Color.WHITE); 82 | ONE.setBounds(10, 95, 50, 47); 83 | CONTAINER.add(ONE); 84 | 85 | JButton TWO = new JButton("2"); 86 | TWO.addActionListener(new ActionListener() { 87 | public void actionPerformed(ActionEvent arg0) { 88 | String ENTERVALUE = textField.getText() + TWO.getText(); 89 | textField.setText(ENTERVALUE); 90 | 91 | } 92 | }); 93 | TWO.setBackground(Color.WHITE); 94 | TWO.setBounds(70, 95, 50, 47); 95 | CONTAINER.add(TWO); 96 | 97 | JButton THREE = new JButton("3"); 98 | THREE.setBackground(Color.WHITE); 99 | THREE.addActionListener(new ActionListener() { 100 | public void actionPerformed(ActionEvent arg0) { 101 | String ENTERVALUE = textField.getText() + THREE.getText(); 102 | textField.setText(ENTERVALUE); 103 | 104 | } 105 | }); 106 | THREE.setBounds(130, 95, 50, 47); 107 | CONTAINER.add(THREE); 108 | 109 | JButton FOUR = new JButton("4"); 110 | FOUR.addActionListener(new ActionListener() { 111 | public void actionPerformed(ActionEvent e) { 112 | 113 | String ENTERVALUE = textField.getText() + FOUR.getText(); 114 | textField.setText(ENTERVALUE); 115 | 116 | } 117 | }); 118 | FOUR.setBackground(Color.WHITE); 119 | FOUR.setBounds(194, 95, 50, 47); 120 | CONTAINER.add(FOUR); 121 | 122 | JButton FIVE = new JButton("5"); 123 | FIVE.addActionListener(new ActionListener() { 124 | public void actionPerformed(ActionEvent e) { 125 | 126 | String ENTERVALUE = textField.getText() + FIVE.getText(); 127 | textField.setText(ENTERVALUE); 128 | 129 | } 130 | }); 131 | FIVE.setBackground(Color.WHITE); 132 | FIVE.setBounds(10, 150, 50, 47); 133 | CONTAINER.add(FIVE); 134 | 135 | JButton SIX = new JButton("6"); 136 | SIX.setBackground(Color.WHITE); 137 | SIX.addActionListener(new ActionListener() { 138 | public void actionPerformed(ActionEvent arg0) { 139 | 140 | String ENTERVALUE = textField.getText() + SIX.getText(); 141 | textField.setText(ENTERVALUE); 142 | 143 | } 144 | }); 145 | SIX.setBounds(70, 150, 50, 47); 146 | CONTAINER.add(SIX); 147 | 148 | JButton SEVEN = new JButton("7"); 149 | SEVEN.addActionListener(new ActionListener() { 150 | public void actionPerformed(ActionEvent e) { 151 | 152 | String ENTERVALUE = textField.getText() + SEVEN.getText(); 153 | textField.setText(ENTERVALUE); 154 | 155 | } 156 | }); 157 | SEVEN.setBackground(Color.WHITE); 158 | SEVEN.setBounds(130, 150, 50, 47); 159 | CONTAINER.add(SEVEN); 160 | 161 | JButton EIGHT = new JButton("8"); 162 | EIGHT.addActionListener(new ActionListener() { 163 | public void actionPerformed(ActionEvent e) { 164 | 165 | String ENTERVALUE = textField.getText() + EIGHT.getText(); 166 | textField.setText(ENTERVALUE); 167 | 168 | } 169 | }); 170 | EIGHT.setBackground(Color.WHITE); 171 | EIGHT.setBounds(194, 150, 50, 47); 172 | CONTAINER.add(EIGHT); 173 | 174 | JButton NINE = new JButton("9"); 175 | NINE.addActionListener(new ActionListener() { 176 | public void actionPerformed(ActionEvent e) { 177 | 178 | String ENTERVALUE = textField.getText() + NINE.getText(); 179 | textField.setText(ENTERVALUE); 180 | 181 | } 182 | }); 183 | NINE.setBackground(Color.WHITE); 184 | NINE.setBounds(10, 208, 50, 47); 185 | CONTAINER.add(NINE); 186 | 187 | JButton SUM = new JButton("+"); 188 | SUM.addActionListener(new ActionListener() { 189 | public void actionPerformed(ActionEvent e) { 190 | if (textField.getText().equals("")) { 191 | JOptionPane.showMessageDialog(null, "SORRY!ENTER YOUR FIRST NUMBER"); 192 | } else { 193 | FIRSTNUM = Double.parseDouble(textField.getText()); 194 | textField.setText(""); 195 | OPERATION = "+"; 196 | } 197 | } 198 | }); 199 | SUM.setBackground(Color.WHITE); 200 | SUM.setBounds(70, 208, 50, 47); 201 | CONTAINER.add(SUM); 202 | 203 | JButton MINUS = new JButton("-"); 204 | MINUS.addActionListener(new ActionListener() { 205 | public void actionPerformed(ActionEvent e) { 206 | if (textField.getText().equals("")) { 207 | JOptionPane.showMessageDialog(null, "SORRY!ENTER YOUR FIRST NUMBER"); 208 | 209 | } else { 210 | FIRSTNUM = Double.parseDouble(textField.getText()); 211 | textField.setText(""); 212 | OPERATION = "-"; 213 | } 214 | } 215 | }); 216 | MINUS.setBackground(Color.WHITE); 217 | MINUS.setBounds(130, 208, 50, 47); 218 | CONTAINER.add(MINUS); 219 | 220 | JButton MULTIPLY = new JButton("*"); 221 | MULTIPLY.addActionListener(new ActionListener() { 222 | public void actionPerformed(ActionEvent e) { 223 | if (textField.getText().equals("")) { 224 | JOptionPane.showMessageDialog(null, "SORRY!ENTER YOUR FIRST NUMBER"); 225 | 226 | } else { 227 | FIRSTNUM = Double.parseDouble(textField.getText()); 228 | textField.setText(""); 229 | OPERATION = "*"; 230 | } 231 | } 232 | }); 233 | MULTIPLY.setBackground(Color.WHITE); 234 | MULTIPLY.setBounds(190, 208, 50, 47); 235 | CONTAINER.add(MULTIPLY); 236 | 237 | JButton DIVISION = new JButton("/"); 238 | DIVISION.addActionListener(new ActionListener() { 239 | public void actionPerformed(ActionEvent e) { 240 | if (textField.getText().equals("")) { 241 | JOptionPane.showMessageDialog(null, "SORRY!ENTER YOUR FIRST NUMBER"); 242 | 243 | } else { 244 | FIRSTNUM = Double.parseDouble(textField.getText()); 245 | textField.setText(""); 246 | OPERATION = "/"; 247 | } 248 | } 249 | }); 250 | DIVISION.setBackground(Color.WHITE); 251 | DIVISION.setBounds(10, 266, 50, 47); 252 | CONTAINER.add(DIVISION); 253 | 254 | JButton CLEAR = new JButton("C"); 255 | CLEAR.addActionListener(new ActionListener() { 256 | public void actionPerformed(ActionEvent e) { 257 | textField.setText(""); 258 | } 259 | }); 260 | CLEAR.setBackground(Color.WHITE); 261 | CLEAR.setBounds(70, 266, 50, 47); 262 | CONTAINER.add(CLEAR); 263 | 264 | JButton EQUAL = new JButton("="); 265 | EQUAL.addActionListener(new ActionListener() { 266 | 267 | public void actionPerformed(ActionEvent e) { 268 | 269 | if (OPERATION == "+") { 270 | SECONDNUM = Double.parseDouble(textField.getText()); 271 | RESULT = FIRSTNUM + SECONDNUM; 272 | ANSWER = ANSWER.valueOf(RESULT); 273 | textField.setText(ANSWER); 274 | } 275 | 276 | if (OPERATION == "-") { 277 | SECONDNUM = Double.parseDouble(textField.getText()); 278 | RESULT = FIRSTNUM - SECONDNUM; 279 | ANSWER = ANSWER.valueOf(RESULT); 280 | textField.setText(ANSWER); 281 | } 282 | 283 | if (OPERATION == "*") { 284 | SECONDNUM = Double.parseDouble(textField.getText()); 285 | RESULT = FIRSTNUM * SECONDNUM; 286 | ANSWER = ANSWER.valueOf(RESULT); 287 | textField.setText(ANSWER); 288 | } 289 | 290 | if (OPERATION == "/") { 291 | SECONDNUM = Double.parseDouble(textField.getText()); 292 | RESULT = FIRSTNUM / SECONDNUM; 293 | ANSWER = ANSWER.valueOf(RESULT); 294 | textField.setText(ANSWER); 295 | } 296 | 297 | } 298 | }); 299 | EQUAL.setBackground(Color.WHITE); 300 | EQUAL.setBounds(190, 266, 50, 47); 301 | CONTAINER.add(EQUAL); 302 | 303 | JLabel ABOUT = new JLabel("DEVELOPED BY :"); 304 | ABOUT.setBounds(92, 334, 100, 25); 305 | CONTAINER.add(ABOUT); 306 | 307 | JLabel ABOUTT = new JLabel("HANCIE PHAGO"); 308 | ABOUTT.setBounds(92, 357, 150, 17); 309 | CONTAINER.add(ABOUTT); 310 | 311 | JButton button = new JButton("."); 312 | button.addActionListener(new ActionListener() { 313 | public void actionPerformed(ActionEvent e) { 314 | String ENTERVALUE = textField.getText() + button.getText(); 315 | textField.setText(ENTERVALUE); 316 | } 317 | }); 318 | button.setBackground(Color.WHITE); 319 | button.setBounds(130, 266, 50, 47); 320 | CONTAINER.add(button); 321 | } 322 | } 323 | --------------------------------------------------------------------------------