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) {
}
durron597
32.5k18 gold badges106 silver badges164 bronze badges
1 Answer 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().
answered May 12, 2015 at 19:45
Jihed Amine
2,20820 silver badges32 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default
JTextArea?