Skip to main content

Featured

How to make a simple calculator with GUI in JAVA (using Netbeans)?

First of all create a new package , then create a simple class. Then create a new JFrame Form class. On the right side you will find every tool needed like buttons textfield radio buttons etc. We'll need the buttons and text field and a JLabel Drag and drop required buttons you want to appear on the calculator eg. 1,2,3,4,5,6,7,8,9,0,+,-,*,/,=,AC,OFF arrange them all then on double clicking any button you will enter the source code tab, for digits 0-9 you have to write this code:         String Number =answer.getText() +  one.getText();         answer.setText(Number); Here answer is the jTextFields variable name you can right click the text field and click change variable name. similarly you have to set the code for every digit then for operations you have to write the code: for "+" operation: firstnumber = Double.parseDouble(answer.getText());         jLabel1.setText(answer.getText()+"+"); ...

Helpfull Things

Some Basic Commands to make your program look better






C++ small codes which you can forget,


"  \n = line break, used in "cout<<"\n Hello world ";
if you want any integer which already declared to be the output

like when you want your answer of sum of 2 numbers

L=n+m
to be the output

like you want this

" Your answer is ____ "
in the blank there will be your answer of n+m=L
so you will type this in cout

cout<<"Your answer is "<<L<<"   ";



If you want to align your output in center or whatever position you like
first include this library below and set cout width

#include <iomanip>
cout << left <<setw(35)  ;



For user defined array.
int size;
cin>>size;
int * array;
array = new int[size];




Comments