Javascript required
Skip to content Skip to sidebar Skip to footer

How to Make a Calculator in Java Using Bluej

  • Create a folder/directory using Microsoft Explorer.

    If this directory (say C:\CSC211) does not exist yet, use the Microsoft Explorer to create it. First start Explorer and go to C:\ (the root directory of C drive). Then under File, select New, and Folder.

    Change the name of the folder from "New Folder" to "CSC211".

  • Invoke BlueJ.

    Start BlueJ by finding and double clicking on its icon. If you followed the installation directions for home, it will have an icon on the desktop. In the computer labs, select Course Applications, CSC, then BlueJ.

  • Create a new project.

    In BlueJ's top menu bar, select Project and New.... to get the New Project Dialog. In Look In box, find and select the CSC211 folder that you created in Step 1. This may require you to go up/down the directory tree a few times. Enter the name of the project (say "HelloWorld") in File name and click on Create.

    The Project Display Area to the middle right should turn white, and an icon that looks like a piece of paper should appear.

  • Create a new class. Click on the button New Class... to obtain the Create New Class Dialog. Enter "HelloWorld" in the Class Name textbox, and make sure that the Class radio button is selected. Then click on the OK button.

    A yellow icon with the lable HelloWorld and diagonal lines should appear.

  • Open the editor for the class. Double click on the yellow HelloWorld icon to open the editor for that class.
  • Modify the code for the class. When you open the HelloWorld Class, you will see some sample code for the class, including an instance variable x, a constructor HelloWorld, and the method named sampleMethod. This code may be interesting the first time you see it, but it is totally worthless. Select all of the code and delete it. Then add your code. For example, the HelloWorld program would be:
                          
  • Compile the class. Click on the Compile button at the top of the editor. You should get the message "Class compiled - no syntax erors."

  • Run the application. Go back to the main BlueJ window. If you don't see it on the desktop screen, look at the bottom of the monitor screen -- there are two BlueJ windows. Then, right click on the yellow HelloWorld icon, and select void main(args) to run the main method.

    You will get the Method Call Dialog. Since you don't have any command line arguments for this method, simply click on OK.
    Note: If your program (or method) takes arguments and you want to enter them, type in values separated by commas.

    You will get the Terminal Window with the message "Hello, world!"

    If you like to save the output to a file, select Options and Save to file...  Specify the name of the file in File name, such as "output.txt", and press Save.

  • Get out of BlueJ. Close the Terminal Window, the Editor, and the Main BlueJ Window. The console window that opened when you invoked BlueJ should close automatically.
  • How to Make a Calculator in Java Using Bluej

    Source: http://facweb.cs.depaul.edu/noriko/howto-bluej.html