Java programs using controls in Netbeans
➢ Open your project, on left side under the Projects tab > right click on Source Packages > New > jFrame Form.
➢ Type the name of the frame under Class Name. Click Finish (frame name will be different for different
programs)
1. Design a simple application to display the input by the user. (class name – Hello)
Source code for Show button:
private void jButton1ActionPerformed([Link] evt) {
// TODO add your handling code here:
String name = [Link]();
[Link]("Hello "+name);
}
Output:
2. Design an application to enter customer’s address.
Source code for Submit button:
private void jButton1ActionPerformed([Link] evt) {
String name=[Link]();
String hno=[Link]();
String building=[Link]();
String street=[Link]();
String city=[Link]();
String state=[Link]();
[Link]("Name: "+name+"\nHouse No.: "+hno+"\nBuilding: "+building+"\nStreet:
"+street+"\nCity: "+city+"\nState: "+state);
}
Source code for Exit button:
private void jButton2ActionPerformed([Link] evt) {
[Link](0);
}
Output:
3. Design a form to calculate the area and the perimeter of a circle whose radius is entered by the user.
Source code:
import [Link]; //This imports the method
public class circle extends [Link]
For Area button:
private void jButton1ActionPerformed([Link] evt) {
String r=[Link]();
float radius=[Link](r); //The input is taken as string but convert it into float value by
using parseint method of Float class
double area=3.14*radius*radius;
[Link](this, "Area of the circle is "+area); //Display the message box
with the result
For Perimeter button:
private void jButton2ActionPerformed([Link] evt) {
String r=[Link]();
float radius=[Link](r);
double perimeter=2*3.14*radius;
[Link](this, "Perimeter of the circle is "+perimeter);
Output:
4. Design a standard calculator for performing basic mathematical operations.
For Addition:
private void jButton1ActionPerformed([Link] evt) {
double number1,number2,result;
number1=[Link]([Link]());
number2=[Link]([Link]());
result=number1+number2;
[Link]([Link](result)); }
For Subtraction:
private void jButton1ActionPerformed([Link] evt) {
double number1,number2,result;
number1=[Link]([Link]());
number2=[Link]([Link]());
result=number1-number2;
[Link]([Link](result)); }
For Multiplication:
private void jButton1ActionPerformed([Link] evt) {
double number1,number2,result;
number1=[Link]([Link]());
number2=[Link]([Link]());
result=number1*number2;
[Link]([Link](result)); }
For Division:
private void jButton1ActionPerformed([Link] evt) {
double number1,number2,result;
number1=[Link]([Link]());
number2=[Link]([Link]());
result=number1/number2;
[Link]([Link](result)); }
For Reset:
private void jButton1ActionPerformed([Link] evt) {
[Link](“ ”);
[Link](“ ”);
[Link](“ ”);
Output:
5. Design an application to calculate the simple interest.
For Calculate:
private void jButton1ActionPerformed([Link] evt) {
double principal, rate, interest;
byte time;
principal = [Link]([Link]());
rate = [Link]([Link]());
time = [Link]([Link]());
interest = (principal*rate*time)/100;
[Link]([Link](interest));
}
For Reset:
private void jButton3ActionPerformed([Link] evt) {
[Link]("");
[Link]("");
[Link]("");
}
Output:
6. Design an application to find maximum number among the two numbers entered by the user.
Source code:
import [Link]; //This imports the method
public class maximum extends [Link]
For Find Maximum:
private void jButton1ActionPerformed([Link] evt) {
int n1=[Link]([Link]());
int n2=[Link]([Link]());
int max;
if (n1>n2)
max=n1;
else
max=n2;
[Link](this,"Maximun Number is "+max);
}
For Reset:
private void jButton2ActionPerformed([Link] evt) {
[Link]("");
[Link]("");
}
For Exit:
private void jButton3ActionPerformed([Link] evt) {
[Link](0);
}
Output:
7. Design an application to use ‘if’ statement with multiple test conditions.
Source code:
import [Link]; //This imports the method
public class paymentmethod extends [Link]
For Submit:
private void jButton1ActionPerformed([Link] evt) {
double payment = [Link]([Link]());
String msg;
if ([Link]())
msg="Payment will be made by Credit Card";
else if ([Link]())
msg="Payment will be made by Debit Card";
else if ([Link]())
msg="Payment is Cash on Delivery";
else if ([Link]())
msg="Payment will be made later by the Amazon Pay";
else
msg="Payment will be through EMI";
[Link](this,"Rs."+payment+" is the payment amount. "+msg);
}
For Exit:
private void jButton2ActionPerformed([Link] evt) {
[Link](0);
}
8. Design an application to use ‘Switch’ statement – GST Calculator.
For Calculate:
private void jButton1ActionPerformed([Link] evt) {
double amount;
double billamount = [Link]([Link]());
switch ([Link]()){
case 0: amount=0.03*billamount;//3% GST
break;
case 1: amount=0.05*billamount;//5% GST
break;
case 2: amount=0.10*billamount;//10% GST
break;
case 3: amount=0.12*billamount;//12% GST
break;
default: amount=0;//No GST
}
[Link]([Link](amount));
[Link]([Link](billamount+amount));
}
For Exit:
private void jButton2ActionPerformed([Link] evt) {
[Link](0);
}
Output: