I want to redirect a sytem.out.println to a JLabel in another class.
I have 2 classes, NextPage and Mctrainer.
NextPage is basically just a Jframe (The gui for my project), and I have created a Jlabel in Nextpage using this code;
public class NextPage extends JFrame {
JLabel label1;
NextPage() {
label1 = new JLabel();
label1.setText("welcome");
getContentPane().add(label1);
This is the code for Mctrainer:
public class Mctrainer {
JLabel label1;
Mctrainer() {
HttpClient client2 = new DefaultHttpClient();
HttpPost post = new HttpPost("http://oo.hive.no/vlnch");
HttpProtocolParams.setUserAgent(client2.getParams(),"android");
try {
List <NameValuePair> nvp = new ArrayList <NameValuePair>();
nvp.add(new BasicNameValuePair("username", "test"));
nvp.add(new BasicNameValuePair("password", "test"));
nvp.add(new BasicNameValuePair("request", "login"));
nvp.add(new BasicNameValuePair("request", "mctrainer"));
post.setEntity(new UrlEncodedFormEntity(nvp));
HttpContext httpContext = new BasicHttpContext();
HttpResponse response1 = client2.execute(post, httpContext);
BufferedReader rd = new BufferedReader(new InputStreamReader(response1.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
}
catch (IOException e) {
e.printStackTrace();
}
}
Mctrainer basically just prints out JSON data from a server using system.out.println. I want to redirect it to show up in the JLabel in my GUI (NextPage) instead of console. Any suggestions on how to do this?