Calculator Program In Java Using Actionlistener

Posted : admin On 17.09.2019

Hello great code am in my first year and been given this assignment of a loan calculator am not a novice when it comes to programming expect with weeks of java been tought i stilll feel like i know nothing, the tutor is asking for a number of classes and super classes and i feel like i havent got a clue how or where to start, if you have any advice i would very much appreciate, thank you. A simple calculator /* This program is a part of the companion code for Core Java 8th ed. (This program is free software: you can redistribute it and/or modify it under. Private class InsertAction implements ActionListener { public void actionPerformed(ActionEvent event) { String input = event.

Calculator Program In Java Using Actionlistener

Contributed by and Tomas Pavek, maintained by Ruth Kusterer This beginner tutorial teaches you how to build a simple GUI with back-end functionality. You will learn how to develop a graphical user interface and how to add functionality to the buttons and fields used. A basic understanding of the Java Programming Language is required. This document takes you through the fundamental concepts of GUI creation and takes the approach taken in many self learning books. We will work through the layout and design of a GUI and add a few Buttons and Text Boxes.

The Text Boxes will be used for receiving user input and also for displaying the program output. The Button will initiate the functionality built into the front end. The application we create will be a simple but functional calculator. Expected duration: 15 minutes. Tutorial Exercises. Prerequisites. The use should have basic skills in the Java language.

The user should be comfortable with using the NetBeans IDE. The user should have already completed the tutorial. Software Needed for This Tutorial The NetBeans GUI Builder comes bundled with NetBeans IDE, and no special setup is necessary. Make sure you have the following software installed on your computer:.

NetBeans IDE 6.0. In order to install and run NetBeans IDE 6.0, you also require the Java SE Development Kit (JDK) version 5.0 or higher.

You can get a version of JDK for your platform at:. Exercise 1: Creating a Project The first step is to create a Project, we will name our project NumberAddition. Choose File New Project. Alternately, you can click the New Project icon in the IDE toolbar. In the Categories pane, select the General node. In the Projects pane, choose Java Application.

Enter NumberAddition in the Project Name field and specify a path e.g. In your home directory as the project location. Ensure that the Set as Main Project checkbox is selected. Deselect Create Main Class if it is selected. Click Finish. Exercise 2: Building the Front End After creating the new application, you may have noticed that the Source Packages folder in the Projects window contains an empty node. Ggu axpile v3 02 winall-tbe software update. To proceed with building our interface, we need to create a Java container within which we will place the other required GUI components.

In this step we'll create a container using the JFrame component and place the container in a new package. Create a JFrame container. In the Projects window, right-click the NumberAddition node and choose New JFrame Form. Enter NumberAdditionUI as the Class Name. Enter my.NumberAddition as the package. Click Finish. The IDE creates the NumberAdditionUI form and the NumberAdditionUI class within the NumberAdditionUI.java application, and opens the NumberAdditionUI form in the GUI Builder.

Notice that the my.NumberAddition package replaces the default package. Adding Components: Making of the Front End Next we are going to populate our application's front end with one JPanel, and three JLabels, JTextFields and JButtons each. The JFrame with the aforementioned components will look like this. Select Windows Palette to open the Palette if you don't see it. You use the Palette to drag and drop UI components to the design area.

Start by selecting a JPanel from the Palette and drop it onto the JFrame. While the JPanel is highlighted, go to the Properties window and click the '.'

Button next to Border to choose a border style. In the Border dialog, select Titled Border from the list, and type in Number Addition in the Title field. Click OK to save the changes and exit the dialog. You should now see an empty titled JFrame that says Number Addition like in the screenshot. Look at the screenshot and add three JLabels, three JTextFields and three JButtons as you see above.

What Is Addactionlistener In Java

Renaming the Components In this step we are going to rename the components that were just added to the JFrame. Double-click on jLabel1 and change the text property to First Number. Double-click on jLabel2 and change the text to Second Number.

Calculator Program In Java Using Actionlistener

Double-click on jLabel3 and change the text to Result. Double-click on jTextField1 and remove the sample text in the text field. You may have to resize the jTextField1 to its original size. Repeat this step for jTextField2 and jTextField3. Double-click on jButton1 and rename it Clear. Double-click on jButton2 and rename it Add.

Program To Create Calculator In Java

Actionlistener

Double-click on jButton3 and rename it Exit Your Finished GUI should now look like this: Exercise 3: Adding Functionality In this exercise we are going to give functionality to the Add, Clear, and Exit buttons. The jTextField1 and jTextField2 boxes will be used for user input and jTextField3 for program output - what we are creating is a very simple calculator.