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 to show insertion of StringBuffer, String objects and other Basic Data Types into a StringBuffer object

  2. Define an array of ten String elements each containing an arbitrary string of the form “month/day/year”

  3. 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

  4. An applet program to add two numbers where data is entered in TextField

  5. Given a list of marks ranging form 0 to 100, write a program to compute and print the number of students marks

  6. Program, which creates a three thread. One thread display the numbers from 1 to 5, second thread display the square root of that number etc

  7. Create an interface coversions. Which have the following functions Inchestomillimeters(), hptowatts(),wattstohp(),poundstogram(),gramtopounds()

  8. RMI application for getting the final total price of the shopping list with some of the following items and quantities chosen by the user

  9. An applet program to draw concentric circle in center of the canvas

  10. Develop a CORBA based application for addition of two complex numbers and displaying the result on client side

  11. Program of UDP datagram

  12. RMI program of count server and client

  13. Program to generate Fibonacci Series of a given number

  14. Program that will count the number of lines in each file that is specified on the command line

  15. Program to show an example of modifying String objects

  16. Program that takes a long sentence and a character from the client and count the occurrence of the character in the sentence at the server side

  17. Program to extract a portion of a character string and print the extracted string

  18. An applet program of linear sort

  19. Program to find the number of and sum of all integers greater than 100 and less than 200 that are divisible by 7

  20. Program of Floyds Triangle

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