Advertisement
KahnClifford

JavaWindowsCalculator

Jan 1st, 2019
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.11 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.ComponentOrientation;
  3. import java.awt.Font;
  4. import java.awt.GridBagConstraints;
  5. import java.awt.GridBagLayout;
  6. import java.awt.Insets;
  7.  
  8. import javax.swing.BorderFactory;
  9. import javax.swing.JButton;
  10. import javax.swing.JPanel;
  11. import javax.swing.JTextArea;
  12.  
  13. public class StandardPanel extends JPanel{
  14. private JTextArea textArea;
  15. private JButton mc = new JButton("MC");
  16. private JButton mr = new JButton("MR");
  17. private JButton ms = new JButton("MS");
  18. private JButton mp = new JButton("M+");
  19. private JButton mn = new JButton("M-");
  20. private JButton backspace = new JButton("←");
  21. private JButton ce = new JButton("CE");
  22. private JButton c = new JButton("C");
  23. private JButton pm = new JButton("±");
  24. private JButton sqrt = new JButton("√");
  25. private JButton _7 = new JButton("7");
  26. private JButton _8 = new JButton("8");
  27. private JButton _9 = new JButton("9");
  28. private JButton div = new JButton("/");
  29. private JButton per = new JButton("%");
  30. private JButton _4 = new JButton("4");
  31. private JButton _5 = new JButton("5");
  32. private JButton _6 = new JButton("6");
  33. private JButton mul = new JButton("*");
  34. private JButton _1x = new JButton("1/x");
  35. private JButton _1 = new JButton("1");
  36. private JButton _2 = new JButton("2");
  37. private JButton _3 = new JButton("3");
  38. private JButton min = new JButton("-");
  39. private JButton equ = new JButton("=");
  40. private JButton _0 = new JButton("0");
  41. private JButton point = new JButton(".");
  42. private JButton plu = new JButton("+");
  43.  
  44. private void setEfx() {
  45. Font keyfonts = new Font("Segoe UI", Font.PLAIN, 11);
  46. Color btncolor1 = new Color(212,224,237);
  47. Color btncolor2 = new Color(238,244,250);
  48. Color btncolor3 = new Color(237,243,248);
  49.  
  50. textArea.setFont(new Font("Consolas", Font.PLAIN, 25));
  51. mc.setFont(keyfonts);
  52. mc.setBackground(btncolor1);
  53. mr.setFont(keyfonts);
  54. mr.setBackground(btncolor1);
  55. ms.setFont(keyfonts);
  56. ms.setBackground(btncolor1);
  57. mp.setFont(keyfonts);
  58. mp.setBackground(btncolor1);
  59.  
  60. mn.setFont(keyfonts);
  61. mn.setBackground(btncolor1);
  62. backspace.setFont(keyfonts);
  63. backspace.setBackground(btncolor2);
  64. ce.setFont(keyfonts);
  65. ce.setBackground(btncolor2);
  66. c.setFont(keyfonts);
  67. c.setBackground(btncolor2);
  68. pm.setFont(keyfonts);
  69. pm.setBackground(btncolor2);
  70.  
  71. sqrt.setFont(keyfonts);
  72. sqrt.setBackground(btncolor2);
  73. _7.setFont(keyfonts);
  74. _7.setBackground(btncolor3);
  75. _8.setFont(keyfonts);
  76. _8.setBackground(btncolor3);
  77. _9.setFont(keyfonts);
  78. _9.setBackground(btncolor3);
  79. div.setFont(keyfonts);
  80. div.setBackground(btncolor2);
  81.  
  82. per.setFont(keyfonts);
  83. per.setBackground(btncolor2);
  84. _4.setFont(keyfonts);
  85. _4.setBackground(btncolor3);
  86. _5.setFont(keyfonts);
  87. _5.setBackground(btncolor3);
  88. _6.setFont(keyfonts);
  89. _6.setBackground(btncolor3);
  90. mul.setFont(keyfonts);
  91. mul.setBackground(btncolor2);
  92.  
  93. _1x.setFont(keyfonts);
  94. _1x.setBackground(btncolor2);
  95. _1.setFont(keyfonts);
  96. _1.setBackground(btncolor3);
  97. _2.setFont(keyfonts);
  98. _2.setBackground(btncolor3);
  99. _3.setFont(keyfonts);
  100. _3.setBackground(btncolor3);
  101.  
  102. min.setFont(keyfonts);
  103. min.setBackground(btncolor2);
  104. equ.setFont(keyfonts);
  105. equ.setBackground(btncolor2);
  106. _0.setFont(keyfonts);
  107. _0.setBackground(btncolor3);
  108. point.setFont(keyfonts);
  109. point.setBackground(btncolor3);
  110. plu.setFont(keyfonts);
  111. plu.setBackground(btncolor2);
  112.  
  113.  
  114.  
  115. }
  116.  
  117. public StandardPanel() {
  118. textArea = new JTextArea();
  119.  
  120.  
  121. setEfx();
  122. setBackground(new Color(217,228,241));
  123. textArea.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
  124. textArea.setEditable(false);
  125. textArea.setText("0");
  126. textArea.setBackground(new Color(251,253,254));
  127.  
  128.  
  129. setLayout(new GridBagLayout());
  130. setBorder(BorderFactory.createEmptyBorder(5,4,5,4));
  131.  
  132. GridBagConstraints gc = new GridBagConstraints();
  133.  
  134. gc.gridx=0;//column
  135. gc.gridy=0;//row
  136.  
  137. gc.weighty = 0.0;
  138. gc.weightx = 0.0;
  139.  
  140. gc.ipady = 5;
  141. gc.ipadx = 1;
  142.  
  143. gc.gridwidth = 5;
  144. gc.gridheight = 1;
  145. gc.anchor = GridBagConstraints.CENTER;
  146. gc.fill = GridBagConstraints.BOTH;
  147. gc.insets = new Insets(5,5,0,5);//top,left,bottom,right
  148. add(textArea,gc);
  149.  
  150. //-------row 1-----------
  151.  
  152. gc.gridx=0;
  153. gc.gridy=1;
  154. gc.gridwidth = 1;
  155. gc.gridheight = 1;
  156. gc.anchor = GridBagConstraints.CENTER;
  157. gc.fill = GridBagConstraints.BOTH;
  158. gc.insets = new Insets(5,5,5,5);
  159. add(mc,gc);
  160.  
  161. gc.gridx=1;
  162. gc.gridy=1;
  163. gc.gridwidth = 1;
  164. gc.gridheight = 1;
  165. gc.anchor = GridBagConstraints.CENTER;
  166. gc.fill = GridBagConstraints.BOTH;
  167. gc.insets = new Insets(5,5,5,5);
  168. add(mr,gc);
  169.  
  170. gc.gridx=2;
  171. gc.gridy=1;
  172. gc.gridwidth = 1;
  173. gc.gridheight = 1;
  174. gc.anchor = GridBagConstraints.CENTER;
  175. gc.fill = GridBagConstraints.BOTH;
  176. gc.insets = new Insets(5,5,5,5);
  177. add(ms,gc);
  178.  
  179. gc.gridx=3;
  180. gc.gridy=1;
  181. gc.gridwidth = 1;
  182. gc.gridheight = 1;
  183. gc.anchor = GridBagConstraints.CENTER;
  184. gc.fill = GridBagConstraints.BOTH;
  185. gc.insets = new Insets(5,5,5,5);
  186. add(mp,gc);
  187.  
  188. gc.gridx=4;
  189. gc.gridy=1;
  190. gc.gridwidth = 1;
  191. gc.gridheight = 1;
  192. gc.anchor = GridBagConstraints.CENTER;
  193. gc.fill = GridBagConstraints.BOTH;
  194. gc.insets = new Insets(5,5,5,5);
  195. add(mn,gc);
  196.  
  197. //-------row 2--------
  198.  
  199. gc.gridx=0;
  200. gc.gridy=2;
  201. gc.gridwidth = 1;
  202. gc.gridheight = 1;
  203. gc.anchor = GridBagConstraints.CENTER;
  204. gc.fill = GridBagConstraints.BOTH;
  205. gc.insets = new Insets(5,5,5,5);
  206. add(backspace,gc);
  207.  
  208. gc.gridx=1;
  209. gc.gridy=2;
  210. gc.gridwidth = 1;
  211. gc.gridheight = 1;
  212. gc.anchor = GridBagConstraints.CENTER;
  213. gc.fill = GridBagConstraints.BOTH;
  214. gc.insets = new Insets(5,5,5,5);
  215. add(ce,gc);
  216.  
  217. gc.gridx=2;
  218. gc.gridy=2;
  219. gc.gridwidth = 1;
  220. gc.gridheight = 1;
  221. gc.anchor = GridBagConstraints.CENTER;
  222. gc.fill = GridBagConstraints.BOTH;
  223. gc.insets = new Insets(5,5,5,5);
  224. add(c,gc);
  225.  
  226. gc.gridx=3;
  227. gc.gridy=2;
  228. gc.gridwidth = 1;
  229. gc.gridheight = 1;
  230. gc.anchor = GridBagConstraints.CENTER;
  231. gc.fill = GridBagConstraints.BOTH;
  232. gc.insets = new Insets(5,5,5,5);
  233. add(pm,gc);
  234.  
  235. gc.gridx=4;
  236. gc.gridy=2;
  237. gc.gridwidth = 1;
  238. gc.gridheight = 1;
  239. gc.anchor = GridBagConstraints.CENTER;
  240. gc.fill = GridBagConstraints.BOTH;
  241. gc.insets = new Insets(5,5,5,5);
  242. add(sqrt,gc);
  243.  
  244. //-------row 3--------
  245.  
  246. gc.gridx=0;
  247. gc.gridy=3;
  248. gc.gridwidth = 1;
  249. gc.gridheight = 1;
  250. gc.anchor = GridBagConstraints.CENTER;
  251. gc.fill = GridBagConstraints.BOTH;
  252. gc.insets = new Insets(5,5,5,5);
  253. add(_7,gc);
  254.  
  255. gc.gridx=1;
  256. gc.gridy=3;
  257. gc.gridwidth = 1;
  258. gc.gridheight = 1;
  259. gc.anchor = GridBagConstraints.CENTER;
  260. gc.fill = GridBagConstraints.BOTH;
  261. gc.insets = new Insets(5,5,5,5);
  262. add(_8,gc);
  263.  
  264. gc.gridx=2;
  265. gc.gridy=3;
  266. gc.gridwidth = 1;
  267. gc.gridheight = 1;
  268. gc.anchor = GridBagConstraints.CENTER;
  269. gc.fill = GridBagConstraints.BOTH;
  270. gc.insets = new Insets(5,5,5,5);
  271. add(_9,gc);
  272.  
  273. gc.gridx=3;
  274. gc.gridy=3;
  275. gc.gridwidth = 1;
  276. gc.gridheight = 1;
  277. gc.anchor = GridBagConstraints.CENTER;
  278. gc.fill = GridBagConstraints.BOTH;
  279. gc.insets = new Insets(5,5,5,5);
  280. add(div,gc);
  281.  
  282. gc.gridx=4;
  283. gc.gridy=3;
  284. gc.gridwidth = 1;
  285. gc.gridheight = 1;
  286. gc.anchor = GridBagConstraints.CENTER;
  287. gc.fill = GridBagConstraints.BOTH;
  288. gc.insets = new Insets(5,5,5,5);
  289. add(per,gc);
  290.  
  291. //-------row 4--------
  292.  
  293. gc.gridx=0;
  294. gc.gridy=4;
  295. gc.gridwidth = 1;
  296. gc.gridheight = 1;
  297. gc.anchor = GridBagConstraints.CENTER;
  298. gc.fill = GridBagConstraints.BOTH;
  299. gc.insets = new Insets(5,5,5,5);
  300. add(_4,gc);
  301.  
  302. gc.gridx=1;
  303. gc.gridy=4;
  304. gc.gridwidth = 1;
  305. gc.gridheight = 1;
  306. gc.anchor = GridBagConstraints.CENTER;
  307. gc.fill = GridBagConstraints.BOTH;
  308. gc.insets = new Insets(5,5,5,5);
  309. add(_5,gc);
  310.  
  311. gc.gridx=2;
  312. gc.gridy=4;
  313. gc.gridwidth = 1;
  314. gc.gridheight = 1;
  315. gc.anchor = GridBagConstraints.CENTER;
  316. gc.fill = GridBagConstraints.BOTH;
  317. gc.insets = new Insets(5,5,5,5);
  318. add(_6,gc);
  319.  
  320. gc.gridx=3;
  321. gc.gridy=4;
  322. gc.gridwidth = 1;
  323. gc.gridheight = 1;
  324. gc.anchor = GridBagConstraints.CENTER;
  325. gc.fill = GridBagConstraints.BOTH;
  326. gc.insets = new Insets(5,5,5,5);
  327. add(mul,gc);
  328.  
  329. gc.gridx=4;
  330. gc.gridy=4;
  331. gc.gridwidth = 1;
  332. gc.gridheight = 1;
  333. gc.anchor = GridBagConstraints.CENTER;
  334. gc.fill = GridBagConstraints.BOTH;
  335. gc.insets = new Insets(5,5,5,5);
  336. add(_1x,gc);
  337.  
  338. //-------row 5--------
  339.  
  340. gc.gridx=0;
  341. gc.gridy=5;
  342. gc.gridwidth = 1;
  343. gc.gridheight = 1;
  344. gc.anchor = GridBagConstraints.CENTER;
  345. gc.fill = GridBagConstraints.BOTH;
  346. gc.insets = new Insets(5,5,5,5);
  347. add(_1,gc);
  348.  
  349. gc.gridx=1;
  350. gc.gridy=5;
  351. gc.gridwidth = 1;
  352. gc.gridheight = 1;
  353. gc.anchor = GridBagConstraints.CENTER;
  354. gc.fill = GridBagConstraints.BOTH;
  355. gc.insets = new Insets(5,5,5,5);
  356. add(_2,gc);
  357.  
  358. gc.gridx=2;
  359. gc.gridy=5;
  360. gc.gridwidth = 1;
  361. gc.gridheight = 1;
  362. gc.anchor = GridBagConstraints.CENTER;
  363. gc.fill = GridBagConstraints.BOTH;
  364. gc.insets = new Insets(5,5,5,5);
  365. add(_3,gc);
  366.  
  367. gc.gridx=3;
  368. gc.gridy=5;
  369. gc.gridwidth = 1;
  370. gc.gridheight = 1;
  371. gc.anchor = GridBagConstraints.CENTER;
  372. gc.fill = GridBagConstraints.BOTH;
  373. gc.insets = new Insets(5,5,5,5);
  374. add(min,gc);
  375.  
  376. gc.gridx=4;
  377. gc.gridy=5;
  378. gc.gridwidth = 1;
  379. gc.gridheight = 2;
  380. gc.anchor = GridBagConstraints.CENTER;
  381. gc.fill = GridBagConstraints.BOTH;
  382. gc.insets = new Insets(5,5,5,5);
  383. add(equ,gc);
  384.  
  385.  
  386.  
  387. //-------row 6--------
  388.  
  389. gc.gridx=0;
  390. gc.gridy=6;
  391. gc.gridwidth = 2;
  392. gc.gridheight = 1;
  393. gc.anchor = GridBagConstraints.CENTER;
  394. gc.fill = GridBagConstraints.BOTH;
  395. gc.insets = new Insets(5,5,5,5);
  396. add(_0,gc);
  397.  
  398. gc.gridx=2;
  399. gc.gridy=6;
  400. gc.gridwidth = 1;
  401. gc.gridheight = 1;
  402. gc.anchor = GridBagConstraints.CENTER;
  403. gc.fill = GridBagConstraints.BOTH;
  404. gc.insets = new Insets(5,5,5,5);
  405. add(point,gc);
  406.  
  407. gc.gridx=3;
  408. gc.gridy=6;
  409. gc.gridwidth = 1;
  410. gc.gridheight = 1;
  411. gc.anchor = GridBagConstraints.CENTER;
  412. gc.fill = GridBagConstraints.BOTH;
  413. gc.insets = new Insets(5,5,5,5);
  414. add(plu,gc);
  415.  
  416.  
  417. }
  418. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement