{"id":4740,"date":"2022-04-06T19:17:50","date_gmt":"2022-04-06T17:17:50","guid":{"rendered":"https:\/\/home.et.utwente.nl\/slootenvanf\/?p=4740"},"modified":"2025-07-28T11:45:29","modified_gmt":"2025-07-28T09:45:29","slug":"java-tutorial-create-calculator","status":"publish","type":"post","link":"https:\/\/home.et.utwente.nl\/slootenvanf\/2022\/04\/06\/java-tutorial-create-calculator\/","title":{"rendered":"Java tutorial: create a simple calculator"},"content":{"rendered":"\n<p>In this Java tutorial you will learn how to create a simple calculator using Eclipse. This tutorial is meant for beginners who are just starting with Java. It is strongly recommended to also learn the Java basics using for instance the <a href=\"https:\/\/www.w3schools.com\/java\/default.asp\" target=\"_blank\" rel=\"noreferrer noopener\">w3schools tutorial<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Installing the Eclipse IDE for Java Developers<\/h3>\n\n\n\n<p>If you already have Eclipse installed, you can skip this part. But make sure you also have installed the Window Builder plugin of Eclipse. You can check that via <em>Help &gt; About, Installation Details.<\/em><\/p>\n\n\n\n<p><a href=\"https:\/\/www.eclipse.org\/downloads\/packages\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Download the Eclipse Installer<\/strong><\/a> and run that. Select the first option: &#8220;Eclipse IDE for Java Developers&#8221;:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-36.png\"><img loading=\"lazy\" decoding=\"async\" width=\"632\" height=\"649\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-36.png\" alt=\"\" class=\"wp-image-4779\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-36.png 632w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-36-292x300.png 292w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-36-97x100.png 97w\" sizes=\"auto, (max-width: 632px) 100vw, 632px\" \/><\/a><\/figure>\n\n\n\n<p>Click &#8220;Install&#8221; (keep options as they are).<br>Click &#8220;Accept Now&#8221;.<br>Wait for the installer to finish. This can take several minutes.<br>Click &#8220;Launch&#8221; to start Eclipse.<br>Select the option &#8220;Use this as the default and do not ask again&#8221; and click <em>Launch<\/em>:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-37.png\"><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"285\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-37.png\" alt=\"\" class=\"wp-image-4780\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-37.png 624w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-37-300x137.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-37-100x46.png 100w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/a><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"appendix3\">Eclipse: Add Window Builder<\/h4>\n\n\n\n<p>The tool to create graphical user interfaces is not part of all editions of Eclipse, and must be added manually. In Eclipse, choose&nbsp;<em>Help &gt; Install New Software<\/em>\u2026 In the field&nbsp;<em>Work with<\/em>, enter this address:<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/download.eclipse.org\/windowbuilder\/latest\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/download.eclipse.org\/windowbuilder\/latest\/<\/a><\/strong><\/p>\n\n\n\n<p>(press Enter), and select&nbsp;<em>WindowBuilder&nbsp;<\/em>and&nbsp;<em>WindowBuilder XWT Support<\/em>:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"833\" height=\"684\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2020\/04\/image-26.png\" alt=\"\" class=\"wp-image-2615\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2020\/04\/image-26.png 833w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2020\/04\/image-26-300x246.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2020\/04\/image-26-768x631.png 768w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2020\/04\/image-26-100x82.png 100w\" sizes=\"auto, (max-width: 833px) 100vw, 833px\" \/><\/figure>\n\n\n\n<p>To start the installation press&nbsp;<em>Next<\/em>&nbsp;two times. Accept the license, then&nbsp;<em>Finish<\/em>. The installation will continue in the background (you can see its progress in the lower right corner). Wait for it to finish. If asked to restart Eclipse, do so.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Create Java project and first Java file<\/h3>\n\n\n\n<p>To start a new project, select <em>File &gt; New &gt; Java Project<\/em> from the menu. Fill in the project name and press Finish (you may leave the other options at their default values):<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-11.png\"><img loading=\"lazy\" decoding=\"async\" width=\"952\" height=\"887\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-11.png\" alt=\"\" class=\"wp-image-4743\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-11.png 952w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-11-300x280.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-11-768x716.png 768w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-11-100x93.png 100w\" sizes=\"auto, (max-width: 952px) 100vw, 952px\" \/><\/a><\/figure>\n\n\n\n<p>If a popup appears that asks you to fill in a module name, fill in &#8220;calculator&#8221; and press <em>Create<\/em>.<\/p>\n\n\n\n<p>Select <em>File &gt; New &gt; Other <\/em>(or press Ctrl + N) to add a Java file to the project. Browse to WindowBuilder, JFrame and click <em>Next<\/em>:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-12.png\"><img loading=\"lazy\" decoding=\"async\" width=\"730\" height=\"597\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-12.png\" alt=\"\" class=\"wp-image-4745\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-12.png 730w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-12-300x245.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-12-100x82.png 100w\" sizes=\"auto, (max-width: 730px) 100vw, 730px\" \/><\/a><\/figure>\n\n\n\n<p>At package name type &#8220;userinterface&#8221; and at name &#8220;Calculator&#8221;. Press <em>Finish<\/em>:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-13.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-13.png\" alt=\"\" class=\"wp-image-4746\" width=\"640\" height=\"523\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-13.png 730w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-13-300x245.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-13-100x82.png 100w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/figure>\n\n\n\n<p>You might get some errors in the code, this is because the imports and the module info are not setup yet:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-14.png\"><img loading=\"lazy\" decoding=\"async\" width=\"452\" height=\"250\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-14.png\" alt=\"\" class=\"wp-image-4748\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-14.png 452w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-14-300x166.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-14-100x55.png 100w\" sizes=\"auto, (max-width: 452px) 100vw, 452px\" \/><\/a><\/figure>\n\n\n\n<p>Top fix this, first add the module info. Click the first warning symbol that has a small light-bulb in front of line 10 (this indicates there are tips on how to resolve those), and click &#8220;Add &#8216;requires java.desktop&#8217; to module-info.java&#8221;:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-15.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1030\" height=\"409\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-15-1030x409.png\" alt=\"\" class=\"wp-image-4750\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-15-1030x409.png 1030w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-15-300x119.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-15-768x305.png 768w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-15-100x40.png 100w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-15.png 1232w\" sizes=\"auto, (max-width: 1030px) 100vw, 1030px\" \/><\/a><\/figure>\n\n\n\n<p>If you have any errors left, you might have to fix the imports (an <a href=\"https:\/\/www.w3schools.com\/java\/java_packages.asp\" target=\"_blank\" rel=\"noreferrer noopener\">&#8216;import&#8217; statement<\/a> tells the compiler to use a <a href=\"https:\/\/www.w3schools.com\/java\/java_packages.asp\" target=\"_blank\" rel=\"noreferrer noopener\">package<\/a>, eg. from a certain library) by clicking one of the warnings in-front of the lines with errors.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Create the userinterface<\/h3>\n\n\n\n<p>We will create the userinterface with help of the Window Builder and its palette.<\/p>\n\n\n\n<p>Switch to the Design tab of the code:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-16.png\"><img loading=\"lazy\" decoding=\"async\" width=\"327\" height=\"297\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-16.png\" alt=\"\" class=\"wp-image-4751\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-16.png 327w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-16-300x272.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-16-100x91.png 100w\" sizes=\"auto, (max-width: 327px) 100vw, 327px\" \/><\/a><\/figure>\n\n\n\n<p>First enlarge the window by selecting the in the components tree and then dragging the window at the lower-right corner:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-17.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1030\" height=\"638\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-17-1030x638.png\" alt=\"\" class=\"wp-image-4752\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-17-1030x638.png 1030w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-17-300x186.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-17-768x476.png 768w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-17-100x62.png 100w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-17.png 1188w\" sizes=\"auto, (max-width: 1030px) 100vw, 1030px\" \/><\/a><\/figure>\n\n\n\n<p>Set the title of the app by modifying the title property of the JFrame:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-33.png\"><img loading=\"lazy\" decoding=\"async\" width=\"379\" height=\"456\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-33.png\" alt=\"\" class=\"wp-image-4774\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-33.png 379w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-33-249x300.png 249w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-33-83x100.png 83w\" sizes=\"auto, (max-width: 379px) 100vw, 379px\" \/><\/a><\/figure>\n\n\n\n<p>Set the look-and-feel of the app to Windows Classic:<br>(this is optional)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-34.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1004\" height=\"228\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-34.png\" alt=\"\" class=\"wp-image-4775\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-34.png 1004w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-34-300x68.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-34-768x174.png 768w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-34-100x23.png 100w\" sizes=\"auto, (max-width: 1004px) 100vw, 1004px\" \/><\/a><\/figure>\n\n\n\n<p>And make sure it will get applied via the preferences: select <em>Window &gt; Preferences<\/em>, then navigate to WindowBuilder, Swing, LookAndFeel. Then set the option &#8220;Apply choosen LookAndFeel in main() method&#8221; (press <em>Apply and Close<\/em>):<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-35.png\"><img loading=\"lazy\" decoding=\"async\" width=\"730\" height=\"525\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-35.png\" alt=\"\" class=\"wp-image-4776\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-35.png 730w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-35-300x216.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-35-100x72.png 100w\" sizes=\"auto, (max-width: 730px) 100vw, 730px\" \/><\/a><\/figure>\n\n\n\n<p>Set the layout of the contentPane to &#8220;Grouplayout&#8221;:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-18.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1030\" height=\"558\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-18-1030x558.png\" alt=\"\" class=\"wp-image-4753\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-18-1030x558.png 1030w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-18-300x162.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-18-768x416.png 768w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-18-100x54.png 100w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-18.png 1280w\" sizes=\"auto, (max-width: 1030px) 100vw, 1030px\" \/><\/a><\/figure>\n\n\n\n<p>We will use a textfield as the display of the calculator, and the buttons will be inside a panel, with a grid-layout. First add the textfield (JTextField):<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-19.png\"><img loading=\"lazy\" decoding=\"async\" width=\"738\" height=\"640\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-19.png\" alt=\"\" class=\"wp-image-4754\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-19.png 738w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-19-300x260.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-19-100x87.png 100w\" sizes=\"auto, (max-width: 738px) 100vw, 738px\" \/><\/a><\/figure>\n\n\n\n<p>Place it somewhere at the top and enlarge it by dragging the corner(s):<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-20.png\"><img loading=\"lazy\" decoding=\"async\" width=\"650\" height=\"226\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-20.png\" alt=\"\" class=\"wp-image-4755\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-20.png 650w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-20-300x104.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-20-100x35.png 100w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/a><\/figure>\n\n\n\n<p>Make it auto resizable and align both left and right, by clicking the small arrow pointing left and then select &#8220;Auto Resizable&#8221;:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-21.png\"><img loading=\"lazy\" decoding=\"async\" width=\"781\" height=\"186\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-21.png\" alt=\"\" class=\"wp-image-4756\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-21.png 781w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-21-300x71.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-21-768x183.png 768w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-21-100x24.png 100w\" sizes=\"auto, (max-width: 781px) 100vw, 781px\" \/><\/a><\/figure>\n\n\n\n<p>Give it a proper name by modifying its properties, rename the Variable name to &#8220;display&#8221;:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-22.png\"><img loading=\"lazy\" decoding=\"async\" width=\"576\" height=\"682\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-22.png\" alt=\"\" class=\"wp-image-4758\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-22.png 576w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-22-253x300.png 253w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-22-84x100.png 84w\" sizes=\"auto, (max-width: 576px) 100vw, 576px\" \/><\/a><\/figure>\n\n\n\n<p>Set the font to a larger font also, for instance Tahoma 24.<\/p>\n\n\n\n<p>Next, add a JPanel, resize it so that is uses up the remaining space, name it &#8220;buttonPanel&#8221; and set its layout to GridLayout:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-23.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1030\" height=\"578\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-23-1030x578.png\" alt=\"\" class=\"wp-image-4759\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-23-1030x578.png 1030w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-23-300x168.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-23-768x431.png 768w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-23-100x56.png 100w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-23.png 1260w\" sizes=\"auto, (max-width: 1030px) 100vw, 1030px\" \/><\/a><\/figure>\n\n\n\n<p>Now define the layout: set the amount of columns the buttons in that panel will be in to 5. Click the plus-sign in-front of Layout, then fill in the 5:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-24.png\"><img loading=\"lazy\" decoding=\"async\" width=\"641\" height=\"229\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-24.png\" alt=\"\" class=\"wp-image-4762\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-24.png 641w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-24-300x107.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-24-100x36.png 100w\" sizes=\"auto, (max-width: 641px) 100vw, 641px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Add buttons to the grid panel<\/h3>\n\n\n\n<p>Add 20 buttons (JButton) to the buttonPanel (make sure to click inside that):<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-25.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1030\" height=\"576\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-25-1030x576.png\" alt=\"\" class=\"wp-image-4763\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-25-1030x576.png 1030w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-25-300x168.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-25-768x430.png 768w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-25-100x56.png 100w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-25.png 1273w\" sizes=\"auto, (max-width: 1030px) 100vw, 1030px\" \/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-26.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1030\" height=\"568\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-26-1030x568.png\" alt=\"\" class=\"wp-image-4764\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-26-1030x568.png 1030w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-26-300x166.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-26-768x424.png 768w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-26-100x55.png 100w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-26.png 1292w\" sizes=\"auto, (max-width: 1030px) 100vw, 1030px\" \/><\/a><\/figure>\n\n\n\n<p>After the first button has been added, click on the right side of that to place the new button at the right side:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-27.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1030\" height=\"574\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-27-1030x574.png\" alt=\"\" class=\"wp-image-4765\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-27-1030x574.png 1030w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-27-300x167.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-27-768x428.png 768w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-27-100x56.png 100w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-27.png 1268w\" sizes=\"auto, (max-width: 1030px) 100vw, 1030px\" \/><\/a><\/figure>\n\n\n\n<p>Keep doing this for all 20 buttons until it looks like:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-28.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1030\" height=\"585\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-28-1030x585.png\" alt=\"\" class=\"wp-image-4766\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-28-1030x585.png 1030w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-28-300x171.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-28-768x437.png 768w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-28-100x57.png 100w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-28.png 1258w\" sizes=\"auto, (max-width: 1030px) 100vw, 1030px\" \/><\/a><\/figure>\n\n\n\n<p>Give all buttons proper names and texts: change their <a href=\"https:\/\/www.w3schools.com\/java\/java_variables.asp\" target=\"_blank\" rel=\"noreferrer noopener\">variable <\/a>names and the text properties of each of them according to the image below. The variable names are written in red on the buttons:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-29.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1030\" height=\"667\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-29-1030x667.png\" alt=\"\" class=\"wp-image-4769\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-29-1030x667.png 1030w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-29-300x194.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-29-768x498.png 768w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-29-100x65.png 100w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-29.png 1096w\" sizes=\"auto, (max-width: 1030px) 100vw, 1030px\" \/><\/a><\/figure>\n\n\n\n<p>The one above the btnEq (equal sign) is not used and can have just an empty text.<\/p>\n\n\n\n<p>Run the app. It should look similar to the one below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-43.png\"><img loading=\"lazy\" decoding=\"async\" width=\"659\" height=\"699\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-43.png\" alt=\"\" class=\"wp-image-4811\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-43.png 659w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-43-283x300.png 283w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-43-94x100.png 94w\" sizes=\"auto, (max-width: 659px) 100vw, 659px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">First interaction: add eventhandlers for the number buttons<\/h3>\n\n\n\n<p>First we are going to make the number buttons work. Double click on the button with a &#8220;7&#8221; (btn7). This will jump to the code and a piece of code will be generated. This is the code that will be called when a user clicks the button:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-30.png\"><img loading=\"lazy\" decoding=\"async\" width=\"402\" height=\"118\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-30.png\" alt=\"\" class=\"wp-image-4771\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-30.png 402w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-30-300x88.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-30-100x29.png 100w\" sizes=\"auto, (max-width: 402px) 100vw, 402px\" \/><\/a><\/figure>\n\n\n\n<p>The &#8220;add code here&#8221; comment has been added to clarify where you must add code for the eventhandler. When btn7 is clicked, a 7 should appear in the display. We can accomplish that by using the <em>setText()<\/em> <a href=\"https:\/\/www.w3schools.com\/java\/java_methods.asp\" target=\"_blank\" rel=\"noreferrer noopener\">method <\/a>of the display (display is an JTextField, which has a <a href=\"https:\/\/www.w3schools.com\/java\/java_methods.asp\" target=\"_blank\" rel=\"noreferrer noopener\">method<\/a> <em>setText()<\/em>, which we can call to set its text).  So we need something like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>display.setText( ... );<\/code><\/pre>\n\n\n\n<p>Inside the brackets should be a 7:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>display.setText( \"7\" );<\/code><\/pre>\n\n\n\n<p>Lets add that to the code:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-31.png\"><img loading=\"lazy\" decoding=\"async\" width=\"402\" height=\"132\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-31.png\" alt=\"\" class=\"wp-image-4772\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-31.png 402w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-31-300x99.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-31-100x33.png 100w\" sizes=\"auto, (max-width: 402px) 100vw, 402px\" \/><\/a><\/figure>\n\n\n\n<p>Now test it by running the app: press the Run icon <img decoding=\"async\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-32.png\" alt=\"Run\"> in the toolbar. Then you will see the app:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>You will notice that if you press the button multiple times, there will remain only one 7 in the display. This is because we will set the text to &#8220;7&#8221; each time the button is pressed. But that is not what we want: we want a 7 to be appended to the text in the display. This can be accomplished if we first get the text of the display, then append a 7 to that and then set the text to that new String:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>String currentText = display.getText();\ndisplay.setText(currentText + \"7\");\n<\/code><\/pre>\n\n\n\n<p>Try this (run the app). Does it work?<\/p>\n\n\n\n<p>Now we will have to add this code to all number buttons. But before we do that, we can make our lives a bit easier. Because now we would have to copy-paste the code to every button, and modify the &#8220;7&#8221; bit. Eg. for btn2, the String would need to be &#8220;2&#8221;, and so on. But what if we can make it a generic piece of code?<\/p>\n\n\n\n<p>We can ask the event (parameter e) for the action command that was involved. If this is empty (not set in the buttons&#8217; properties), it will default to the text on the button, which is precisely what we need. So instead of &#8220;7&#8221;, we can use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>e.getActionCommand()<\/code><\/pre>\n\n\n\n<p>So the code would look like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>display.setText(currentText + e.getActionCommand());<\/code><\/pre>\n\n\n\n<p>To make it even more generic, it will be better to call a <a href=\"https:\/\/www.w3schools.com\/java\/java_methods.asp\" target=\"_blank\" rel=\"noreferrer noopener\">method<\/a> from the eventhandler, which will have any additional code we will need in the future. We will name this method &#8220;processDigit&#8221;. So replace the code in the eventhandler by:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>processDigit( e.getActionCommand() );<\/code><\/pre>\n\n\n\n<p>So now the eventhandler looks like:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-38.png\"><img loading=\"lazy\" decoding=\"async\" width=\"394\" height=\"116\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-38.png\" alt=\"\" class=\"wp-image-4782\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-38.png 394w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-38-300x88.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-38-100x29.png 100w\" sizes=\"auto, (max-width: 394px) 100vw, 394px\" \/><\/a><\/figure>\n\n\n\n<p>Eclipse is now complaining that this <a href=\"https:\/\/www.w3schools.com\/java\/java_methods.asp\" target=\"_blank\" rel=\"noreferrer noopener\">method<\/a> does not yet exists. So we will create it. We will do this automatically, by clicking the lightbulb in the margin and selecting to create the method in the Calculator class:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-39.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1030\" height=\"314\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-39-1030x314.png\" alt=\"\" class=\"wp-image-4787\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-39-1030x314.png 1030w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-39-300x91.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-39-768x234.png 768w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-39-100x30.png 100w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-39.png 1051w\" sizes=\"auto, (max-width: 1030px) 100vw, 1030px\" \/><\/a><\/figure>\n\n\n\n<p>This will add the code, all the way down at the end of the class (scroll down):<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-40.png\"><img loading=\"lazy\" decoding=\"async\" width=\"413\" height=\"63\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-40.png\" alt=\"\" class=\"wp-image-4788\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-40.png 413w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-40-300x46.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-40-100x15.png 100w\" sizes=\"auto, (max-width: 413px) 100vw, 413px\" \/><\/a><\/figure>\n\n\n\n<p>In this method, add the code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>display.setText( display.getText() + actionCommand );<\/code><\/pre>\n\n\n\n<p>This is a bit shortened version of the code used earlier. Do you understand the differences?<\/p>\n\n\n\n<p>Switch to the WindowBuilder (tab Design) and double click on the next button, for instance the &#8220;8&#8221;. In its event handler, add the same line of code (copy-paste from the eventhandler of btn7):<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-41.png\"><img loading=\"lazy\" decoding=\"async\" width=\"387\" height=\"113\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-41.png\" alt=\"\" class=\"wp-image-4789\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-41.png 387w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-41-300x88.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-41-100x29.png 100w\" sizes=\"auto, (max-width: 387px) 100vw, 387px\" \/><\/a><\/figure>\n\n\n\n<p>Repeat this for all number buttons and the &#8220;.&#8221; (btnDot). And test if it work, you should be able to make any number appear on the display. The only problem is that you can now have multiple dots in a number, which should be fixed later.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Make operators work, and input a second number<\/h3>\n\n\n\n<p>In the Design view, double click the btnPlus, to add an eventhandler for that.<\/p>\n\n\n\n<p>In the eventhandler, add a call to a method which will process the operator:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>setOperator( e.getActionCommand() );<\/code><\/pre>\n\n\n\n<p>Repeat this for the other operators (btnDiv, btnMin, btnMul).<\/p>\n\n\n\n<p>Add the method <em>setOperator()<\/em> to the Calculator class (click the bulb in the margin). Add this line of code to that method:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>operand1 = display.getText();<\/code><\/pre>\n\n\n\n<p>This will store the number on the display into a <a href=\"https:\/\/www.w3schools.com\/java\/java_variables.asp\" target=\"_blank\" rel=\"noreferrer noopener\">variable<\/a>, which we can use later when we will calculate the result of the expression. The variable operand1 does not exist yet, create it by clicking the bulb in the margin and choosing the option to &#8216;Create field &#8230;&#8217;:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-42.png\"><img loading=\"lazy\" decoding=\"async\" width=\"974\" height=\"294\" src=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-42.png\" alt=\"\" class=\"wp-image-4791\" srcset=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-42.png 974w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-42-300x91.png 300w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-42-768x232.png 768w, https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/image-42-100x30.png 100w\" sizes=\"auto, (max-width: 974px) 100vw, 974px\" \/><\/a><\/figure>\n\n\n\n<p>A <a href=\"https:\/\/www.w3schools.com\/java\/java_class_attributes.asp\" target=\"_blank\" rel=\"noreferrer noopener\">field<\/a> is another word for a class-variable.<\/p>\n\n\n\n<p>The operator which is in the actionCommand parameter, must also be stored:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>operator = actionCommand;<\/code><\/pre>\n\n\n\n<p>Create a variable for operator also (create a field).<\/p>\n\n\n\n<p>Finally, remove the number from the display, to indicate to the user that the second number can be entered:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>display.setText(\"\");<\/code><\/pre>\n\n\n\n<p>Try this (run the App). Does it work?<\/p>\n\n\n\n<p>You might want to <a href=\"https:\/\/www.w3schools.com\/java\/java_comments.asp\" target=\"_blank\" rel=\"noreferrer noopener\">add comments<\/a> on the working of the code now. This is important to understand your code later. Or if you have to present\/explain it to somebody else. Use the explanation from this tutorial to add comments. An example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>operand1 = display.getText(); \/\/ store the number entered first in variable operand1<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Perform calculation when equal button pressed<\/h3>\n\n\n\n<p>Add an eventhandler to the button btnEq by double clicking it in the Design view. Then add this code in that eventhandler and create a variable for the second operand (add field in the class):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>operand2 = display.getText();\n<\/code><\/pre>\n\n\n\n<p>Until now we have stored the numbers (operand1 and 2) as Strings, which are text. To be able to do the calculation, they must be converted to real numbers. We will convert them to doubles. that can be done like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>double o1 = Double.parseDouble(operand1);<\/code><\/pre>\n\n\n\n<p>Do this for the second operand also, use variable o2 for that.<\/p>\n\n\n\n<p>The result can be calculated now. But first, we must determine what is the operator, using an <a href=\"https:\/\/www.w3schools.com\/java\/java_conditions.asp\" target=\"_blank\" rel=\"noreferrer noopener\">if-statement<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (operator==\"+\") ...<\/code><\/pre>\n\n\n\n<p>Then in case of the &#8216;+&#8217; we can write:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (operator==\"+\") result = o1 + o2;<\/code><\/pre>\n\n\n\n<p>Now we must display the result:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>display.setText(\"\"+result);<\/code><\/pre>\n\n\n\n<p>Check if it works (run the App).<\/p>\n\n\n\n<p>The reason <code>\"\"+result<\/code> is used above, is that this will convert the double to a String, which is the type of the parameter of <em>setText()<\/em>.<\/p>\n\n\n\n<p>Now we must do some work to make the other operators work also. Extend the if-statement with <strong>else if &#8230;,<\/strong> to make it work for subtraction (<a href=\"https:\/\/www.w3schools.com\/java\/java_conditions.asp\" target=\"_blank\" rel=\"noreferrer noopener\">read this you find need help<\/a>):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (operator==\"+\") result = o1 + o2;\nelse if (operator==\"-\") ...<\/code><\/pre>\n\n\n\n<p>Finalize this by adding the code to calculate the result. then add two more <strong>else if &#8230;<\/strong> parts to allow for multiplication and division operators to work.<\/p>\n\n\n\n<p>At the end of the method empty the variables to allow to start over (for a next calculation):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>operand1 = \"\"; operand2 = \"\"; operator = \"\";<\/code><\/pre>\n\n\n\n<p>Try this (run the App). Does it work?<\/p>\n\n\n\n<p>You might notice that starting a next calculation does not work properly: if you start pressing number buttons, they will append to the result which is still displayed. Instead of this the results must be erased when the first button is pressed. For this we can introduce a helper variable, which will indicate if a result is visible. For this we can use a <a href=\"https:\/\/www.w3schools.com\/java\/java_booleans.asp\" target=\"_blank\" rel=\"noreferrer noopener\">boolean<\/a> variable, which is <em>true<\/em> if the result is visible, and <em>false<\/em> otherwise. Declare that as a class-variable (<a href=\"https:\/\/www.w3schools.com\/java\/java_class_attributes.asp\" target=\"_blank\" rel=\"noreferrer noopener\">class attribute<\/a>):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>boolean resultVisible = false;<\/code><\/pre>\n\n\n\n<p>And set that to true at the end of the eventhandler of btnEq:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>resultVisible = true;<\/code><\/pre>\n\n\n\n<p>Now, we can add an if-statement to the <em>processDigit()<\/em> method which in pseudo-code does:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if resultVisible is true:\n    clear the display\n    set resultVisible to false\n<\/code><\/pre>\n\n\n\n<p>Add this in real code to the beginning of the <em>processDigit()<\/em> method (it must be the first line of code). Make sure to use a <a href=\"https:\/\/www.w3schools.com\/java\/java_conditions.asp\" target=\"_blank\" rel=\"noreferrer noopener\">comparison operator<\/a> in the if.<\/p>\n\n\n\n<p>Check if you can do multiple calculations now.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Proper input of broken numbers (using the dot-button)<\/h3>\n\n\n\n<p>The eventhandler of btnDot could be improved by preventing that multiple dots can be input.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>String n = display.getText(); \/\/ get the text on the display\nif (n.contains(\".\")) return; \/\/ if it already contains a \".\" skip rest of this method\n<\/code><\/pre>\n\n\n\n<p>Add this at the beginning of the eventhandler for the button btnDot.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Make deletions possible<\/h3>\n\n\n\n<p>The btnC will simply delete the entire expression, exactly the same is what is being done after the calculation is displayed (at the end of the eventhandler of the btnEq. So add a method clear() to the class, and move the code from there to that. Then call the method at both spots.<\/p>\n\n\n\n<p>The btnDel will delete the last character added. The code below will accomplish that. Try to understand it, then add it to the eventhandler.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ remove last character on display:\nString tmp = display.getText();\nif (tmp.length()&gt;1) \/\/ if there is more than 1 character\n    display.setText( tmp.substring(0, tmp.length()-1) );\nelse \/\/ otherwise just make display empty\n    display.setText(\"\");<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">The &#8220;+\/-&#8221; button<\/h3>\n\n\n\n<p>The final button is the &#8220;+\/-&#8221; one. Add an eventhandler for that. For this we provide the pseudo code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>get first character of the text on display\nif first character is a minus sign, remove that\nelse, add a minus sign<\/code><\/pre>\n\n\n\n<p>You might want to get the text from the display into a temporal variable first, eg. with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>String tmp = display.getText();<\/code><\/pre>\n\n\n\n<p>Next, you can call the charAt() method of the <a href=\"https:\/\/www.w3schools.com\/java\/java_strings.asp\" target=\"_blank\" rel=\"noreferrer noopener\">String<\/a> tmp to retrieve the first character, this will be of type char (that is a <a href=\"https:\/\/www.w3schools.com\/java\/java_data_types.asp\" target=\"_blank\" rel=\"noreferrer noopener\">basic type<\/a>):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>char first = tmp.charAt(0);<\/code><\/pre>\n\n\n\n<p>After that you can construct the if-statement using the pseudo code.<\/p>\n\n\n\n<p>If the first character is a minus-sign, we can set the display to the remaining part of the String, so the substring starting with character 1 (which is the second character):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tmp.substring(1, tmp.length())<\/code><\/pre>\n\n\n\n<p>The else-part of the if-statment deals with the situation that there is no minus-sign. Then we need to add one:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>display.setText(\"-\"+tmp);<\/code><\/pre>\n\n\n\n<p>Try this, do some more calculations. Your App should be complete now. Congratualtions!<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to create a simple calculator in Java.<\/p>\n","protected":false},"author":1,"featured_media":4813,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","footnotes":""},"categories":[3],"tags":[514,516,107,95,509,515],"class_list":["post-4740","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-education","tag-calculator","tag-eclipse","tag-java","tag-programming","tag-start","tag-userinterface"],"blocksy_meta":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java tutorial: create a simple calculator - vanslooten.com<\/title>\n<meta name=\"description\" content=\"Java tutorial: create a simple calculator Learn how to create a simple calculator in Java using Eclipse.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/home.et.utwente.nl\/slootenvanf\/2022\/04\/06\/java-tutorial-create-calculator\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java tutorial: create a simple calculator - vanslooten.com\" \/>\n<meta property=\"og:description\" content=\"Java tutorial: create a simple calculator Learn how to create a simple calculator in Java using Eclipse.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/home.et.utwente.nl\/slootenvanf\/2022\/04\/06\/java-tutorial-create-calculator\/\" \/>\n<meta property=\"og:site_name\" content=\"vanslooten.com\" \/>\n<meta property=\"article:published_time\" content=\"2022-04-06T17:17:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-28T09:45:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"255\" \/>\n\t<meta property=\"og:image:height\" content=\"270\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Fjodor van Slooten\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fjodorvs\" \/>\n<meta name=\"twitter:site\" content=\"@fjodorvs\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Fjodor van Slooten\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"17 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/2022\\\/04\\\/06\\\/java-tutorial-create-calculator\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/2022\\\/04\\\/06\\\/java-tutorial-create-calculator\\\/\"},\"author\":{\"name\":\"Fjodor van Slooten\",\"@id\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/#\\\/schema\\\/person\\\/e62ff2d6beaa937dc9345a023eeb05dd\"},\"headline\":\"Java tutorial: create a simple calculator\",\"datePublished\":\"2022-04-06T17:17:50+00:00\",\"dateModified\":\"2025-07-28T09:45:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/2022\\\/04\\\/06\\\/java-tutorial-create-calculator\\\/\"},\"wordCount\":2229,\"publisher\":{\"@id\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/#\\\/schema\\\/person\\\/e62ff2d6beaa937dc9345a023eeb05dd\"},\"image\":{\"@id\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/2022\\\/04\\\/06\\\/java-tutorial-create-calculator\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/featured.png\",\"keywords\":[\"calculator\",\"eclipse\",\"java\",\"programming\",\"start\",\"userinterface\"],\"articleSection\":[\"Education\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/2022\\\/04\\\/06\\\/java-tutorial-create-calculator\\\/\",\"url\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/2022\\\/04\\\/06\\\/java-tutorial-create-calculator\\\/\",\"name\":\"Java tutorial: create a simple calculator - vanslooten.com\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/2022\\\/04\\\/06\\\/java-tutorial-create-calculator\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/2022\\\/04\\\/06\\\/java-tutorial-create-calculator\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/featured.png\",\"datePublished\":\"2022-04-06T17:17:50+00:00\",\"dateModified\":\"2025-07-28T09:45:29+00:00\",\"description\":\"Java tutorial: create a simple calculator Learn how to create a simple calculator in Java using Eclipse.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/2022\\\/04\\\/06\\\/java-tutorial-create-calculator\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/2022\\\/04\\\/06\\\/java-tutorial-create-calculator\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/2022\\\/04\\\/06\\\/java-tutorial-create-calculator\\\/#primaryimage\",\"url\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/featured.png\",\"contentUrl\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/featured.png\",\"width\":255,\"height\":270},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/2022\\\/04\\\/06\\\/java-tutorial-create-calculator\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java tutorial: create a simple calculator\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/#website\",\"url\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/\",\"name\":\"vanslooten.com\",\"description\":\"Personal website of Fjodor van Slooten\",\"publisher\":{\"@id\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/#\\\/schema\\\/person\\\/e62ff2d6beaa937dc9345a023eeb05dd\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/#\\\/schema\\\/person\\\/e62ff2d6beaa937dc9345a023eeb05dd\",\"name\":\"Fjodor van Slooten\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/wp-content\\\/uploads\\\/2019\\\/06\\\/2018-08-24-13.33.38_small.jpg\",\"url\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/wp-content\\\/uploads\\\/2019\\\/06\\\/2018-08-24-13.33.38_small.jpg\",\"contentUrl\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/wp-content\\\/uploads\\\/2019\\\/06\\\/2018-08-24-13.33.38_small.jpg\",\"width\":300,\"height\":214,\"caption\":\"Fjodor van Slooten\"},\"logo\":{\"@id\":\"https:\\\/\\\/home.et.utwente.nl\\\/slootenvanf\\\/wp-content\\\/uploads\\\/2019\\\/06\\\/2018-08-24-13.33.38_small.jpg\"},\"sameAs\":[\"http:\\\/\\\/vanslooten.com\",\"https:\\\/\\\/x.com\\\/fjodorvs\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java tutorial: create a simple calculator - vanslooten.com","description":"Java tutorial: create a simple calculator Learn how to create a simple calculator in Java using Eclipse.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/home.et.utwente.nl\/slootenvanf\/2022\/04\/06\/java-tutorial-create-calculator\/","og_locale":"en_US","og_type":"article","og_title":"Java tutorial: create a simple calculator - vanslooten.com","og_description":"Java tutorial: create a simple calculator Learn how to create a simple calculator in Java using Eclipse.","og_url":"https:\/\/home.et.utwente.nl\/slootenvanf\/2022\/04\/06\/java-tutorial-create-calculator\/","og_site_name":"vanslooten.com","article_published_time":"2022-04-06T17:17:50+00:00","article_modified_time":"2025-07-28T09:45:29+00:00","og_image":[{"width":255,"height":270,"url":"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/featured.png","type":"image\/png"}],"author":"Fjodor van Slooten","twitter_card":"summary_large_image","twitter_creator":"@fjodorvs","twitter_site":"@fjodorvs","twitter_misc":{"Written by":"Fjodor van Slooten","Est. reading time":"17 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/home.et.utwente.nl\/slootenvanf\/2022\/04\/06\/java-tutorial-create-calculator\/#article","isPartOf":{"@id":"https:\/\/home.et.utwente.nl\/slootenvanf\/2022\/04\/06\/java-tutorial-create-calculator\/"},"author":{"name":"Fjodor van Slooten","@id":"https:\/\/home.et.utwente.nl\/slootenvanf\/#\/schema\/person\/e62ff2d6beaa937dc9345a023eeb05dd"},"headline":"Java tutorial: create a simple calculator","datePublished":"2022-04-06T17:17:50+00:00","dateModified":"2025-07-28T09:45:29+00:00","mainEntityOfPage":{"@id":"https:\/\/home.et.utwente.nl\/slootenvanf\/2022\/04\/06\/java-tutorial-create-calculator\/"},"wordCount":2229,"publisher":{"@id":"https:\/\/home.et.utwente.nl\/slootenvanf\/#\/schema\/person\/e62ff2d6beaa937dc9345a023eeb05dd"},"image":{"@id":"https:\/\/home.et.utwente.nl\/slootenvanf\/2022\/04\/06\/java-tutorial-create-calculator\/#primaryimage"},"thumbnailUrl":"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/featured.png","keywords":["calculator","eclipse","java","programming","start","userinterface"],"articleSection":["Education"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/home.et.utwente.nl\/slootenvanf\/2022\/04\/06\/java-tutorial-create-calculator\/","url":"https:\/\/home.et.utwente.nl\/slootenvanf\/2022\/04\/06\/java-tutorial-create-calculator\/","name":"Java tutorial: create a simple calculator - vanslooten.com","isPartOf":{"@id":"https:\/\/home.et.utwente.nl\/slootenvanf\/#website"},"primaryImageOfPage":{"@id":"https:\/\/home.et.utwente.nl\/slootenvanf\/2022\/04\/06\/java-tutorial-create-calculator\/#primaryimage"},"image":{"@id":"https:\/\/home.et.utwente.nl\/slootenvanf\/2022\/04\/06\/java-tutorial-create-calculator\/#primaryimage"},"thumbnailUrl":"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/featured.png","datePublished":"2022-04-06T17:17:50+00:00","dateModified":"2025-07-28T09:45:29+00:00","description":"Java tutorial: create a simple calculator Learn how to create a simple calculator in Java using Eclipse.","breadcrumb":{"@id":"https:\/\/home.et.utwente.nl\/slootenvanf\/2022\/04\/06\/java-tutorial-create-calculator\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/home.et.utwente.nl\/slootenvanf\/2022\/04\/06\/java-tutorial-create-calculator\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/home.et.utwente.nl\/slootenvanf\/2022\/04\/06\/java-tutorial-create-calculator\/#primaryimage","url":"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/featured.png","contentUrl":"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2022\/04\/featured.png","width":255,"height":270},{"@type":"BreadcrumbList","@id":"https:\/\/home.et.utwente.nl\/slootenvanf\/2022\/04\/06\/java-tutorial-create-calculator\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/home.et.utwente.nl\/slootenvanf\/"},{"@type":"ListItem","position":2,"name":"Java tutorial: create a simple calculator"}]},{"@type":"WebSite","@id":"https:\/\/home.et.utwente.nl\/slootenvanf\/#website","url":"https:\/\/home.et.utwente.nl\/slootenvanf\/","name":"vanslooten.com","description":"Personal website of Fjodor van Slooten","publisher":{"@id":"https:\/\/home.et.utwente.nl\/slootenvanf\/#\/schema\/person\/e62ff2d6beaa937dc9345a023eeb05dd"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/home.et.utwente.nl\/slootenvanf\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/home.et.utwente.nl\/slootenvanf\/#\/schema\/person\/e62ff2d6beaa937dc9345a023eeb05dd","name":"Fjodor van Slooten","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2019\/06\/2018-08-24-13.33.38_small.jpg","url":"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2019\/06\/2018-08-24-13.33.38_small.jpg","contentUrl":"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2019\/06\/2018-08-24-13.33.38_small.jpg","width":300,"height":214,"caption":"Fjodor van Slooten"},"logo":{"@id":"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-content\/uploads\/2019\/06\/2018-08-24-13.33.38_small.jpg"},"sameAs":["http:\/\/vanslooten.com","https:\/\/x.com\/fjodorvs"]}]}},"_links":{"self":[{"href":"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-json\/wp\/v2\/posts\/4740","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-json\/wp\/v2\/comments?post=4740"}],"version-history":[{"count":37,"href":"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-json\/wp\/v2\/posts\/4740\/revisions"}],"predecessor-version":[{"id":4814,"href":"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-json\/wp\/v2\/posts\/4740\/revisions\/4814"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-json\/wp\/v2\/media\/4813"}],"wp:attachment":[{"href":"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-json\/wp\/v2\/media?parent=4740"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-json\/wp\/v2\/categories?post=4740"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/home.et.utwente.nl\/slootenvanf\/wp-json\/wp\/v2\/tags?post=4740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}