English 中文(简体)
jtextarea不出人
原标题:jtextarea does not pop out
import net.htmlparser.jericho.*;

@SuppressWarnings({ "serial", "unused" })
public class RenderToText extends JDialog {


    static JTextArea _resultArea = new JTextArea(100, 100);
    JScrollPane scrollingArea = new JScrollPane(_resultArea);
    private final static String newline = "
";
    int filename = 100;
    String[] fileName = new String[filename];

    public RenderToText(){
        for (int i = 0; i < filename; i++) {
         String fileName = "abc"+i+".txt";
            // A File object to represent the filename
            File f = new File(fileName);
            f.delete();
        }


        _resultArea.setEditable(false);
        //Starting to write files
        try{
        FileReader fr = new FileReader(
                "C:\Users\user\fypworkspace\FYP\Link\abc.txt");
        BufferedReader textReader = new BufferedReader(fr);

        // for each URL, process the URL and render the HTML file
        int numberofURL = 100;
        String[] URL = new String[numberofURL];
        int a;




        // For each URL, assign one text file to store the contents

        // for each URL, extract the URL contents

        for (a = 0; a < numberofURL; a++) {
            for (int i = 0; i < numberofURL; i++) {

                URL[a] = textReader.readLine();
                try{
                try {
                    try {
                        // Render the text from the HTML file
                        String sourceUrlString = URL[a];


                        System.out.println("Using argument of ""
                                    + sourceUrlString +  " );


                        if (sourceUrlString.indexOf( : ) == -1)
                            sourceUrlString = "file:" + sourceUrlString;
                        Source source = new Source(new URL(sourceUrlString));
                        String renderedText = source.getRenderer()
                                .toString();
                        _resultArea.append("
Simple rendering of the HTML document:
" + newline);
                        System.out.println(renderedText+ newline);

                        // Write the rendered text to a text file


                        String filename = ("abc" + i + ".txt");
                        Writer output = null;
                        String text = renderedText;
                        File file = new File(filename);
                        output = new BufferedWriter(new FileWriter(file));
                        output.write(text);
                        output.close();
                        System.out.println("Your file has been written"+ newline);



                        // Count the number of words available in the
                        // rendered text.

                        BufferedReader br = new BufferedReader(
                                new FileReader(
                                        "C:\Users\user\fypworkspace\FYP\abc"
                                                + i + ".txt"));
                        String line = "", str = "";
                        int count = 0;
                        while ((line = br.readLine()) != null) {
                            str += line + " ";

                        }
                        StringTokenizer st = new StringTokenizer(str);
                        while (st.hasMoreTokens()) {
                            String s = st.nextToken();
                            count++;
                        }
                        _resultArea.append("File has " + count + " words."+ newline);
                    } catch (UnknownServiceException ex) {
                        System.out.println("The following url cannot be processed"+ newline);

                    }

                    System.out.println("
");
                    System.out.println("
");
                    System.out.println("
");
                } catch (NullPointerException ex) {
                    System.out.println("End of URL");
                    System.exit(0);
                }
            }catch(IOException ex){
                System.out.println("The following url cannot be processed due to the need to login");
            }
            }
        }


    }catch (IOException e1) {
    }
    JPanel content = new JPanel();
    content.setLayout(new BorderLayout());
    content.add(scrollingArea, BorderLayout.CENTER);

    this.setContentPane(content);
    this.setTitle("TextAreaDemo B");

    this.pack();
    }



    public static void main(String[] args) throws IOException {
        JDialog win = new RenderToText();
        win.setVisible(true);

    }
    }

该守则摘录了网站的内容。 我使用了产出的附录,但 j字塔并没有出现。 它可以运行,但CANT将产出转让给jtextarea。 什么是失踪?

问题回答

你们有两处 lo。

for (a = 0; a < numberofURL; a++)
    for (int i = 0; i < numberofURL; i++)

每一步骤100个。 因此,您重新阅读了10 000卢比的投入文件。 如果其中没有足够的话,<条码>即线即告无效,从而可以例外(另见外线的评论)。 • 摆脱无用的第二次循环。

除了阅读档案中的错误外,文本应显示产出(在我测试时也是如此)。 因此,这似乎属于你们的读物和其中处理的例外。

Note: please also consider the other comments from extraneon.

Agree with comment about static JTextArea. If you want to shere content you can use the same Document in two JTextAreas added in different places.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签