Follow the steps to create GUI:
Step-1: Drag and drop the label from the Palette window and rename it as "Enter First Numer".
Step-2: Drag and drop the TextField from the Palette window and give the variable name to "tfFirstNumber" by right-clicking on text field object.
Step-3: Drag and drop the label from the Palette window and rename it as "Enter Second Number".
Step-4: Drag and drop the TextField from the Palette window and give the variable name to "tfSecondNumber".
Step-5: Drag and drop the label from the Palette window and rename it as "Enter Third Number".
Step-6: Drag and drop the TextField from the Palette window and give the variable name to "tfThirdNumber".
Step-1: Drag and drop the label from the Palette window and rename it as "Enter Fourth Numer".
Step-2: Drag and drop the TextField from the Palette window and give the variable name to "tfFourthNumber" by right-clicking on text field object.
Step-7: Drag and drop the Button object from the Palette window and give the variable name to "btnFind" and change the text to "Find Largest".
Step-10: Drag and drop the TextField from the Palette window and give the variable name to "tfResult" by right-clicking on text field object and make editable to false.
Finally, double-click on the button and follow the codes given below:
private void btnFindActionPerformed(java.awt.event.ActionEvent evt) {
int fn,sn,th,fr;
fn=Integer.parseInt(tfFirstNumber.getText());
sn=Integer.parseInt(tfSecondNumber.getText());
th=Integer.parseInt(tfThirdNumber.getText());
fr=Integer.parseInt(tfFourthNumber.getText());
if(fn>sn && fn>th && fn>fr)
{
tfResult.setText("Largest Number is: "+Integer.toString(fn));
}
else if(sn>fn && sn>th && sn>fr)
{
tfResult.setText("Largest Number is: "+Integer.toString(sn));
}
else if(th>fn && th>sn && th>fr)
{
tfResult.setText("Largest Number is: "+Integer.toString(th));
}
else if(fr>fn && fr>sn && fr>th)
{
tfResult.setText("Largest Number is: "+Integer.toString(fr));
}
}
Your blog is very nice
ReplyDelete