![]() IntNum2=Integer.parseInt(ansTextField.getText()) ĪtText(Integer.toString(intNum1 + intNum2)) ĪtText(Integer.toString(intNum1 - intNum2)) ![]() if the current value of strOperator is + add the two numbers, if it's value is. get the current value of the text field and assign it as a value of intNum2 if the name of the control that recieves an event is equals button store "-" in the strOperator variable then clear the text field if it is minusButton, get the value displayed in the textfield and place it IntNum1=Integer.parseInt(ansTextField.getText()) Store "+" in the strOperator variable then clear the text field if it is plusButton, get the value displayed in the textfield and place it I just leave that to you to figure outĪtText(ansTextField.getText() + twoButton.getText()) you can add else ifs for numbers 3 to 9. if the name of the control is twoButton, display 2 in the textfield if the name of the control that recieves an event is oneButton, display 1 in the textfieldĪtText(ansTextField.getText() + oneButton.getText()) getSource determines the name of the control that recieves an event Public void actionPerformed(ActionEvent e) SetDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) JTextField ansTextField=new JTextField("",18) īorderLayout border=new BorderLayout(5,5) įlowLayout flow=new FlowLayout(FlowLayout.RIGHT,10,10) Public class Calc extends JFrame implements ActionListener creates a class named Calc and prepares it to accept an event swing for frame, awt for controls, and event for button events Press Ctrl + A to select all the codes, then Press Delete. A Window containing default BlueJ source code will then appear. Click New Class>Select Class in the class type radio buttons then enter Calc in the Class Name textbox.Ħ. ![]() Click Project>New Project>For the sake of example, let’s use Java as a project name.Ĥ. Download BlueJ installer from then install it.ģ. In this project we’ll be using BlueJ as our Java Development Tool.ġ. We are going to be making simple programming projects starting from now and for our first project, let’s make a simplest calculator using Java. I missed blogging somehow and this year I figure I’ll get back to blogging again. I’d been very busy with work in these past few years that I haven’t had time to blog.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |