Results 1 to 5 of 5
Thread: Is this right!! Java Swing
- 05-28-2010, 02:36 PM #1
Member
- Join Date
- Nov 2009
- Location
- Puttalam, Sri Lanka.
- Posts
- 6
- Rep Power
- 0
Is this right!! Java Swing
import javax.swing.JOptionPane;
public class Addition_GUI
{
public static void main(String args[])
{
String firstInt;
String secondInt;
firstInt = JOptionPane.showInputDialog("Enter the First Integer value :");
Integer num1 = Integer.parseInt(firstInt);
secondInt = JOptionPane.showInputDialog("Enter the Second Integer value :");
Integer num2 = Integer.parseInt(secondInt);
Integer sum = num1 + num2;
String result = String.format("The sum is : %s",sum);
JOptionPane.showMessageDialog(null,result);
}
}
It didn't give any errors. But, I need a explanation. Please help me.
- 05-28-2010, 03:51 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
About what?But, I need a explanation.
Also, use the "Code tags" when posting code to the formatting is retained and the code is more readable.
- 05-28-2010, 07:01 PM #3
Member
- Join Date
- Nov 2009
- Location
- Puttalam, Sri Lanka.
- Posts
- 6
- Rep Power
- 0
- 05-28-2010, 07:13 PM #4
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
So Java automatically invokes toString().
A couple of other points:
1. You don't really need two String variables, since you're done with the first by the time you use the second. It might make your code clearer if you had just one String variable called input or something along those lines.
2. Your Integer variables can all be primitive int variables instead. Generally it's good practice to use primitives where you can, although in this case it certainly wouldn't make much difference.
-Gary-
- 05-28-2010, 07:20 PM #5
Member
- Join Date
- Nov 2009
- Location
- Puttalam, Sri Lanka.
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
Help with java.swing.Jlist
By mitsukai in forum AWT / SwingReplies: 2Last Post: 04-23-2009, 01:12 PM -
Java swing question
By Godsent in forum New To JavaReplies: 4Last Post: 04-18-2009, 01:00 PM -
Java Swing
By JavaBean in forum Java TutorialReplies: 1Last Post: 04-11-2009, 03:09 PM -
[swing] Java and sql
By ezee in forum AWT / SwingReplies: 1Last Post: 03-27-2009, 05:55 PM -
Java Swing
By RAMYA in forum New To JavaReplies: 3Last Post: 11-12-2008, 07:00 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks