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 an example of using Abstract Class and Abstract Method

  2. Program to change characters in a StringBuffer objects and to reverse its contents

  3. Biological Sequence Allignment Using Dynamic Programing

  4. Program of UDP news server

  5. Program to show an example of Driving and using a Class

  6. Program to show an example of Concatination of Strings

  7. Program of linear search

  8. Program using Switch case to compute the net amount to be paid by a customer

  9. corba program of client and a DNS server where given a URL the server sends back an IP address

  10. Program to show the use of Labeled Continue Statement

  11. CORBA PROGRAM TO GET THE HTML CODE FROM ANY URL

  12. Word list program that reads a text file and makes an alphabetical list of all the words in that file. The list of words is output to another file

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

  14. Corba program of UDP client server application which sends the news to the client. Server takes the news from the NewsDataFile located at the server

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

  16. Program to show an example of searching Strings for characters

  17. Develop a CORBA application that takes a string from client and returns whether it is palindrome

  18. Program to show an example of using initialization block to initialize the data members of a class

  19. Write a program for restaurant

  20. Socket program of multi client chat server

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