SHARE
TWEET

Untitled

a guest Dec 10th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package a;
  2.  
  3. import java.awt.event.*;
  4. import java.awt.*;
  5. import java.awt.Button;
  6. import java.awt.Color;
  7. import java.awt.Container;
  8. import java.awt.Font;
  9. import java.awt.Frame;
  10. import java.awt.Label;
  11. import javax.swing.*;
  12. //2
  13. public class S0754044_3 extends JFrame implements ActionListener{
  14. static S0754044_3 frm1 = new S0754044_3();
  15. static JLabel Label = new JLabel("Java");
  16. static JButton btn = new JButton("1");
  17. static JButton btn1 = new JButton("2");
  18. static JButton btn2 = new JButton("3");
  19. static JButton btn3 = new JButton("4");
  20. static JButton btn4 = new JButton("5");
  21. static JButton btn5 = new JButton("6");
  22. static JButton btn6 = new JButton("7");
  23. static JButton btn7 = new JButton("8");
  24. static JButton btn8 = new JButton("9");
  25. static JButton btn9 = new JButton("0");
  26. static JButton btn0 = new JButton("+");
  27. static JButton btnex = new JButton("=");
  28.  
  29. static int sum = 0;
  30. static int a =0;
  31. static int b;
  32. static int c;
  33. static int total;
  34. static JTextField txt = new JTextField();
  35.  
  36. public static void main(String[] args) {
  37. Container container = frm1.getContentPane();
  38. frm1.setLayout(null);
  39. btn1.addActionListener(frm1);
  40. btn2.addActionListener(frm1);
  41. btn3.addActionListener(frm1);
  42. btn4.addActionListener(frm1);
  43. btn5.addActionListener(frm1);
  44. btn6.addActionListener(frm1);
  45. btn7.addActionListener(frm1);
  46. btn8.addActionListener(frm1);
  47. btn.addActionListener(frm1);
  48. btn9.addActionListener(frm1);
  49. btn0.addActionListener(frm1);
  50. btnex.addActionListener(frm1);
  51.  
  52. //Label.setBounds(150,150,100,50);
  53. btn.setBounds(50,100,50,50);
  54. btn1.setBounds(100,100,50,50);
  55. btn2.setBounds(150,100,50,50);
  56. btn3.setBounds(50,150,50,50);
  57. btn4.setBounds(100,150,50,50);
  58. btn5.setBounds(150,150,50,50);
  59. btn6.setBounds(50,200,50,50);
  60. btn7.setBounds(100,200,50,50);
  61. btn8.setBounds(150,200,50,50);
  62. btn9.setBounds(50,250,50,50);
  63. btn0.setBounds(100,250,50,50);
  64. btnex.setBounds(150,250,50,50);
  65.  
  66. frm1.setSize(280,340);
  67. txt.setBounds(50,48,150,27);
  68. container.add(txt);
  69. container.add(Label);
  70. container.add(btn);
  71. container.add(btn1);
  72. container.add(btn2);
  73. container.add(btn3);
  74. container.add(btn4);
  75. container.add(btn5);
  76. container.add(btn6);
  77. container.add(btn7);
  78. container.add(btn8);
  79. container.add(btn9);
  80. container.add(btn0);
  81. container.add(btnex);
  82. txt.setHorizontalAlignment(JTextField.RIGHT);
  83.  
  84.  
  85.  
  86. frm1.setLocation(5,5);
  87. frm1.add(Label);
  88. frm1.setVisible(true);
  89. frm1.setTitle("text");
  90. frm1.addWindowListener(new WindowAdapter()
  91. {
  92. public void windowClosing(WindowEvent e)
  93. {
  94. System.exit(0);}});
  95. }
  96.  
  97. @Override
  98. public void actionPerformed(ActionEvent e) {
  99. // TODO Auto-generated method stub
  100. if(a==0)
  101. {
  102. if(e.getSource()==btn)
  103. {
  104. sum*=10;
  105. sum+=1;
  106. String str =String.valueOf(sum);
  107. txt.setText(str);
  108. }
  109. if(e.getSource()== btn1)
  110. {
  111. sum*=10;
  112. sum+=2;
  113. String str =String.valueOf(sum);
  114. txt.setText(str);
  115. }
  116. if(e.getSource()==btn2)
  117. {
  118. sum*=10;
  119. sum+=3;
  120. String str =String.valueOf(sum);
  121. txt.setText(str);
  122. }
  123. if(e.getSource()==btn3)
  124. {
  125. sum*=10;
  126. sum+=4;
  127. String str =String.valueOf(sum);
  128. txt.setText(str);
  129. }
  130. if(e.getSource()==btn4)
  131. {
  132. sum*=10;
  133. sum+=5;
  134. String str =String.valueOf(sum);
  135. txt.setText(str);
  136. }
  137. if(e.getSource()==btn5)
  138. {
  139. sum*=10;
  140. sum+=6;
  141. String str =String.valueOf(sum);
  142. txt.setText(str);
  143. }
  144. if(e.getSource()==btn6)
  145. {
  146. sum*=10;
  147. sum+=7;
  148. String str =String.valueOf(sum);
  149. txt.setText(str);
  150. }
  151. if(e.getSource()==btn7)
  152. {
  153. sum*=10;
  154. sum+=8;
  155. String str =String.valueOf(sum);
  156. txt.setText(str);
  157. }
  158. if(e.getSource()==btn8)
  159. {
  160. sum*=10;
  161. sum+=9;
  162. String str =String.valueOf(sum);
  163. txt.setText(str);
  164. }
  165. if(e.getSource()==btn9)
  166. {
  167. sum*=10;
  168. sum+=0;
  169. String str =String.valueOf(sum);
  170. txt.setText(str);
  171. }
  172. if(e.getSource()==btn0)
  173. {
  174. String str =String.valueOf(sum);
  175.     b = Integer.parseInt(String.valueOf(str));
  176.     sum = 0;
  177.     a=1;
  178. }
  179. }
  180. else if(a==1)
  181. {
  182. if(e.getSource()==btn)
  183. {
  184. sum*=10;
  185. sum+=1;
  186. String str =String.valueOf(sum);
  187. txt.setText(str);
  188. }
  189. if(e.getSource()== btn1)
  190. {
  191. sum*=10;
  192. sum+=2;
  193. String str =String.valueOf(sum);
  194. txt.setText(str);
  195. }
  196. if(e.getSource()==btn2)
  197. {
  198. sum*=10;
  199. sum+=3;
  200. String str =String.valueOf(sum);
  201. txt.setText(str);
  202. }
  203. if(e.getSource()==btn3)
  204. {
  205. sum*=10;
  206. sum+=4;
  207. String str =String.valueOf(sum);
  208. txt.setText(str);
  209. }
  210. if(e.getSource()==btn4)
  211. {
  212. sum*=10;
  213. sum+=5;
  214. String str =String.valueOf(sum);
  215. txt.setText(str);
  216. }
  217. if(e.getSource()==btn5)
  218. {
  219. sum*=10;
  220. sum+=6;
  221. String str =String.valueOf(sum);
  222. txt.setText(str);
  223. }
  224. if(e.getSource()==btn6)
  225. {
  226. sum*=10;
  227. sum+=7;
  228. String str =String.valueOf(sum);
  229. txt.setText(str);
  230. }
  231. if(e.getSource()==btn7)
  232. {
  233. sum*=10;
  234. sum+=8;
  235. String str =String.valueOf(sum);
  236. txt.setText(str);
  237. }
  238. if(e.getSource()==btn8)
  239. {
  240. sum*=10;
  241. sum+=9;
  242. String str =String.valueOf(sum);
  243. txt.setText(str);
  244. }
  245. if(e.getSource()==btn9)
  246. {
  247. sum*=10;
  248. sum+=0;
  249. String str =String.valueOf(sum);
  250. txt.setText(str);
  251. }
  252. if(e.getSource()==btn0||e.getSource()==btnex)
  253. {
  254. String str =String.valueOf(sum);
  255.    c = Integer.parseInt(String.valueOf(str));
  256.    total +=b;
  257.    total +=c;
  258. txt.setText(String.valueOf(total));
  259.    sum = 0;
  260.    a=0;
  261. }
  262. }
  263. }
  264. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top