0% found this document useful (0 votes)
7 views3 pages

Java GUI Project: Data Validation & Calculator

The document outlines the creation of a Java project named GUIProject, which includes classes for data validation and a GUI calculator. It provides code snippets for validating letter and numeric inputs, as well as handling button actions for arithmetic operations in the calculator. The document emphasizes the use of JOptionPane for user feedback during input validation and operation execution.

Uploaded by

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

Java GUI Project: Data Validation & Calculator

The document outlines the creation of a Java project named GUIProject, which includes classes for data validation and a GUI calculator. It provides code snippets for validating letter and numeric inputs, as well as handling button actions for arithmetic operations in the calculator. The document emphasizes the use of JOptionPane for user feedback during input validation and operation execution.

Uploaded by

melesew mossie
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Advanced Programming Lab session 1

Create a project called GUIProject and create a class called datavalidation under this project

Add import [Link]; at the top of the class

// code for Letter Validation

private void txt1KeyPressed([Link] evt) {

if( ([Link]() >= 'a' && [Link]() <= 'z')||(([Link]() >= 'A' && [Link]() <= 'Z')) )

[Link](true);
else {
[Link](false);
[Link](null," Enter only letter");
[Link](true);
}
}
// code for Number validation
private void txt2KeyPressed([Link] evt) {

if ([Link]() >= '0' && [Link]() <= '9')

[Link](true);
else {
[Link](false);
[Link](null," Enter only numeric digits(0-9)");
[Link](true);
}
}

1
GUI Calculator, Create a class called GUIcalculator under the project GUIproject

Add import [Link]; at the top of the class

//code for btn1

private void btn1ActionPerformed([Link] evt)


{
if([Link]().equals(""))
{ String one = [Link]() + [Link]();
[Link](one);
} else
{ String one = [Link]() + [Link]();
[Link](one);
}
}

//code for btnadd


private void btnaddActionPerformed([Link] evt) {
if([Link]().equals("")) [Link](null," Enter value in the first
textfield");
else{
[Link]("+");
[Link](true);
}

2
//code for btndot
private void btndotActionPerformed([Link] evt)
{
String num;
if([Link]().equals(""))
{
num = [Link]() + [Link]();
[Link](num);
[Link](false);
}
else
{
num = [Link]() + [Link]();
[Link](num);
[Link](false);
}
}
// code for btnequal
private void btnequalActionPerformed([Link] evt) {
float val1=[Link]([Link]());
float val2= [Link]([Link]());
float sum=val1+val2;
float diff=val1-val2;
float prod=val1*val2;
float quet=val1/val2;
float mod=val1%val2;
String oper=[Link]();
if([Link]("+"))
{ String sumres=[Link](sum);
[Link](sumres);
}
else if([Link]("-"))
{ String diffres=[Link](diff);
[Link](diffres); }
else if([Link]("*"))
{ String prodres=[Link](prod);
[Link](prodres);
}
else if([Link]("/"))
{ String divres=[Link](quet);
[Link](divres);
}
else if([Link]("%"))
{ String modres=[Link](mod);
[Link](modres);
}
}

You might also like