Remember to explicitly call your parent's constructor! Good style.The first big piece of making your GUI will be to fill in the constructor. JTextField is somewhat like JLabel, but looks a little different (and can by default be edited by the user) To act as the "display" of your calculator. This will make it easy to loop through the buttons and can reduce the amount of code you right. As you will be using several buttons, it might be convenient (but not necessary) to use an array of JButton objects. You'll also likely want some instances of theĬlass to represent the buttons of your calculator. At the very least, you'll likely want an instance of the Calculator engine to perform the mathematical operations!.Try to think about what variable you might need you can also add more later as you discover you need them! You will need a number of these to get your calculator working. Your CalculatorGUI should should extend the built-inĪs always when making classes, the next step is to declare your instance variables. Remember you will need to import the necessary packages ( java.awt.*, javax.swing.*, and .*) for building a GUI.However, this class does not provide any input/output mechanism needed to interact with the calculator-that's what you will be doing! Skim through the class to get a sense for how it works and what methods it has you will be using these methods to perform necessary operations in response to user inputs, as well as to get the output to show to the user.Ī simple tester class to run the CalculatorGUI program (which is what you will write!)įor this lab, you will be making one new class: a CalculatorGUI Details for building this class are below: There are methods to operate on the value (that is: to add, subtract, multiply, or divide). For example, this class contains a variable that represents the result computed so far. This class represents the "engine" underlying the calculator, with methods and variables to represent the calculator's core operations. This project will supply you with the following classes: You will need to download and extract the BlueJ project from the
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |