Java Tutorial

 
 
 
 
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

class HTMLGetter extends Frame implements ActionListener
{
    TextField tURL = new TextField(50);
    Button btn = new Button(\"Get HTML\");
    Button exit = new Button(\"Exit\");
    TextArea ta = new TextArea(50,20);

    HTMLGetter() throws Exception
    {
        Panel p = new Panel();
        add(p,BorderLayout.NORTH);
        p.add(tURL);
        p.add(btn);
        p.add(exit);
        add(ta);
        btn.addActionListener(this);
        exit.addActionListener(this);
        setSize(600,400);
        show();
    }

    public static void main(String args[]) throws Exception
    {
        HTMLGetter hg = new HTMLGetter();
    }

    public void actionPerformed(ActionEvent ae)
    {
        if(ae.getSource()==btn)
        {
            try
            {
                URL htmlURL = new URL(tURL.getText());
                InputStream in = htmlURL.openStream();
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
                String getLine;

                while((getLine=br.readLine())!=null)
                {
                    ta.append(getLine);
                }
                br.close();
                in.close();
            }
            catch(Exception e)
            {
                //No handling exception here;
            }
        }
        else
        {
            System.exit(0);
        }
    }
}

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

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

  3. Program to sort the contents of an array using Bubble Sort

  4. Program to show the use of Bitwise Operator (&) AND

  5. Simple Applet which will show life cycle of an Applet

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

  7. Write a class whose objects holds a current value and have a method to add that value, printing the new value

  8. Program to show an example of using multiple classes in a program

  9. Program to display Floyds Triangle of a numbers

  10. Program to read command line arguments

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

  12. Program to display bank account

  13. Dialog Boxes

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

  15. Program to print some text on the same line using multiple print statements

  16. Program to declare and initialize Boolean variables and print them on the Standard Output Device

  17. Program that demonstrates type casting

  18. CORBA based application for addition of two mathematical expressions of the form (ax + by) and displaying the result on client side

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

  20. Program to show an example of Overriding a Base Class Method

 
 
Didn't find what you were looking for? Find more on CORBA PROGRAM TO GET THE HTML CODE FROM ANY URL