Friday, October 28, 2011

WALKTHROUGH:TNB Java Tut 50 -"Graphical User Interface GUI" [VIDEO] [SOURCE CODE]

In this walk-through you will create a simple GUI that will use 2 shoInputDialogs and a showMessageDialog to find the sum of two numbers input from the user. 
 
Whats New In This Walk-Through:
  • showInputDialog's- A graphical box that users can input data from
  • Integer.parseInt - A method used to convert a string number to a int var
  • Using showMessageDialog's-A graphical box that can display a message




    Step 1. Import javax.swing.JOptionPane:

    Photobucket

    Step 2. Declare a class and a main method:


    Step 3.Create 2 String variable and set them equal to a showInputDialog:



    Step 4. Create two int variable and set them equal to the Strings we collected from the user via the showInputDialog (you will need to parse the strings before you can set them equal to a int variable):



    Step 5.Create a third int var and set it equal to the sum of int var1 and int var2:



    Step 6. Create a showMessageDialog that will display the sum of the two numbers in sentence form:

    TNB Java Tut 50 Source Code:

     import javax.swing.JOptionPane;  
     class apples {  
       public static void main(String[] args){  
        String fn = JOptionPane.showInputDialog("Enter first number");  
        String sn = JOptionPane.showInputDialog("Enter second number");  
        int num1 = Integer.parseInt(fn);  
        int num2 = Integer.parseInt(sn);  
        int sum = num1 + num2;  
        JOptionPane.showMessageDialog(null, "The answer is " + sum, "the title", JOptionPane.PLAIN_MESSAGE);  
       }  
     }  
    


    End of Tutorial

    2 comments:

    Mary Brown said...

    Java EE article is practical oriented and real time examples. How Java EE address the enterprise development is very important. for that you need a practical orieneted Java Training you need.

    Online Java Training
    Online Java Training from India
    Java Training Institutes in Chennai
    Java Training in Chennai
    Java Training

    techbuzz ctp said...

    What an amazing and well written article.
    project training company in Ahmedabad

    Post a Comment

     
    ;