1

This code is in a class and it gets the source code from a website. I would like get the code and print it out in a jTextArea that is in another class, but i have no idea how i can do that. how can i export this source code in another class?

public static void Connect() throws Exception{

    URL url = new URL("https://www.google.com/");
    URLConnection spoof = url.openConnection();


    spoof.setRequestProperty( "User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; H010818)" );
    BufferedReader in = new BufferedReader(new InputStreamReader(spoof.getInputStream()));
    String strLine = "";

    while ((strLine = in.readLine()) != null){

        System.out.println(strLine);
    }

}

in the other class I have a button with this code:

    try{
        Connect();
    } catch(Exception e) {

    }
2
  • 1
    I don't really understand your problem. You can just copy paste the code anywhere you want. If you have a good idea the imports will be added automatically. Instead of the println you will have to set the text of the jTextArea then. Commented May 12, 2015 at 19:35
  • Are you trying to get all the html for the page and put it into a JTextArea? Commented May 12, 2015 at 19:40

1 Answer 1

1

In the second class, you would call

try{
    ClassA.Connect();
} catch(Exception e) {

}

Where ClassA is the name of the class where public static void Connect() is defined. Note that, by convention, the method name should begin with a lower case, so it should be public static void connect().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.