question

Sir,

how to write the following code in jsp , avoid swing components , please give me the following code in another method , iwant to avoid swing . /* * To change this template, choose Tools | Templates * and open the template in the editor. */

package sample;

/**
 *
 * @author Manesh
 */
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import java.io.FileReader;
import java.util.List;
import java.util.ArrayList;
import javax.swing.text.html.parser.ParserDelegator;
import javax.swing.text.html.HTMLEditorKit.ParserCallback;
import javax.swing.text.html.HTML.Tag;
import javax.swing.text.MutableAttributeSet;
public class Original
{
    public static void main(String[] args)
    {
       JFrame frame = new EditorPaneFrame();
          frame.show();
    }

}
class EditorPaneFrame extends JFrame
{

     private JTextField url;
     private JCheckBox editable;
     private JButton loadButton;
     private JButton backButton;
      private JButton b1;
     private JEditorPane editorPane;
     private Stack urlStack = new Stack();


     public EditorPaneFrame()
     {
          setTitle("Java Web Browser");
          setSize(600,400);
          addWindowListener(new WindowAdapter()
          {
               public void windowClosing(WindowEvent e)
               {
                    System.exit(0);
               }
          } );

          // set up text field and load button for typing in URL

          url = new JTextField(30);

          loadButton = new JButton("Load");
          loadButton.addActionListener(new ActionListener()
          {
               public void actionPerformed(ActionEvent event)
               {
                    try
                    {
                         // remember URL for back button
                         urlStack.push(url.getText());
                         editorPane.setPage(url.getText());
                    }
                    catch(Exception e)
                    {
                         editorPane.setText("Error: " +e);
                    }
               }
          });

          // set up back button and button action

          backButton = new JButton("Back");
          backButton.addActionListener(new ActionListener()
          {
               public void actionPerformed(ActionEvent event)
               {
                    if(urlStack.size()<=1) return;
                    try
                    {
                         urlStack.pop();
                         String urlString = (String)urlStack.peek();
                         url.setText(urlString);
                         editorPane.setPage(urlString);
                    }
                    catch(IOException e)
                    {
                         editorPane.setText("Error : " +e);
                    }
               }
          });

          editorPane = new JEditorPane();
          editorPane.setEditable(false);
          editorPane.addHyperlinkListener(new HyperlinkListener()
          {
               public void hyperlinkUpdate(HyperlinkEvent event)
               {
                    if(event.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
                    {
                         try
                         {
                              urlStack.push(event.getURL().toString());
                              System.out.println(event.getURL().toString());
                              url.setText(event.getURL().toString());

                              editorPane.setPage(event.getURL());
                         }
                         catch(IOException e)
                         {
                              editorPane.setText("Error: " + e);
                         }
                    }
               }
          });

          editable = new JCheckBox();
          editable.addActionListener(new ActionListener()
          {
               public void actionPerformed(ActionEvent event)
               {
                    editorPane.setEditable(editable.isSelected());
               }
          });

          Container contentPane = getContentPane();
          contentPane.add(new JScrollPane(editorPane), "Center");

          JPanel panel = new JPanel();
          panel.add(new JLabel("URL"));
          panel.add(url);
          panel.add(loadButton);
          panel.add(backButton);
          panel.add(new JLabel("Editable"));
          panel.add(editable);
      b1=new JButton("Extract");
    panel.add(b1);
     contentPane.add(b1, "East");
          contentPane.add(panel,"South");
    final TextArea ta = new TextArea();
               //  ta.setFont(new Font("Serif", Font.ITALIC, 16));

    //ta.setLineWrap(true);
    //ta.setWrapStyleWord(true);

    panel.add(ta);
    contentPane.add(ta,"West");
JButton b2=new JButton("Summary");
panel.add(b2);
contentPane.add(panel,"South");
    //code 4 extracting url
     b1.addActionListener(new ActionListener()
           {
               public void actionPerformed(ActionEvent event)
                {
                   // System.out.println(url.getText());
     String strUrl = url.getText();
    System.out.println(strUrl);
    v2 x1=new v2();
    try{
        x1.fun(strUrl,ta);
    }
    catch(Exception e){}
               }

    });
  }
}
//new thing
 class v2{
public String fun(String Url,TextArea ta )throws Exception
{
        BufferedWriter writer2 = null;
        BufferedReader reader1 = null;
        BufferedWriter writer3 = null;
            try {
                URL url = new URL(Url);
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
                    BufferedWriter writer = new BufferedWriter(new FileWriter("data.html"));
            writer2 = new BufferedWriter(new FileWriter("xx.txt"));
            writer3 = new BufferedWriter(new FileWriter("content.txt"));
                String line;
            while ((line = reader.readLine()) != null) {
                //System.out.println(line);

                        writer.write(line);
                        writer.newLine();
                    }

                reader.close();
                    writer.close();
        } catch (MalformedURLException e) {
                        e.printStackTrace();
                }
        catch (IOException e) {
            e.printStackTrace();
                }
        FileReader readerutil = new FileReader("data.html");
        List<String> lines = Sample.extractText(readerutil);

        for (String line : lines) {
            writer2.write(line);
            writer2.newLine();
            //System.out.println(line);
        }
        writer2.close();
        BufferedReader br=new BufferedReader(new FileReader("xx.txt"));
        StringBuffer sbr=new StringBuffer();
        String str=br.readLine();
        while(str!=null){
            str = str.trim();
            if(!(str.equals("<")||str.equals(">")||str.equals("|"))){
                sbr.append(str+" ");
                sbr.append("\n");
            }
            str=br.readLine();
        }
        writer3.write(sbr.toString());
            ta.setFont(new Font("Serif", Font.ITALIC, 16));

        ta.setText(sbr.toString());
        //ta.setLineWrap(true);
        //ta.setWrapStyleWord(true);

        writer3.close();
        //String line;
        //while((line=sbr.readLine()!=null){
        //writer3.write(line);
        //writer3.newLine();
        //}writer3.close();
        System.out.println(sbr);

        return "hhhh";
    }
    public static List<String> extractText(Reader reader) throws IOException {
            final ArrayList<String> list = new ArrayList<String>();
            ParserDelegator parserDelegator = new ParserDelegator();
        ParserCallback parserCallback = new ParserCallback() {
                public void handleText(final char[] data, final int pos) {
                    list.add(new String(data));
            }
            public void handleStartTag(Tag tag, MutableAttributeSet attribute, int pos) { }
                public void handleEndTag(Tag t, final int pos) {  }
                public void handleSimpleTag(Tag t, MutableAttributeSet a, final int pos) { }
                public void handleComment(final char[] data, final int pos) { }
                public void handleError(final java.lang.String errMsg, final int pos) { }
            };
        parserDelegator.parse(reader, parserCallback, true);
            return list;
    }
}
View Answers









Related Tutorials/Questions & Answers:
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
Advertisements
Question
Question   When there is an exception in my program how java runtime system handles
question
question  dear sir/madam my question is how to compare two text format in java..we are java beginners..so we need the complete source code for above mentioned question...we have to compare each and every word
question
question  Dear sir i had some typing mistake at previous question so its my humble request to let me know the steps to start the tomcat6 under the tomcat directory
question
question  Gud morning sir, I have asked u some question regarding jsp in saturaday for that i didnot find any answere in which u send me the some of the links.U have asked me the specify some details. There is a entity name
Question?
Question?  My question is how to: Add a menu bar to the program with a File menu. In the File menu, add a submenu (JMenuItem) called About. When the user clicks on the About menu item, display a JOptionPane message dialog
Question on pooling
Question on pooling  which server supports pooling?Application server or web server
This question in Jmeter
This question in Jmeter  hi..i want to send request(xml) 100 times but each time in request xml one element needs to change, otherwise request will be failed since its duplicate
Question on javascript
Question on javascript  This is not exactly what i wanted....If i enter in 2nd combobox as name of child then it should show child id in 1st combobox automatically and vice versa
C# question
Create a Solution by name Bank with Classes Account.cs, SavingsAccount.cs and savingsTest.cs to Demonstrate Abstract Classes in C#  1st question : Create a Solution by name Bank with Classes Account.cs, SavingsAccount.cs
question for c++
question for c++   write Program to swap between two numbers if first number is greater than second number and total of two numbers greater than 10
Inheritance question?
Inheritance question?  Q3)Create a class hierarchy as Company extended by AccountsDepartment. AccountsDepartment extended by AccountsReceivable... as AccountsPayable. please send the code of this question soon....plzzzzzzzz  
Inheritance question?
Inheritance question?  Q3)Create a class hierarchy as Company extended by AccountsDepartment. AccountsDepartment extended by AccountsReceivable... as AccountsPayable. please send the code of this question soon....plzzzzzzzz View
Question in Eclipse
Question in Eclipse   ** Hello EveryOne , L Have Question in Eclipse ?!! Question is : A.( The square class) Design a class named Square that contains : 1.A private instance variable side of type double 2.A no-argument
Question in Eclipse ??
Question in Eclipse ??  ** Hello EveryOne , L Have Question in Eclipse ?!! Question is : A.( The square class) Design a class named Square that contains : 1.A private instance variable side of type double 2.A no-argument
jsp question..
jsp question..  what should do in deployment descriptor after adding jstl jar files.. I am the the following message in console screen; The absolute cannot be resolved in either web.xml or the jar files deployed
jsp question..
jsp question..  what should do in deployment descriptor after adding jstl jar files.. I am the the following message in console screen; The absolute cannot be resolved in either web.xml or the jar files deployed
Question in Java ??
Question in Java ??   Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number squrfoot
Question in Java ??
Question in Java ??  Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number 0 ,2, . . . ,18,20 squrfoot 00000 1.4142 5.2426 5.4721
Question in Java ??
Question in Java ??  Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number 0 ,2, . . . ,18,20 squrfoot 00000 1.4142 5.2426 5.4721
jsp question
jsp question   sir plz tell me how can I create a page which is similar to feedback form in which if one option is empty then other option is inaccessible. for example it consists of name address etc. if name field is not filled
jsp question
jsp question   sir plz tell me how can I create a page which is similar to feedback form in which if one option is empty then other option is inaccessible. for example it consists of name address etc. if name field is not filled
Question in eclipes ??!!
Question in eclipes ??!!  Hooole EveryOne I have Question in eclipes !!? Question is : The objectives of this lab are 1.Using the ââ?¬Å? thisââ?¬Â? reference. 2.Initializing class objects. 3.Using overloaded constructors
Question Java>?
Question Java>?  **ïâ??· Create a new class called Bank and in the main method use class Account (lab 4) to create an array of 10 accounts. ïâ??· Enter data for all accounts (account number,name, balance). ïâ??· Add
Question on java
Question on java  why java is not purely oop?   java is not purely OOP because 1.) Multiple Inheritance is not supported.ADS_TO_REPLACE_1 2.) It uses primitive data type. 3.) static method can be called without
Ajax Question
Ajax Question   I am having 3 fields in jsp they are Fieldname,Fieldtype,Required. If i enter as Fieldname studentid,Fieldtype as checkbox,Required as true(i.e., mandatory field as *).It should store their details in database
java question
java question   Create a class called Complex to perform arithmetic operations with complex numbers. 1- Use double variables to represent the fields of the class. 2- Provide a no-argument constructor with default values in case
Interview question.
Interview question.  Program to read the integers from the standard input (until it gets a negative number) and puts them in to an array.after that it calls process Array on the array,and then prints the content of the array