IDE,till now we have worked on the simple Text Editor,but now we need to use a Development Environment to add more functionality to our code.Here are the steps need to follow while installing and running a Netbeans IDE.
1.First of all we need to install an IDE(Integrated Development Environment),right now we are using Netbeans IDE version 7.2.1.
2.After IDE is installed,click on File>New Project.
3.Now the New Project window will open,in Projects click on Java Application,then click Next.
4.Now New Java Application window will open,give a name to your Project as required,click Next.
5.You are ready to use IDE for writing Java Codes.
6.Now as we want to build frames using IDE,so right click on the Package you created,and now Open New>JFrame Form.
7.Give the name you want to give to your Frame form,click Next.
8.Now,your form design window is ready to use,now you can drag and drop your Controls on your Window.
9.You can change the variable name,the control name you selected ,double click on the Control you had selected,and write the code.It is the example of how you can drag and drop controls in design window.
10.If you want to apply action listener on their control then you need to double click on the control.Then it move on source window and write the following code if you apply action listener on buttons and perform calculations.
WAP to add action listeners in calculator
private void btn1ActionPerformed(java.awt.event.ActionEvent evt) {
if(evt .getSource()==btn1)
{int num1,num2,res;
num1=Integer.parseInt(txt1.getText());
num2=Integer.parseInt(txt2.getText()) ;
res=num1+num2;
txt3.setText(Integer.toString(res));
}
}
private void btn2ActionPerformed(java.awt.event.ActionEvent evt) {
if(evt.getSource()==btn2)
{
txt1.setText("");
txt2.setText("");
txt3.setText("");
txt1.requestFocus();
}
}
private void btn3ActionPerformed(java.awt.event.ActionEvent evt) {
if(evt .getSource()==btn3)
{int num1,num2,res;
num1=Integer.parseInt(txt1.getText());
num2=Integer.parseInt(txt2.getText()) ;
res=num1*num2;
txt3.setText(Integer.toString(res));
}
}
private void btn4ActionPerformed(java.awt.event.ActionEvent evt) {
if(evt .getSource()==btn4)
{int num1,num2,res;
num1=Integer.parseInt(txt1.getText());
num2=Integer.parseInt(txt2.getText()) ;
res=num1/num2;
txt3.setText(Integer.toString(res));
}
}
private void btn5ActionPerformed(java.awt.event.ActionEvent evt) {
if(evt .getSource()==btn5)
{int num1,num2,res;
num1=Integer.parseInt(txt1.getText());
num2=Integer.parseInt(txt2.getText()) ;
res=num1-num2;
txt3.setText(Integer.toString(res));
}
}
Output of this program:
1.First of all we need to install an IDE(Integrated Development Environment),right now we are using Netbeans IDE version 7.2.1.
2.After IDE is installed,click on File>New Project.
5.You are ready to use IDE for writing Java Codes.
6.Now as we want to build frames using IDE,so right click on the Package you created,and now Open New>JFrame Form.
7.Give the name you want to give to your Frame form,click Next.
8.Now,your form design window is ready to use,now you can drag and drop your Controls on your Window.
10.If you want to apply action listener on their control then you need to double click on the control.Then it move on source window and write the following code if you apply action listener on buttons and perform calculations.
private void btn1ActionPerformed(java.awt.event.ActionEvent evt) {
if(evt .getSource()==btn1)
{int num1,num2,res;
num1=Integer.parseInt(txt1.getText());
num2=Integer.parseInt(txt2.getText()) ;
res=num1+num2;
txt3.setText(Integer.toString(res));
}
}
private void btn2ActionPerformed(java.awt.event.ActionEvent evt) {
if(evt.getSource()==btn2)
{
txt1.setText("");
txt2.setText("");
txt3.setText("");
txt1.requestFocus();
}
}
private void btn3ActionPerformed(java.awt.event.ActionEvent evt) {
if(evt .getSource()==btn3)
{int num1,num2,res;
num1=Integer.parseInt(txt1.getText());
num2=Integer.parseInt(txt2.getText()) ;
res=num1*num2;
txt3.setText(Integer.toString(res));
}
}
private void btn4ActionPerformed(java.awt.event.ActionEvent evt) {
if(evt .getSource()==btn4)
{int num1,num2,res;
num1=Integer.parseInt(txt1.getText());
num2=Integer.parseInt(txt2.getText()) ;
res=num1/num2;
txt3.setText(Integer.toString(res));
}
}
private void btn5ActionPerformed(java.awt.event.ActionEvent evt) {
if(evt .getSource()==btn5)
{int num1,num2,res;
num1=Integer.parseInt(txt1.getText());
num2=Integer.parseInt(txt2.getText()) ;
res=num1-num2;
txt3.setText(Integer.toString(res));
}
}
Output of this program:
No comments:
Post a Comment