Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.49 KB | None | 0 0
  1. package Calculator;
  2.  
  3. import java.awt.EventQueue;
  4.  
  5. import javax.swing.JFrame;
  6. import javax.swing.JMenuBar;
  7. import javax.swing.JMenu;
  8. import javax.swing.JMenuItem;
  9. import javax.swing.JTextField;
  10. import java.awt.event.ActionListener;
  11. import java.awt.event.ActionEvent;
  12. import javax.swing.JButton;
  13. import java.awt.Font;
  14. import javax.swing.JRadioButton;
  15.  
  16. public class Calc {
  17.  
  18. private JFrame frmStandardCalculator;
  19. private JTextField txtDisplay;
  20. double firstnum = 0;
  21. double secondnum = 0;
  22. double result;
  23. String operations;
  24. String answer;
  25.  
  26. /**
  27. * Launch the application.
  28. */
  29. public static void main(String[] args) {
  30. EventQueue.invokeLater(new Runnable() {
  31. public void run() {
  32. try {
  33. Calc window = new Calc();
  34. window.frmStandardCalculator.setVisible(true);
  35. } catch (Exception e) {
  36. e.printStackTrace();
  37. }
  38. }
  39. });
  40. }
  41.  
  42. /**
  43. * Create the application.
  44. */
  45. public Calc() {
  46. initialize();
  47. }
  48. public static int Fact(int n) {
  49. if (n <= 1)
  50. return 1;
  51. else
  52. return n * Fact(n - 1);
  53. }
  54. /**
  55. * Initialize the contents of the frame.
  56. */
  57. private void initialize() {
  58. frmStandardCalculator = new JFrame();
  59. frmStandardCalculator.setTitle("Calculator");
  60. frmStandardCalculator.setBounds(100, 100, 275, 367);
  61. frmStandardCalculator.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  62.  
  63. JMenuBar menuBar = new JMenuBar();
  64. frmStandardCalculator.setJMenuBar(menuBar);
  65.  
  66. JMenu mnFile = new JMenu("File");
  67. menuBar.add(mnFile);
  68.  
  69. JMenuItem mntmStandard = new JMenuItem("Standard");
  70. mntmStandard.addActionListener(new ActionListener() {
  71. public void actionPerformed(ActionEvent e) {
  72. frmStandardCalculator.setTitle("Calculator");
  73. frmStandardCalculator.setBounds(100, 100, 275, 367);
  74. txtDisplay.setBounds(10, 11, 243, 37);
  75. }
  76. });
  77. mnFile.add(mntmStandard);
  78.  
  79. JMenuItem mntmScintific = new JMenuItem("Scientific");
  80. mntmScintific.addActionListener(new ActionListener() {
  81. public void actionPerformed(ActionEvent e) {
  82. frmStandardCalculator.setTitle("Scientific Calculator");
  83. frmStandardCalculator.setBounds(100, 100, 459, 367);
  84. txtDisplay.setBounds(10, 11, 243, 37);
  85.  
  86. }
  87. });
  88. mnFile.add(mntmScintific);
  89.  
  90. JMenuItem mntmExit = new JMenuItem("Exit");
  91. mntmExit.addActionListener(new ActionListener() {
  92. public void actionPerformed(ActionEvent e) {
  93. System.exit(0);
  94. }
  95. });
  96. mnFile.add(mntmExit);
  97.  
  98. JMenu mnAbout = new JMenu("About");
  99. menuBar.add(mnAbout);
  100.  
  101. JMenuItem mntmMadeByVadim = new JMenuItem("Made by Vadim Gromov");
  102. mnAbout.add(mntmMadeByVadim);
  103. frmStandardCalculator.getContentPane().setLayout(null);
  104.  
  105. txtDisplay = new JTextField();
  106. txtDisplay.setBounds(9, 11, 244, 37);
  107. frmStandardCalculator.getContentPane().add(txtDisplay);
  108. txtDisplay.setColumns(10);
  109.  
  110. JButton btnNewButton = new JButton("\u2190");
  111. btnNewButton.addActionListener(new ActionListener() {
  112. public void actionPerformed(ActionEvent e) {
  113. String backspace = null;
  114.  
  115. if(txtDisplay.getText().length() > 0) {
  116. StringBuilder strB = new StringBuilder(txtDisplay.getText());
  117. strB.deleteCharAt(txtDisplay.getText().length() - 1);
  118. backspace = strB.toString();
  119. txtDisplay.setText(backspace);
  120. }
  121. }
  122. });
  123. btnNewButton.setBounds(9, 50, 46, 47);
  124. frmStandardCalculator.getContentPane().add(btnNewButton);
  125. JRadioButton rdbtnRad = new JRadioButton("Rad");
  126. JRadioButton rdbtnGrad = new JRadioButton("Deg");
  127. rdbtnGrad.addActionListener(new ActionListener() {
  128. public void actionPerformed(ActionEvent e) {
  129. rdbtnRad.setSelected(false);
  130. rdbtnGrad.setSelected(true);
  131. }
  132. });
  133. rdbtnRad.addActionListener(new ActionListener() {
  134. public void actionPerformed(ActionEvent e) {
  135. rdbtnRad.setSelected(true);
  136. rdbtnGrad.setSelected(false);
  137. }
  138. });
  139.  
  140. JButton btnCe = new JButton("CE");
  141. btnCe.addActionListener(new ActionListener() {
  142. public void actionPerformed(ActionEvent e) {
  143. firstnum = 0;
  144. secondnum = 0;
  145. operations = "";
  146. txtDisplay.setText("");
  147. }
  148. });
  149. btnCe.setFont(new Font("Tahoma", Font.PLAIN, 8));
  150. btnCe.setBounds(58, 50, 46, 47);
  151. frmStandardCalculator.getContentPane().add(btnCe);
  152.  
  153. JButton btnC = new JButton("C");
  154. btnC.setFont(new Font("Tahoma", Font.PLAIN, 8));
  155. btnC.addActionListener(new ActionListener() {
  156. public void actionPerformed(ActionEvent e) {
  157. txtDisplay.setText("");
  158. }
  159. });
  160. btnC.setBounds(107, 50, 46, 47);
  161. frmStandardCalculator.getContentPane().add(btnC);
  162.  
  163. JButton button_plus_minus = new JButton("\u00B1");
  164. button_plus_minus.addActionListener(new ActionListener() {
  165. public void actionPerformed(ActionEvent e) {
  166.  
  167. double ops = Double.parseDouble(String.valueOf(txtDisplay.getText().replace(',', '.')));
  168. ops = ops * (-1);
  169. txtDisplay.setText(String.valueOf(ops).replace(',', '.'));
  170. }
  171. });
  172. button_plus_minus.setBounds(156, 50, 46, 47);
  173. frmStandardCalculator.getContentPane().add(button_plus_minus);
  174.  
  175. JButton button_square = new JButton("\u221A");
  176. button_square.addActionListener(new ActionListener() {
  177. public void actionPerformed(ActionEvent e) {
  178. double ops = Double.parseDouble(String.valueOf(txtDisplay.getText().replace(',', '.')));
  179. ops = Math.sqrt(ops);
  180. txtDisplay.setText(String.valueOf(ops).replace(',', '.'));
  181. }
  182. });
  183. button_square.setBounds(206, 50, 46, 47);
  184. frmStandardCalculator.getContentPane().add(button_square);
  185.  
  186. JButton button_seven = new JButton("7");
  187. button_seven.addActionListener(new ActionListener() {
  188. public void actionPerformed(ActionEvent e) {
  189. String iNum = txtDisplay.getText() + button_seven.getText();
  190. txtDisplay.setText(iNum);
  191. }
  192. });
  193. button_seven.setBounds(9, 100, 46, 47);
  194. frmStandardCalculator.getContentPane().add(button_seven);
  195.  
  196. JButton button_eight = new JButton("8");
  197. button_eight.addActionListener(new ActionListener() {
  198. public void actionPerformed(ActionEvent e) {
  199. String iNum = txtDisplay.getText() + button_eight.getText();
  200. txtDisplay.setText(iNum);
  201. }
  202. });
  203. button_eight.setBounds(58, 100, 46, 47);
  204. frmStandardCalculator.getContentPane().add(button_eight);
  205.  
  206. JButton button_nine = new JButton("9");
  207. button_nine.addActionListener(new ActionListener() {
  208. public void actionPerformed(ActionEvent e) {
  209. String iNum = txtDisplay.getText() + button_nine.getText();
  210. txtDisplay.setText(iNum);
  211. }
  212. });
  213. button_nine.setBounds(107, 100, 46, 47);
  214. frmStandardCalculator.getContentPane().add(button_nine);
  215.  
  216. JButton button_del = new JButton("/");
  217. button_del.addActionListener(new ActionListener() {
  218. public void actionPerformed(ActionEvent e) {
  219. firstnum = Double.parseDouble(txtDisplay.getText().replace(',', '.'));
  220. txtDisplay.setText("");
  221. operations = "/";
  222. }
  223. });
  224. button_del.setBounds(156, 100, 46, 47);
  225. frmStandardCalculator.getContentPane().add(button_del);
  226.  
  227. JButton button_prochenti = new JButton("%");
  228. button_prochenti.addActionListener(new ActionListener() {
  229. public void actionPerformed(ActionEvent e) {
  230.  
  231. double ops = Double.parseDouble(String.valueOf(txtDisplay.getText().replace(',', '.')));
  232. ops = ops/100;
  233. txtDisplay.setText(String.valueOf(ops).replace(',', '.'));
  234. }
  235. });
  236. button_prochenti.setBounds(206, 100, 46, 47);
  237. frmStandardCalculator.getContentPane().add(button_prochenti);
  238.  
  239. JButton button_four = new JButton("4");
  240. button_four.addActionListener(new ActionListener() {
  241. public void actionPerformed(ActionEvent e) {
  242. String iNum = txtDisplay.getText() + button_four.getText();
  243. txtDisplay.setText(iNum);
  244. }
  245. });
  246. button_four.setBounds(9, 150, 46, 47);
  247. frmStandardCalculator.getContentPane().add(button_four);
  248.  
  249. JButton button_five = new JButton("5");
  250. button_five.addActionListener(new ActionListener() {
  251. public void actionPerformed(ActionEvent e) {
  252. String iNum = txtDisplay.getText() + button_five.getText();
  253. txtDisplay.setText(iNum);
  254. }
  255. });
  256. button_five.setBounds(58, 150, 46, 47);
  257. frmStandardCalculator.getContentPane().add(button_five);
  258.  
  259. JButton button_six = new JButton("6");
  260. button_six.addActionListener(new ActionListener() {
  261. public void actionPerformed(ActionEvent e) {
  262. String iNum = txtDisplay.getText() + button_six.getText();
  263. txtDisplay.setText(iNum);
  264. }
  265. });
  266. button_six.setBounds(107, 150, 46, 47);
  267. frmStandardCalculator.getContentPane().add(button_six);
  268.  
  269. JButton button_mult = new JButton("*");
  270. button_mult.addActionListener(new ActionListener() {
  271. public void actionPerformed(ActionEvent e) {
  272. firstnum = Double.parseDouble(txtDisplay.getText().replace(',', '.'));
  273. txtDisplay.setText("");
  274. operations = "*";
  275. }
  276. });
  277. button_mult.setBounds(156, 150, 46, 47);
  278. frmStandardCalculator.getContentPane().add(button_mult);
  279.  
  280. JButton button_podlit_x = new JButton("1/x");
  281. button_podlit_x.addActionListener(new ActionListener() {
  282. public void actionPerformed(ActionEvent e) {
  283. double ops = Double.parseDouble(String.valueOf(txtDisplay.getText()));
  284. ops = 1/ops;
  285. txtDisplay.setText(String.valueOf(ops).replace(',', '.'));
  286. }
  287. });
  288. button_podlit_x.setFont(new Font("Tahoma", Font.PLAIN, 9));
  289. button_podlit_x.setBounds(206, 150, 46, 47);
  290. frmStandardCalculator.getContentPane().add(button_podlit_x);
  291.  
  292. JButton button_one = new JButton("1");
  293. button_one.addActionListener(new ActionListener() {
  294. public void actionPerformed(ActionEvent e) {
  295. String iNum = txtDisplay.getText() + button_one.getText();
  296. txtDisplay.setText(iNum);
  297. }
  298. });
  299. button_one.setBounds(9, 200, 46, 47);
  300. frmStandardCalculator.getContentPane().add(button_one);
  301.  
  302. JButton button_two = new JButton("2");
  303. button_two.addActionListener(new ActionListener() {
  304. public void actionPerformed(ActionEvent e) {
  305. String iNum = txtDisplay.getText() + button_two.getText();
  306. txtDisplay.setText(iNum);
  307. }
  308. });
  309. button_two.setBounds(58, 200, 46, 47);
  310. frmStandardCalculator.getContentPane().add(button_two);
  311.  
  312. JButton button_three = new JButton("3");
  313. button_three.addActionListener(new ActionListener() {
  314. public void actionPerformed(ActionEvent e) {
  315. String iNum = txtDisplay.getText() + button_three.getText();
  316. txtDisplay.setText(iNum);
  317. }
  318. });
  319. button_three.setBounds(107, 200, 46, 47);
  320. frmStandardCalculator.getContentPane().add(button_three);
  321.  
  322. JButton button_minus = new JButton("-");
  323. button_minus.addActionListener(new ActionListener() {
  324. public void actionPerformed(ActionEvent e) {
  325. firstnum = Double.parseDouble(txtDisplay.getText().replace(',', '.'));
  326. txtDisplay.setText("");
  327. operations = "-";
  328. }
  329. });
  330. button_minus.setBounds(156, 200, 46, 47);
  331. frmStandardCalculator.getContentPane().add(button_minus);
  332.  
  333. JButton button_point = new JButton(".");
  334. button_point.addActionListener(new ActionListener() {
  335. public void actionPerformed(ActionEvent e) {
  336. String backspace = null;
  337.  
  338. if(txtDisplay.getText().length() > 0 && !txtDisplay.getText().contains(".")) {
  339. StringBuilder strB = new StringBuilder(txtDisplay.getText());
  340. strB.append('.');
  341. backspace = strB.toString();
  342. txtDisplay.setText(backspace);
  343. }
  344. }
  345. });
  346. button_point.setBounds(107, 250, 46, 47);
  347. frmStandardCalculator.getContentPane().add(button_point);
  348.  
  349. JButton button_plus = new JButton("+");
  350. button_plus.addActionListener(new ActionListener() {
  351. public void actionPerformed(ActionEvent e) {
  352. firstnum = Double.parseDouble(txtDisplay.getText().replace(',', '.'));
  353. txtDisplay.setText("");
  354. operations = "+";
  355. }
  356. });
  357. button_plus.setBounds(156, 250, 46, 47);
  358. frmStandardCalculator.getContentPane().add(button_plus);
  359.  
  360. JButton button_zero = new JButton("0");
  361. button_zero.addActionListener(new ActionListener() {
  362. public void actionPerformed(ActionEvent e) {
  363. String iNum = txtDisplay.getText() + button_zero.getText();
  364. txtDisplay.setText(iNum);
  365. }
  366. });
  367. button_zero.setBounds(9, 250, 95, 47);
  368. frmStandardCalculator.getContentPane().add(button_zero);
  369.  
  370. JButton button_equal = new JButton("=");
  371. button_equal.addActionListener(new ActionListener() {
  372. public void actionPerformed(ActionEvent e) {
  373. String answer;
  374. secondnum = Double.parseDouble(txtDisplay.getText());
  375.  
  376. if(operations == "+") {
  377. result = firstnum + secondnum;
  378. answer = String.format("%f", result).replace(',', '.');
  379. txtDisplay.setText(answer);
  380. }
  381. if(operations == "-") {
  382. result = firstnum - secondnum;
  383. answer = String.format("%f", result).replace(',', '.');
  384. txtDisplay.setText(answer);
  385. }
  386. if(operations == "*") {
  387. result = firstnum * secondnum;
  388. answer = String.format("%f", result).replace(',', '.');
  389. txtDisplay.setText(answer);
  390. }
  391. if(operations == "/") {
  392. result = firstnum / secondnum;
  393. answer = String.format("%f", result).replace(',', '.');
  394. txtDisplay.setText(answer);
  395. }
  396. if(operations == "pow") {
  397. result = Math.pow(firstnum, secondnum);
  398. answer = String.format("%f", result).replace(',', '.');
  399. txtDisplay.setText(answer);
  400. }
  401. if(operations == "sqrt") {
  402.  
  403. result = Math.pow(firstnum, (1/secondnum));
  404. answer = String.format("%f", result).replace(',', '.');
  405. txtDisplay.setText(answer);
  406. }
  407.  
  408. }
  409. });
  410. button_equal.setBounds(206, 200, 46, 97);
  411. frmStandardCalculator.getContentPane().add(button_equal);
  412.  
  413. JButton btnSin = new JButton("sin");
  414. btnSin.addActionListener(new ActionListener() {
  415. public void actionPerformed(ActionEvent e) {
  416. double ops = Double.parseDouble(String.valueOf(txtDisplay.getText().replace(',', '.')));
  417. if(rdbtnRad.isSelected() == true) {
  418. ops = Math.sin(ops);
  419. }
  420. if(rdbtnGrad.isSelected() == true) {
  421. ops = Math.sin(Math.toRadians (ops));
  422. }
  423. txtDisplay.setText(String.valueOf(ops).replace(',', '.'));
  424. }
  425. });
  426. btnSin.setFont(new Font("Tahoma", Font.PLAIN, 11));
  427. btnSin.setBounds(260, 50, 55, 47);
  428.  
  429. frmStandardCalculator.getContentPane().add(btnSin);
  430.  
  431. JButton btnCos = new JButton("cos");
  432. btnCos.addActionListener(new ActionListener() {
  433. public void actionPerformed(ActionEvent e) {
  434. double ops = Double.parseDouble(String.valueOf(txtDisplay.getText().replace(',', '.')));
  435. if(rdbtnRad.isSelected() == true) {
  436. ops = Math.cos(ops);
  437. }
  438. if(rdbtnGrad.isSelected() == true) {
  439. ops = Math.cos(Math.toRadians (ops));
  440. }
  441.  
  442. txtDisplay.setText(String.valueOf(ops).replace(',', '.'));
  443. }
  444. });
  445. btnCos.setFont(new Font("Tahoma", Font.PLAIN, 11));
  446. btnCos.setBounds(260, 100, 55, 47);
  447. frmStandardCalculator.getContentPane().add(btnCos);
  448.  
  449. JButton btnTan = new JButton("tan");
  450. btnTan.addActionListener(new ActionListener() {
  451. public void actionPerformed(ActionEvent e) {
  452. double ops = Double.parseDouble(String.valueOf(txtDisplay.getText().replace(',', '.')));
  453. if(rdbtnRad.isSelected() == true) {
  454. ops = Math.tan(ops);
  455. }
  456. if(rdbtnGrad.isSelected() == true) {
  457. ops = Math.tan(Math.toRadians (ops));
  458. }
  459. txtDisplay.setText(String.valueOf(ops).replace(',', '.'));
  460. }
  461. });
  462. btnTan.setFont(new Font("Tahoma", Font.PLAIN, 11));
  463. btnTan.setBounds(260, 150, 55, 47);
  464. frmStandardCalculator.getContentPane().add(btnTan);
  465.  
  466. JButton btnLog = new JButton("log");
  467. btnLog.addActionListener(new ActionListener() {
  468. public void actionPerformed(ActionEvent e) {
  469. double ops = Double.parseDouble(String.valueOf(txtDisplay.getText().replace(',', '.')));
  470. ops = Math.log10(ops);
  471. txtDisplay.setText(String.valueOf(ops).replace(',', '.'));
  472. }
  473. });
  474. btnLog.setFont(new Font("Tahoma", Font.PLAIN, 11));
  475. btnLog.setBounds(260, 200, 55, 47);
  476. frmStandardCalculator.getContentPane().add(btnLog);
  477.  
  478. JButton btnPi = new JButton("\u03C0");
  479. btnPi.addActionListener(new ActionListener() {
  480. public void actionPerformed(ActionEvent e) {
  481. double ops;
  482. ops = Math.PI;
  483. txtDisplay.setText(String.valueOf(ops).replace(',', '.'));
  484. }
  485. });
  486. btnPi.setFont(new Font("Centaur", Font.PLAIN, 11));
  487. btnPi.setBounds(260, 250, 55, 47);
  488. frmStandardCalculator.getContentPane().add(btnPi);
  489.  
  490. JButton btnSinh = new JButton("sinh");
  491. btnSinh.addActionListener(new ActionListener() {
  492. public void actionPerformed(ActionEvent e) {
  493. double ops = Double.parseDouble(String.valueOf(txtDisplay.getText().replace(',', '.')));
  494. if(rdbtnRad.isSelected() == true) {
  495. ops = Math.sinh(ops);
  496. }
  497. if(rdbtnGrad.isSelected() == true) {
  498. ops = Math.sinh(Math.toRadians (ops));
  499. }
  500. txtDisplay.setText(String.valueOf(ops).replace(',', '.'));
  501. }
  502. });
  503. btnSinh.setFont(new Font("Tahoma", Font.PLAIN, 11));
  504. btnSinh.setBounds(320, 50, 55, 47);
  505. frmStandardCalculator.getContentPane().add(btnSinh);
  506.  
  507. JButton btnCosh = new JButton("cosh");
  508. btnCosh.addActionListener(new ActionListener() {
  509. public void actionPerformed(ActionEvent e) {
  510. double ops = Double.parseDouble(String.valueOf(txtDisplay.getText().replace(',', '.')));
  511. if(rdbtnRad.isSelected() == true) {
  512. ops = Math.cosh(ops);
  513. }
  514. if(rdbtnGrad.isSelected() == true) {
  515. ops = Math.cosh(Math.toRadians (ops));
  516. }
  517. txtDisplay.setText(String.valueOf(ops).replace(',', '.'));
  518. }
  519. });
  520. btnCosh.setFont(new Font("Tahoma", Font.PLAIN, 10));
  521. btnCosh.setBounds(320, 100, 55, 47);
  522. frmStandardCalculator.getContentPane().add(btnCosh);
  523.  
  524. JButton btnTanh = new JButton("tanh");
  525. btnTanh.addActionListener(new ActionListener() {
  526. public void actionPerformed(ActionEvent e) {
  527. double ops = Double.parseDouble(String.valueOf(txtDisplay.getText().replace(',', '.')));
  528. if(rdbtnRad.isSelected() == true) {
  529. ops = Math.tanh(ops);
  530. }
  531. if(rdbtnGrad.isSelected() == true) {
  532. ops = Math.tanh(Math.toRadians (ops));
  533. }
  534. txtDisplay.setText(String.valueOf(ops).replace(',', '.'));
  535. }
  536. });
  537. btnTanh.setFont(new Font("Tahoma", Font.PLAIN, 10));
  538. btnTanh.setBounds(320, 150, 55, 47);
  539. frmStandardCalculator.getContentPane().add(btnTanh);
  540.  
  541. JButton btnLn = new JButton("ln");
  542. btnLn.addActionListener(new ActionListener() {
  543. public void actionPerformed(ActionEvent e) {
  544. double ops = Double.parseDouble(String.valueOf(txtDisplay.getText().replace(',', '.')));
  545. ops = Math.log(ops);
  546. txtDisplay.setText(String.valueOf(ops).replace(',', '.'));
  547. }
  548. });
  549. btnLn.setFont(new Font("Tahoma", Font.PLAIN, 11));
  550. btnLn.setBounds(320, 200, 55, 47);
  551. frmStandardCalculator.getContentPane().add(btnLn);
  552.  
  553. JButton btnE = new JButton("e");
  554. btnE.addActionListener(new ActionListener() {
  555. public void actionPerformed(ActionEvent e) {
  556. double ops;
  557. ops = Math.E;
  558. txtDisplay.setText(String.valueOf(ops).replace(',', '.'));
  559. }
  560. });
  561. btnE.setFont(new Font("Tahoma", Font.PLAIN, 11));
  562. btnE.setBounds(320, 250, 55, 47);
  563. frmStandardCalculator.getContentPane().add(btnE);
  564.  
  565. JButton btnPow2 = new JButton("x^2");
  566. btnPow2.addActionListener(new ActionListener() {
  567. public void actionPerformed(ActionEvent e) {
  568. double ops = Double.parseDouble(String.valueOf(txtDisplay.getText().replace(',', '.')));
  569. ops = Math.pow(ops, 2);
  570. txtDisplay.setText(String.valueOf(ops).replace(',', '.'));
  571. }
  572. });
  573. btnPow2.setFont(new Font("Tahoma", Font.PLAIN, 11));
  574. btnPow2.setBounds(380, 50, 55, 47);
  575. frmStandardCalculator.getContentPane().add(btnPow2);
  576.  
  577. JButton btnPow3 = new JButton("x^3");
  578. btnPow3.addActionListener(new ActionListener() {
  579. public void actionPerformed(ActionEvent e) {
  580. double ops = Double.parseDouble(String.valueOf(txtDisplay.getText().replace(',', '.')));
  581. ops = Math.pow(ops, 3);
  582. txtDisplay.setText(String.valueOf(ops).replace(',', '.'));
  583. }
  584. });
  585. btnPow3.setFont(new Font("Tahoma", Font.PLAIN, 11));
  586. btnPow3.setBounds(380, 100, 55, 47);
  587. frmStandardCalculator.getContentPane().add(btnPow3);
  588.  
  589. JButton btnXy = new JButton("x^y");
  590. btnXy.addActionListener(new ActionListener() {
  591. public void actionPerformed(ActionEvent e) {
  592. firstnum = Double.parseDouble(txtDisplay.getText().replace(',', '.'));
  593. txtDisplay.setText("");
  594. operations = "pow";
  595. }
  596. });
  597. btnXy.setFont(new Font("Tahoma", Font.PLAIN, 11));
  598. btnXy.setBounds(380, 150, 55, 47);
  599. frmStandardCalculator.getContentPane().add(btnXy);
  600.  
  601. JButton btnSqrtY = new JButton("x^1/y");
  602. btnSqrtY.addActionListener(new ActionListener() {
  603. public void actionPerformed(ActionEvent e) {
  604. firstnum = Double.parseDouble(txtDisplay.getText().replace(',', '.'));
  605. txtDisplay.setText("");
  606. operations = "sqrt";
  607. }
  608. });
  609. btnSqrtY.setFont(new Font("Tahoma", Font.PLAIN, 8));
  610. btnSqrtY.setBounds(380, 200, 55, 47);
  611. frmStandardCalculator.getContentPane().add(btnSqrtY);
  612.  
  613. JButton btnFact = new JButton("x!");
  614. btnFact.addActionListener(new ActionListener() {
  615. public void actionPerformed(ActionEvent e) {
  616. int ops = Integer.parseInt(String.valueOf(txtDisplay.getText().replace(',', '.')));
  617. ops = Fact(ops);
  618. txtDisplay.setText(String.valueOf(ops).replace(',', '.'));
  619. }
  620.  
  621. });
  622. btnFact.setFont(new Font("Tahoma", Font.PLAIN, 11));
  623. btnFact.setBounds(380, 250, 55, 47);
  624. frmStandardCalculator.getContentPane().add(btnFact);
  625.  
  626.  
  627. rdbtnRad.setSelected(true);
  628. rdbtnRad.setBounds(259, 18, 55, 23);
  629. frmStandardCalculator.getContentPane().add(rdbtnRad);
  630.  
  631. rdbtnGrad.setBounds(317, 18, 55, 23);
  632. frmStandardCalculator.getContentPane().add(rdbtnGrad);
  633. }
  634. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement