0% found this document useful (0 votes)
5 views

JAVA PROGRAM-2

The document outlines the design of multiple GUI applications using Swing controls for various functionalities, including calculating simple interest, converting mass and temperature, checking number properties (positive/negative, even/odd), voting eligibility, and determining grades based on percentage marks. Each application includes labeled input fields, buttons for actions (calculate, refresh), and event handling methods for processing user inputs. The document provides detailed specifications for each GUI component and the corresponding Java code for functionality implementation.

Uploaded by

ppanigrahi9355
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

JAVA PROGRAM-2

The document outlines the design of multiple GUI applications using Swing controls for various functionalities, including calculating simple interest, converting mass and temperature, checking number properties (positive/negative, even/odd), voting eligibility, and determining grades based on percentage marks. Each application includes labeled input fields, buttons for actions (calculate, refresh), and event handling methods for processing user inputs. The document provides detailed specifications for each GUI component and the corresponding Java code for functionality implementation.

Uploaded by

ppanigrahi9355
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Design a GUI application, to input the Principal amount, rate of interest, time period, Find

the simple interest as per the given value

Enter the Principal Amount :

Enter the Rate of interest (%) :

Enter the Time period :

Simple Interest :

CALCULATE REFRESH
Swing Controls used in the GUI Application :
1. jLabel1 : 6. jTextField1 :
Properties : Properties :
Text – “Enter the Principal Amount : ” Change variable name – “T1”
Font - Bold, 20 Text – “ ”
2. jLabel2 : Font - Bold, 20
Properties : 7. jTextField1 :
Text – “Enter the Rate of Interest : ” Properties :
Font - Bold, 20 Change variable name – “T2”
3. jLabel3 : Text – “ ”
Properties : Font - Bold, 20
Text – “Enter the time period: ” 8. jTextField1 :
Font - Bold, 20 Properties :
4. jLabel4 : Change variable name – “T3”
Properties : Text – “ ”
Text – “Simple Interest: ” Font - Bold, 20
Font - Bold, 20 9. jButton1 :
5. jLabel5 : Properties :
Properties : Text – “CALCULATE”
Text – “ ” Font - Bold, 20
Font - Bold, 20 10. jButton2 :
Properties :
Text – “REFRESH”
Font - Bold, 20
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
int P, R, T;
Double SI;
P = Integer.parseInt(T1.getTest());
R = Integer.parseInt(T2.getText());
T = Integer.parseInt(T3.getText());
SI = (P*R*T)/100;
jLabel4.setText(SI);
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)


{
T1.setText(“ “);
T2.setText(“ “);
T3.setText(“ “);
}
Design a GUI application, to enter the mass of an object in Kilogram and convert it into
Gram and vice versa.
Swing Controls used in the GUI Application :
1. jLabel1 :
Properties : KG
ENTER THE MASS : Gram
Text – “ENTER THE MASS : ”
Font - Bold, 20
2. jTextField1 :
Properties :
Change variable name – “T” CONVERT REFRESH
Text – “ ”
Font - Bold, 20
3. jRadioButton1 :
Text – “KG”
4. jRadioButton2 :
Text – “Gram”
5. jButton1 :
Properties :
Text – “CONVERT”
Font - Bold, 20
6. jButton2 :
Properties :
Text – “REFRESH”
Font - Bold, 20
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
int M;
M = Integer.parseInt(T.getText());
if(jRadioButton1.isSelected())
{
Double K = M/1000;
JOptionPane.showMessageDialog(this, “Mass in KG”+K);
}
else
{
Double G = M*1000;
JOptionPane.showMessageDialog(this, “Mass in gram“+G);
}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)


{
T.setText(“ “);
jRadioButton1.setSelected(FALSE);
jRadioButton2.setSelected(FALSE);
}
Design a GUI application, to enter the Temperature of an object in Celcious and convert it
into Farenhite and vice versa.
Swing Controls used in the GUI Application :
1. jLabel1 :
Properties : Celsius
Enter the Temperature :
Text – “ENTER THE MASS : ” Fahrenheit
Font - Bold, 20
2. jTextField1 :
Properties :
Change variable name – “T” CONVERT REFRESH
Text – “ ”
Font - Bold, 20
3. jRadioButton1 :
Text – “Celsius”
4. jRadioButton2 :
Text – “Farenheit”
5. jButton1 :
Properties :
Text – “CONVERT”
Font - Bold, 20
6. jButton2 :
Properties :
Text – “REFRESH”
Font - Bold, 20
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
int M;
M = Integer.parseInt(T.getText());
if(jRadioButton1.isSelected())
{
Double C = (5/9)*(M-32);
JOptionPane.showMessageDialog(this, “Temperature in Celsius”+C);
}
else
{
Double F = (9/5)*M+32;
JOptionPane.showMessageDialog(this, “Temperature in Fahrenheit“+F);
}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)


{
T.setText(“ “);
jRadioButton1.setSelected(FALSE);
jRadioButton2.setSelected(FALSE);
}
Design a GUI application, to enter a number and check whether it is positive or negative

Swing Controls used in the GUI Application :


1. jLabel1 :
Properties : Enter a Number :
Text – “Enter a Number : ”
Font - Bold, 20
2. jTextField1 :
Properties :
Change variable name – “T” Positive / Negative REFRESH
Text – “ ”
Font - Bold, 20
3. jButton1 :
Properties :
Text – “Positive / Negative”
Font - Bold, 20
4. jButton2 :
Properties :
Text – “REFRESH”
Font - Bold, 20
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
int N;
N = Integer.parseInt(T.getText();
if(N>0)
{
JOptionPane.showMessageDialog(this, N+” is a Positive number”);
}
else
{
JOptionPane.showMessageDialog(this, N+” is a Negative number”);
}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)


{
T.setText(“ “);
}
Design a GUI application, to enter a number and check whether it is Even / Odd.

Swing Controls used in the GUI Application :


1. jLabel1 :
Properties : Enter a Number :
Text – “Enter a Number : ”
Font - Bold, 20
2. jTextField1 :
Properties :
Change variable name – “T” Even / Odd REFRESH
Text – “ ”
Font - Bold, 20
3. jButton1 :
Properties :
Text – “Even / Odd”
Font - Bold, 20
4. jButton2 :
Properties :
Text – “REFRESH”
Font - Bold, 20
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
int N;
N = Integer.parseInt(T.getText();
if(N%2==0)
{
JOptionPane.showMessageDialog(this, N+” is a Even number”);
}
else
{
JOptionPane.showMessageDialog(this, N+” is a Odd number”);
}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)


{
T.setText(“ “);
}
Design a GUI application, to enter the age of a person and check whether the person is
eligible for voting or not.
Swing Controls used in the GUI Application :
1. jLabel1 :
Properties : Enter the Age :
Text – “Enter the Age : ”
Font - Bold, 20
2. jTextField1 :
Properties :
Change variable name – “T” Check Eligible for Voting REFRESH
Text – “ ”
Font - Bold, 20
3. jButton1 :
Properties :
Text – “Check Eligible for Voting”
Font - Bold, 20
4. jButton2 :
Properties :
Text – “REFRESH”
Font - Bold, 20
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
int A;
A = Integer.parseInt(T.getText();
if(A>=18)
{
JOptionPane.showMessageDialog(this, “The parson is eligible for voting”);
}
else
{
JOptionPane.showMessageDialog(this, “The person is not eligible for voting”);
}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)


{
T.setText(“ “);
}
Design a GUI application, to enter two number and find the greatest number
Swing Controls used in the GUI Application :
1. jLabel1 :
Properties :
Text – “Enter the Cost Price: ”
Font - Bold, 20
2. jLabel2 : Enter the Cost Price :
Properties :
Text – “Enter the Selling price : ”
Enter the Selling Price :
Font - Bold, 20
3. jTextField1 :
Properties :
Change variable name – “T1”
Text – “ ” Find the Profit / Loss REFRESH
Font - Bold, 20
4. jTextField2 :
Properties :
Change variable name – “T2”
Text – “ ”
Font - Bold, 20
3. jButton1 :
Properties :
Text – “Find the Profit / Loss”
Font - Bold, 20
4. jButton2 :
Properties :
Text – “REFRESH”
Font - Bold, 20
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
int CP, SP, P, L;
CP = Integer.parseInt(T1.getText();
SP = Integer.parseInt(T2.getText();
if(SP > CP)
{
P = SP – CP;
JOptionPane.showMessageDialog(this, P+“ rupees profit earned”);
}
else
{
L = CP – SP;
JOptionPane.showMessageDialog(this, L+“ rupees loss earned”);
}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)


{
T1.setText(“ “);
T2.setText(“ “);
}
Design a GUI application, to enter two number and find the greatest number
Swing Controls used in the GUI Application :
1. jLabel1 :
Properties :
Text – “Enter the 1st Number : ”
Font - Bold, 20
2. jLabel2 : Enter the 1st Number :
Properties :
Text – “Enter the 2nd Number : ”
Enter the 2nd Number :
Font - Bold, 20
3. jTextField1 :
Properties :
Change variable name – “T1”
Text – “ ” Find the Greatest Number REFRESH
Font - Bold, 20
4. jTextField2 :
Properties :
Change variable name – “T2”
Text – “ ”
Font - Bold, 20
3. jButton1 :
Properties :
Text – “Check Eligible for Voting”
Font - Bold, 20
4. jButton2 :
Properties :
Text – “REFRESH”
Font - Bold, 20
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
int A,B;
A = Integer.parseInt(T1.getText();
B = Integer.parseInt(T2.getText();
if(A>B)
{
JOptionPane.showMessageDialog(this, A+“ is Greatest”);
}
else
{
JOptionPane.showMessageDialog(this, B“ is Greatest”);
}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)


{
T1.setText(“ “);
T2.setText(“ “);
}
Design a GUI application, to enter three number and find the greatest number
Swing Controls used in the GUI Application :
1. jLabel1 :
Properties :
Text – “Enter the 1st Number : ”
Font - Bold, 20
2. jLabel2 :
Properties : Enter the 1st Number :
Text – “Enter the 2nd Number : ”
Font - Bold, 20
3. jLabel3 :
Properties : Enter the 2nd Number :
Text – “Enter the 3rd Number : ”
Font - Bold, 20
4. jTextField1 :
Properties : Enter the 3rd Number :
Change variable name – “T1”
Text – “ ”
Font - Bold, 20
5. jTextField2 :
Properties : Find the Greatest Number REFRESH
Change variable name – “T2”
Text – “ ”
Font - Bold, 20
6. jTextField3 :
Properties :
Change variable name – “T3”
Text – “ ”
Font - Bold, 20
3. jButton1 :
Properties :
Text – “Check Eligible for Voting”
Font - Bold, 20
4. jButton2 :
Properties :
Text – “REFRESH”
Font - Bold, 20
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
int A,B,C;
A = Integer.parseInt(T1.getText();
B = Integer.parseInt(T2.getText();
C = Integer.parseInt(T3.getText();
if(A>B && A>C)
{
JOptionPane.showMessageDialog(this, A+“ is Greatest”);
}
else if(B>A && B>C)
{
JOptionPane.showMessageDialog(this, B“ is Greatest”);
}
else
{
JOptionPane.showMessageDialog(this, C“ is Greatest”);

}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)


{
T1.setText(“ “);
T2.setText(“ “);
}
Design a GUI application, to enter the percentage mark of a student, find the Grade as
follow,
A1 -> >90%, A2 -> 81% - 90%, B1 -> 71% - 80%, B2 -> 61% - 70%, C1 -> 51% - 60%
C2 -> 41% - 50%, D -> 33% - 40%, E -> <= 32%

Swing Controls used in the GUI Application :


1. jLabel1 :
Properties :
Text – “Enter the Percentage Mark: ”
Font - Bold, 20
2. jLabel2 :
Properties : Enter the Percentage Mark :
Text – “Grade: ”
Font - Bold, 20
3. jLabel3 :
Properties : Grade :
Text – “ ”
Font - Bold, 20
4. jTextField1 :
Properties :
Change variable name – “T”
Text – “ ”
Find REFRESH
Font - Bold, 20
3. jButton1 :
Properties :
Text – “Find”
Font - Bold, 20
4. jButton2 :
Properties :
Text – “REFRESH”
Font - Bold, 20
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
int P;
P = Integer.parseInt(T.getText();
if(P > 90)
{ else if(P >=33)
jLabel3.setText(“A1”); {
} jLabel3.setText(“D”);
else if(P > 80)
{ }
jLabel3.setText(“A2”); else
} {
else if(P > 70) jLabel3.setText(“E”);
{ }
jLabel3.setText(“B1”);

} }
else if(P > 60)
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
{
{
jLabel3.setText(“B2”); T.setText(“ “);
}
}
else if(P > 50)
{
jLabel3.setText(“C1”);

}
else if(P > 40)
{
jLabel3.setText(“C2”);

}
Design a GUI application, to enter an alphabet and check whether it is vowel / consonant

Swing Controls used in the GUI Application :


1. jLabel1 :
Properties :
Text – “Enter the Alphabet : ”
Font - Bold, 20
2. jTextField1 :
Properties : Enter the Alphabet:
Change variable name – “T”
Text – “ ”
Font - Bold, 20
3. jButton1 :
Properties :
Text – “Vowel / Consonant”
Font - Bold, 20 Vowel / Consonant REFRESH
4. jButton2 :
Properties :
Text – “REFRESH”
Font - Bold, 20
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
String S = T.getText( );
switch(S)
{
case “a”:
JOptionPane.showMessageDialog(this, S+” is Vowel”);
break;
case “e”:
JOptionPane.showMessageDialog(this, S+” is Vowel”);
break;
case “i”:
JOptionPane.showMessageDialog(this, S+” is Vowel”);
break;
case “o”:
JOptionPane.showMessageDialog(this, S+” is Vowel”);
break;
case “u”:
JOptionPane.showMessageDialog(this, S+” is Vowel”);
break;
default:
JOptionPane.showMessageDialog(this, S+” is Consonant”);
}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)


{
T.setText(“ “);
}
Design a GUI application, to enter two number and an arithmetic operator, perform the arithmetic
operation as per the arithematic operator
Swing Controls used in the GUI Application :
1. jLabel1 :
Properties :
Text – “Enter the 1st number : ”
Font - Bold, 20
2. jLabel2 : Enter the 1st number :
Properties :
Text – “Enter the 2nd number : ”
Font - Bold, 20
3. jLabel3 :
Enter the 2nd number :
Properties :
Text – “Enter the arithmetic operator : ”
Font - Bold, 20 Enter the Arithmetic Operator :
4. jTextField1 :
Properties :
Change variable name – “T1”
Text – “ ”
Font - Bold, 20
5. jTextField2 :
Properties :
Change variable name – “T2”
RESULT REFRESH
Text – “ ”
Font - Bold, 20
6. jTextField3 :
Properties :
Change variable name – “T3”
Text – “ ”
Font - Bold, 20
3. jButton1 :
Properties :
Text – “RESULT”
Font - Bold, 20
4. jButton2 :
Properties :
Text – “REFRESH”
Font - Bold, 20
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
int A, B, C; private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
A = Integer.parseInt(T1.getText( )); {
B = Integer.parseInt(T2.getText( )); T1.setText(“ “);
String S = T3.getText( ); T2.setText(“ “);
switch(S) T3.setText(“ “);
{ }
case “+”:
c = A + B;
JOptionPane.showMessageDialog(this, A + “+” + B + “=“ + C);
break;
case “-”:
c = A - B;
JOptionPane.showMessageDialog(this, A + “-” + B + “=“ + C);
break;
case “*”:
c = A * B;
JOptionPane.showMessageDialog(this, A + “*” + B + “=“ + C);
break;
case “/”:
c = A / B;
JOptionPane.showMessageDialog(this, A + “/” + B + “=“ + C);
break;
case “%”:
c = A % B;
JOptionPane.showMessageDialog(this, A + “%” + B + “=“ + C);
break;
default:
JOptionPane.showMessageDialog(this,”Invalid Operator”);
}
}
Design a GUI application as follow, The customeris given a discount on the Bill Amount depending upon the customer type selected
from the combobox.. Discount is calculated as follow,
Customer Type Discount
Platinum 30% Swing Controls used in the GUI Application :
1. jLabel1 :
Gold 20%
Properties :
Silver 10% Text – “Bill Amount : ”
New Customer No Discount Font - Bold, 20
2. jLabel2 :
Properties :
Text – “Customer Type : ”
Font - Bold, 20
3. jLabel3 :
Properties :
Bill Amount : Text – “Final Amount : ”
Font - Bold, 20
4. jLabel4 :
Properties :
Customer Type : Text – “ ”
Font - Bold, 20
5. jTextField1 :
Properties :
Change variable name – “T”
Calculate Final Amount REFRESH Text – “ ”
Font - Bold, 20
6. jCombobox1 :
Properties :
Change variable name – “C”
Final Amount : Model – “Platinum”, “Gold”, “Silver”, “New Member”
7. jButton1 :
Properties :
Text – “RESULT”
Font - Bold, 20
8. jButton2 :
Properties :
Text – “REFRESH”
Font - Bold, 20
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
int A;
double D;
A = Integer.parseInt(T1.getText( ));
if(C.getSelected( ) == “Platinum”)
{
D = A - A*0.3;
jLabel4.setText(D);
}
else if((C.getSelected( ) == “Gold”)
{
D = A - A*0.2;
jLabel4.setText(D);
}
else if((C.getSelected( ) == “Silver”)
{
D = A - A*0.1;
jLabel4.setText(D);
}
else
{
jLabel4.setText(A);
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)


{
T.setText(“ “);
jLabel1.setText(“ “);
}
A book publishing house decided to design a GUI Application as follow,
You have to accept book code, Title, Author and quantity sold from the user. The price will be generated depending upon the book code.
The net price should be calculated on the basis of discount given,
Bookseller 25%
School 20%
Customer 5%

Book Code :

Title of Book :

Author of Book :

Price of Book :

Customer Type :

Calculate Final Amount REFRESH

Final Amount :
Swing Controls used in the GUI Application :
1. jLabel1 :
Properties : 11. jButton1 :
Text – “Book Code : ” Properties :
Font - Bold, 20 Text – “RESULT”
2. jLabel2 : Font - Bold, 20
Properties : 12. jButton2 :
Text – “Title of Book : ” Properties :
Font - Bold, 20 Text – “REFRESH”
3. jLabel3 : Font - Bold, 20
Properties : 13. jTextField1 :
Text – “Author of Book : ” Properties :
Font - Bold, 20 Text – “ ”
4. jLabel4 : Font - Bold, 20
Properties : 14. jTextField2 :
Text – “ Price of Book” Properties :
Font - Bold, 20 Text – “ ”
Font - Bold, 20
5. jLabel5 :
Properties :
Text – “ ”
Font - Bold, 20
6. jLabel6 :
Properties :
Text – “ Customer Type :”
Font - Bold, 20
7. jLabel7 :
Properties :
Text – “ Final Amount :”
Font - Bold, 20
8. jLabel8 :
Properties :
Text – “ ”
Font - Bold, 20
9. jCombobox1 :
Properties :
Change variable name – “C1”
Model – “B001”, “B002”, “B003”, “B004”
10. jCombobox2 :
Properties :
Change variable name – “C2”
Model – “Bookseller”, “School”, “Customer”
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
double A, D;
if(C1.getSelected( ) == “B001”)
{
D = 300;
jLabel5.setText(“300”);
}
else if(C1.getSelected( ) == “B002”)
{
D = 200;
jLabel5.setText(“200”); private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
}
else if((C1.getSelected( ) == “B003”)
{
{ jTextField1..setText(“ “);
D = 100; jTextField2..setText(“ “);
jLabel5.setText(“100”); jLabel5.setText(“ “);
} jLabel8.setText(“ “);
else
{
}
jLabel5.setText(“50”);
}

if(C2.getSelected( ) == “Bookseller”)
{
A = D - D*0.25;
jLabel8.setText(A);
}
else if(C2.getSelected( ) == “School”)
{
A = D - D*0.2;
jLabel8.setText(A);
}
else
{
A = D - D*0.1;
jLabel8.setText(A);

}
}
A networking company design a GUI Application to store the employee information as follow,
It accept the Employee Name, Father’s Name, Mother’s Name, Address, Gender, Basic Salary, Medical & Conveyance.
Calculate the Gross and Net salary as follow.
Basic DA HRA
>=40000 35% 37%
>=20000 25% 32%
>=10000 25% 30%

Employee Name :

Father’s Name :

Mother’s Name :

Address :

Gender : Male Female

Basic Salary :

Medical Conveyance:

Gross Salary

Net Salary

REFRESH
Swing Controls used in the GUI Application : 10. jButton1 :
1. jLabel1 : Properties :
Properties : Text – “Gross Salary”
Text – “Employee Name : ” Font - Bold, 20
Font - Bold, 20 11. jButton2 :
2. jLabel2 : Properties :
Properties : Text – “Net Salary”
Font - Bold, 20
Text – “Father’s Name : ”
12. jButton3 :
Font - Bold, 20
Properties :
3. jLabel3 : Text – “REFRESH”
Properties : Font - Bold, 20
Text – “Mother’s Name: ” 13. jTextField1 :
Font - Bold, 20 Properties :
4. jLabel4 : Text – “ ”
Properties : Font - Bold, 20
Text – “ Address :” 14. jTextField2 :
Font - Bold, 20 Properties :
5. jLabel5 : Text – “ ”
Properties : Font - Bold, 20
Text – “ Gender :” 15. jTextField3 :
Font - Bold, 20 Properties :
6. jLabel6 : Text – “ ”
Properties : Font - Bold, 20
Text – “Basic Salary :” 16. jTextField4 :
Font - Bold, 20 Properties :
7. jLabel7 : Text – “ ”
Properties : Font - Bold, 20
17. jTextField5 :
Text – “ Medical Conveyance :”
Properties :
Font - Bold, 20
Text – “ ”
8. jLabel8 : Font - Bold, 20
Properties : 18. jTextField6 :
Text – “ ” Properties :
Font - Bold, 20 Text – “ ”
9. jLabel9 : Font - Bold, 20
Properties : 19. jRadioButton1 :
Text – “ ” Properties :
Font - Bold, 20 Text – “Male”
20. jRadioButton1 :
Properties :
Text – “Female”
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
double BS, GS, NS;
BS = Double.parseDouble(jTextField5.getText( ));
if(BS >= 40000)
{
GS = BS + BS*0.35;
NS = BS + BS*0.35 + BS*0.37;
jLabel8.setText(GS);
jLabel9.setText(NS);
}
else if(BS >= 20000) private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
{
GS = BS + BS*0.25;
{
NS = BS + BS*0.25 + BS*0.32; jTextField1..setText(“ “);
jLabel8.setText(GS); jTextField2..setText(“ “);
jLabel9.setText(NS); jTextField3..setText(“ “);
} jTextField4..setText(“ “);
else if((BS >= 10000)
{
jTextField5..setText(“ “);
GS = BS + BS*0.25; jTextField6..setText(“ “);
NS = BS + BS*0.25 + BS*0.30; jLabel8.setText(“ “);
jLabel8.setText(GS); jLabel9.setText(“ “);
jLabel9.setText(NS); }
}
else
{
jLabel8.setText(GS);
jLabel9.setText(NS);
}

}
Design a GUI application, to enter a three digit number and find the sum of all the digits.

Swing Controls used in the GUI Application :


1. jLabel1 :
Properties : Enter the Number :
Text – “Enter the Number : ”
Font - Bold, 20
2. jLabel2 :
Properties :
Text – “ ”
Sum of digits
Font - Bold, 20
3. jTextField1 :
Properties : REFRESH
Change variable name – “T”
Text – “ ”
Font - Bold, 20
4. jButton1 :
Properties :
Text – “Sum of digits”
Font - Bold, 20
5. jButton2 :
Properties :
Text – “REFRESH”
Font - Bold, 20
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
int S, N1, N2, N3, NUM;
NUM = Integer.parseInt(T.getText( ));
if(NUM >= 100 && NUM < 1000)
{
N1 = NUM % 10;
NUM = NUM / 10;
N2 = NUM % 10;
NUM = NUM / 10;
N3 = NUM % 10;
S = N! + N2 + N3;
jLabel2.setText(“Sum of three digits of the number is :”+S);
}
else
{
JOptionPane.showMessageDialog(this, “Kindly enter three digit number only”);
}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)


{
T.setText(“ “);
jLabel2.setText(“ “);
}

You might also like