Java Tutorial

 
 
 
 
import java.awt.*;
import java.applet.*;

public class UserInput extends Applet
{
      TextField text1, text2;

      public void init()
      {
           text1 = new TextField(8);
           text2 = new TextField(8);
           add(text1);
           add(text2);
           text1.setText(\"0\");
           text2.setText(\"0\");
      }

      public void paint(Graphics g)
      {
          int x=0,y=0,z=0;
          String s1,s2,s;
          g.drawString(\"Input a number in each box  \",10,50);
          try
          {
                 s1 = text1.getText();
                 x = Integer.parseInt(s1);
                 s2 = text2.getText();
                 y = Integer.parseInt(s2);
           }
          catch(Exception e) {}

           z = x + y;
           s =  String.valueOf(z);
           g.drawString(\"The Sum is : \",10,75);
           g.drawString(s,100,75);
    }

    public boolean action(Event event, Object obj)
    {
          repaint();
          return true;
    }
}

    Related Post:
  1. Program which will read a string and rewrite it in the alphabetical order

  2. Servlet which takes input from an HTML client page and calculates and outputs the premium amount

  3. RMI based application for login validation based on data saved in text file stored on the server and will display appropriate message to the client..

  4. Program to append a StringBuffer by StringBuffer, String objects and other Basic Data Types

  5. An applet program to take user input and display

  6. Program that will read real number from the keyboard and print the following output in one line: small Integer not less The Given Number Largest Int

  7. Develop a game application in CORBA for which the player will guess a number between 1 to 100, which will be compared to the random number generated b

  8. Program to show the use of Labeled Continue Statement

  9. Program to show an example of creating a class and using its object

  10. Program to read rollno, marks of sub1,sub2 and sub3 and on basis of that display result

  11. Program using session tracking capability of Servlets, which displays information of current user session by HttpServletRequest object

  12. An application that combines several classes and interface

  13. Program to read command line arguments

  14. Program sets up a String variable containing a paragraph of text of your choice. Extract the words from the text and sort them into alphabetical order

  15. Socket program of multi client chat server

  16. Program in CORBA which takes a long sentence from client (at least 7 words), passes to the server, server separates out each word and sends back

  17. Program to declare, initialize and print a String object

  18. An applet program to display Vertical Color Bar

  19. CORBA program for displaying the date and time of the server machine, client machine and the difference between these two date and time

  20. Program to show the use of Conditional OR Operator (||) in If Statements

 
 
Didn't find what you were looking for? Find more on An applet program to take user input and display