Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.59 KB | None | 0 0
  1. package kalkukacka;
  2.  
  3. public class NewJFrame extends javax.swing.JFrame {
  4.  
  5. int firstnum;
  6. int secondnum;
  7. int result;
  8. String operation;
  9.  
  10. public NewJFrame() {
  11. initComponents();
  12. }
  13.  
  14. @SuppressWarnings("unchecked")
  15. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  16. private void initComponents() {
  17.  
  18. jScrollPane1 = new javax.swing.JScrollPane();
  19. jEditorPane1 = new javax.swing.JEditorPane();
  20. jButton8 = new javax.swing.JButton();
  21. jButton10 = new javax.swing.JButton();
  22. jButton13 = new javax.swing.JButton();
  23. jButton15 = new javax.swing.JButton();
  24. jButton19 = new javax.swing.JButton();
  25. jTextField1 = new javax.swing.JTextField();
  26. jButton1 = new javax.swing.JButton();
  27. jButton2 = new javax.swing.JButton();
  28. jButton3 = new javax.swing.JButton();
  29. jButton4 = new javax.swing.JButton();
  30. jButton5 = new javax.swing.JButton();
  31. jButton6 = new javax.swing.JButton();
  32. jButton7 = new javax.swing.JButton();
  33. jButton9 = new javax.swing.JButton();
  34. jButton11 = new javax.swing.JButton();
  35. jButton12 = new javax.swing.JButton();
  36. jButton14 = new javax.swing.JButton();
  37. jButton16 = new javax.swing.JButton();
  38. jButton17 = new javax.swing.JButton();
  39. jButton18 = new javax.swing.JButton();
  40. jButton20 = new javax.swing.JButton();
  41. jButton21 = new javax.swing.JButton();
  42. jButton22 = new javax.swing.JButton();
  43. jButton23 = new javax.swing.JButton();
  44.  
  45. jScrollPane1.setViewportView(jEditorPane1);
  46.  
  47. jButton8.setText("jButton1");
  48.  
  49. jButton10.setText("jButton1");
  50.  
  51. jButton13.setText("jButton1");
  52.  
  53. jButton15.setText("jButton1");
  54.  
  55. jButton19.setText("jButton1");
  56.  
  57. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  58.  
  59. jTextField1.addActionListener(new java.awt.event.ActionListener() {
  60. public void actionPerformed(java.awt.event.ActionEvent evt) {
  61. jTextField1ActionPerformed(evt);
  62. }
  63. });
  64.  
  65. jButton1.setText("1");
  66. jButton1.addActionListener(new java.awt.event.ActionListener() {
  67. public void actionPerformed(java.awt.event.ActionEvent evt) {
  68. jButton1ActionPerformed(evt);
  69. }
  70. });
  71.  
  72. jButton2.setText("2");
  73. jButton2.setActionCommand("2");
  74. jButton2.setAutoscrolls(true);
  75. jButton2.addActionListener(new java.awt.event.ActionListener() {
  76. public void actionPerformed(java.awt.event.ActionEvent evt) {
  77. jButton2ActionPerformed(evt);
  78. }
  79. });
  80.  
  81. jButton3.setText("3");
  82. jButton3.addActionListener(new java.awt.event.ActionListener() {
  83. public void actionPerformed(java.awt.event.ActionEvent evt) {
  84. jButton3ActionPerformed(evt);
  85. }
  86. });
  87.  
  88. jButton4.setText("4");
  89. jButton4.addActionListener(new java.awt.event.ActionListener() {
  90. public void actionPerformed(java.awt.event.ActionEvent evt) {
  91. jButton4ActionPerformed(evt);
  92. }
  93. });
  94.  
  95. jButton5.setText("5");
  96. jButton5.addActionListener(new java.awt.event.ActionListener() {
  97. public void actionPerformed(java.awt.event.ActionEvent evt) {
  98. jButton5ActionPerformed(evt);
  99. }
  100. });
  101.  
  102. jButton6.setText("6");
  103. jButton6.addActionListener(new java.awt.event.ActionListener() {
  104. public void actionPerformed(java.awt.event.ActionEvent evt) {
  105. jButton6ActionPerformed(evt);
  106. }
  107. });
  108.  
  109. jButton7.setText("7");
  110. jButton7.addActionListener(new java.awt.event.ActionListener() {
  111. public void actionPerformed(java.awt.event.ActionEvent evt) {
  112. jButton7ActionPerformed(evt);
  113. }
  114. });
  115.  
  116. jButton9.setText("9");
  117. jButton9.addActionListener(new java.awt.event.ActionListener() {
  118. public void actionPerformed(java.awt.event.ActionEvent evt) {
  119. jButton9ActionPerformed(evt);
  120. }
  121. });
  122.  
  123. jButton11.setText("8");
  124. jButton11.addActionListener(new java.awt.event.ActionListener() {
  125. public void actionPerformed(java.awt.event.ActionEvent evt) {
  126. jButton11ActionPerformed(evt);
  127. }
  128. });
  129.  
  130. jButton12.setText("0");
  131. jButton12.addActionListener(new java.awt.event.ActionListener() {
  132. public void actionPerformed(java.awt.event.ActionEvent evt) {
  133. jButton12ActionPerformed(evt);
  134. }
  135. });
  136.  
  137. jButton14.setText("=");
  138. jButton14.addActionListener(new java.awt.event.ActionListener() {
  139. public void actionPerformed(java.awt.event.ActionEvent evt) {
  140. jButton14ActionPerformed(evt);
  141. }
  142. });
  143.  
  144. jButton16.setText("+");
  145. jButton16.addActionListener(new java.awt.event.ActionListener() {
  146. public void actionPerformed(java.awt.event.ActionEvent evt) {
  147. jButton16ActionPerformed(evt);
  148. }
  149. });
  150.  
  151. jButton17.setText("x");
  152. jButton17.addActionListener(new java.awt.event.ActionListener() {
  153. public void actionPerformed(java.awt.event.ActionEvent evt) {
  154. jButton17ActionPerformed(evt);
  155. }
  156. });
  157.  
  158. jButton18.setText("/");
  159. jButton18.addActionListener(new java.awt.event.ActionListener() {
  160. public void actionPerformed(java.awt.event.ActionEvent evt) {
  161. jButton18ActionPerformed(evt);
  162. }
  163. });
  164.  
  165. jButton20.setText("<-");
  166. jButton20.addActionListener(new java.awt.event.ActionListener() {
  167. public void actionPerformed(java.awt.event.ActionEvent evt) {
  168. jButton20ActionPerformed(evt);
  169. }
  170. });
  171.  
  172. jButton21.setText("C");
  173. jButton21.setActionCommand("C");
  174.  
  175. jButton22.setText("CE");
  176.  
  177. jButton23.setText("-");
  178. jButton23.addActionListener(new java.awt.event.ActionListener() {
  179. public void actionPerformed(java.awt.event.ActionEvent evt) {
  180. jButton23ActionPerformed(evt);
  181. }
  182. });
  183.  
  184. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  185. getContentPane().setLayout(layout);
  186. layout.setHorizontalGroup(
  187. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  188. .addGroup(layout.createSequentialGroup()
  189. .addContainerGap()
  190. .addComponent(jTextField1)
  191. .addContainerGap())
  192. .addGroup(layout.createSequentialGroup()
  193. .addGap(49, 49, 49)
  194. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  195. .addComponent(jButton22, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
  196. .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
  197. .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
  198. .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
  199. .addGap(36, 36, 36)
  200. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  201. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  202. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  203. .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
  204. .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
  205. .addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
  206. .addComponent(jButton12, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
  207. .addComponent(jButton21, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
  208. .addGap(48, 48, 48)
  209. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  210. .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
  211. .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
  212. .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
  213. .addComponent(jButton20, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
  214. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 51, Short.MAX_VALUE)
  215. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  216. .addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
  217. .addComponent(jButton16, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
  218. .addComponent(jButton17, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
  219. .addComponent(jButton18, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
  220. .addComponent(jButton23, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
  221. .addGap(41, 41, 41))
  222. );
  223. layout.setVerticalGroup(
  224. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  225. .addGroup(layout.createSequentialGroup()
  226. .addContainerGap()
  227. .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
  228. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  229. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  230. .addComponent(jButton18, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  231. .addComponent(jButton20, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  232. .addComponent(jButton21, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  233. .addComponent(jButton22, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
  234. .addGap(13, 13, 13)
  235. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  236. .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  237. .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  238. .addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  239. .addComponent(jButton17, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
  240. .addGap(18, 18, 18)
  241. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  242. .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  243. .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  244. .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  245. .addComponent(jButton23, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
  246. .addGap(22, 22, 22)
  247. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  248. .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  249. .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  250. .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  251. .addComponent(jButton16, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
  252. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  253. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  254. .addComponent(jButton12, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
  255. .addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)))
  256. );
  257.  
  258. pack();
  259. }// </editor-fold>
  260.  
  261. private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
  262. // TODO add your handling code here:
  263. }
  264.  
  265. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  266. String Enternumber = jTextField1.getText() + jButton1.getText();
  267. jTextField1.setText(Enternumber);
  268. }
  269.  
  270. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  271. String Enternumber = jTextField1.getText() + jButton2.getText();
  272. jTextField1.setText(Enternumber);
  273. }
  274.  
  275. private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
  276. String Enternumber = jTextField1.getText() + jButton3.getText();
  277. jTextField1.setText(Enternumber);
  278. }
  279.  
  280. private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
  281. String Enternumber = jTextField1.getText() + jButton4.getText();
  282. jTextField1.setText(Enternumber);
  283. }
  284.  
  285. private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
  286. String Enternumber = jTextField1.getText() + jButton5.getText();
  287. jTextField1.setText(Enternumber);
  288. }
  289.  
  290. private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
  291. String Enternumber = jTextField1.getText()+jButton6.getText();
  292. jTextField1.setText(Enternumber);
  293. }
  294.  
  295. private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
  296. String Enternumber = jTextField1.getText()+jButton7.getText();
  297. jTextField1.setText(Enternumber);
  298. }
  299.  
  300. private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {
  301. String Enternumber = jTextField1.getText()+jButton11.getText();
  302. jTextField1.setText(Enternumber);
  303. }
  304.  
  305. private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
  306. String Enternumber = jTextField1.getText()+jButton9.getText();
  307. jTextField1.setText(Enternumber);
  308. }
  309.  
  310. private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {
  311. String Enternumber = jTextField1.getText()+jButton12.getText();
  312. jTextField1.setText(Enternumber);
  313. }
  314.  
  315. private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {
  316. secondnum=Integer.parseInt(jTextField1.getText());
  317. if(operation.equals("+")){
  318. result=firstnum+secondnum;
  319. }
  320. if(operation.equals("-")){
  321. result=firstnum-secondnum;
  322. }
  323. if(operation.equals("/")){
  324. result=firstnum/secondnum;
  325. }
  326. if(operation.equals("*")){
  327. result=firstnum*secondnum;
  328. }
  329. jTextField1.setText(result+" ");
  330.  
  331. }
  332.  
  333. private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {
  334. firstnum=Integer.parseInt(jTextField1.getText());
  335. jTextField1.setText("");
  336. operation="+";
  337. }
  338.  
  339. private void jButton23ActionPerformed(java.awt.event.ActionEvent evt) {
  340. firstnum=Integer.parseInt(jTextField1.getText());
  341. jTextField1.setText("");
  342. operation="-";
  343. }
  344.  
  345. private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) {
  346. firstnum=Integer.parseInt(jTextField1.getText());
  347. jTextField1.setText("");
  348. operation="*";
  349. }
  350.  
  351. private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {
  352. firstnum=Integer.parseInt(jTextField1.getText());
  353. jTextField1.setText("");
  354. operation="/";
  355. }
  356.  
  357. private void jButton20ActionPerformed(java.awt.event.ActionEvent evt) {
  358. secondnum = 0;
  359. jTextField1.setText("");
  360. }
  361.  
  362. /**
  363. * @param args the command line arguments
  364. */
  365. public static void main(String args[]) {
  366. /* Set the Nimbus look and feel */
  367. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  368. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  369. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  370. */
  371. try {
  372. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  373. if ("Nimbus".equals(info.getName())) {
  374. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  375. break;
  376. }
  377. }
  378. } catch (ClassNotFoundException ex) {
  379. java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  380. } catch (InstantiationException ex) {
  381. java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  382. } catch (IllegalAccessException ex) {
  383. java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  384. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  385. java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  386. }
  387. //</editor-fold>
  388.  
  389. /* Create and display the form */
  390. java.awt.EventQueue.invokeLater(new Runnable() {
  391. public void run() {
  392. new NewJFrame().setVisible(true);
  393. }
  394. });
  395. }
  396.  
  397. // Variables declaration - do not modify
  398. private javax.swing.JButton jButton1;
  399. private javax.swing.JButton jButton10;
  400. private javax.swing.JButton jButton11;
  401. private javax.swing.JButton jButton12;
  402. private javax.swing.JButton jButton13;
  403. private javax.swing.JButton jButton14;
  404. private javax.swing.JButton jButton15;
  405. private javax.swing.JButton jButton16;
  406. private javax.swing.JButton jButton17;
  407. private javax.swing.JButton jButton18;
  408. private javax.swing.JButton jButton19;
  409. private javax.swing.JButton jButton2;
  410. private javax.swing.JButton jButton20;
  411. private javax.swing.JButton jButton21;
  412. private javax.swing.JButton jButton22;
  413. private javax.swing.JButton jButton23;
  414. private javax.swing.JButton jButton3;
  415. private javax.swing.JButton jButton4;
  416. private javax.swing.JButton jButton5;
  417. private javax.swing.JButton jButton6;
  418. private javax.swing.JButton jButton7;
  419. private javax.swing.JButton jButton8;
  420. private javax.swing.JButton jButton9;
  421. private javax.swing.JEditorPane jEditorPane1;
  422. private javax.swing.JScrollPane jScrollPane1;
  423. private javax.swing.JTextField jTextField1;
  424. // End of variables declaration
  425. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement