如何在GUI中显示控制台的输出

时间:2015-05-07 12:03:18

标签: java xml user-interface

我想将JAVA中的输出控制台显示为GUI,但我不知道如何操作 这是我的输出,它看起来像xml文件,但我想只显示结果而不是所有输出。 请帮帮我。

1 个答案:

答案 0 :(得分:0)

    package javaapplication2;

    import java.io.BufferedReader;

    import java.io.IOException;

    import java.io.InputStreamReader;

    import java.net.HttpURLConnection;

    import java.net.MalformedURLException;

    import java.net.URL;

    public class  Information3G{

public String API_MONI_TRAF_STATS="/api/monitoring/traffic-statistics";//
public String API_RESET_TRAF_STATS="/api/monitoring/clear-traffic";
// public String API_CURR_PLMN="/api/net/current-plmn";//
//public String API_DIALUP_CONNECTION="/api/dialup/connection";
public String API_MONITORI_STATUT="/api/monitoring/status";//
public String API_NET_NETWORK="/api/net/network";//
public String API_PIN_STATUT="/api/pin/status";//

public String API_DIALUP_PROFILES="/api/dialup/profiles";
public String API_DEVICE_INFO="/api/device/information";//
public String API_SMS_SMSLIST="/api/sms/sms-list";
//public String API_CHECK_NOTIF="/api/monitoring/check-notifications";
public String API_SMS_COUNT="/api/sms/sms-count";


public String tab[]= new String[3];
public URL url= null;
public BufferedReader rd  = null;
public StringBuilder sb = null;

public HttpURLConnection connection = null;
public String host, ipcheck;

public String trafficStats, monitor, device;
//constructor
public Information3G()
{
    this.setHost("http://192.168.1.1");



    tab[1]="/api/net/network";
    tab[2]="/api/dialup/connection";        




}


// connecting  ...
public HttpURLConnection getConnection() throws MalformedURLException, IOException
{       
    url = new URL(host);
    connection = (HttpURLConnection)url.openConnection();
    connection.setRequestMethod("GET");
    connection.setDoOutput(true);
    connection.setReadTimeout(10000);
    connection.connect();
    return connection;
} 
// get Host
public String getHost() {
    return host;
}
// set Host
public void setHost(String host) {
    this.host = host;
}  

public void resetHost()
{
    this.setHost("http://192.168.1.1");
}

public URL getUrl() {
    return url;
}

public void setUrl(URL url) {
    this.url = url;
}
public String get_traffic_statistics() throws IOException
{
    String line="";
    host = "http://192.168.1.1/api/monitoring/traffic-statistics" ;
    System.out.println(host);
    //connection.
    rd  = new BufferedReader(new InputStreamReader(this.getConnection().getInputStream()));
    sb = new StringBuilder();        
    while ((line = rd.readLine()) != null)
        {                
            if(!(line.contains("</response>")))    
                sb.append(line + '\n');               
        }
    return sb.toString();
}

public String get_device_infos() throws IOException
{
    String line="";
    host = "http://192.168.1.1/api/device/information" ;
   // System.out.println(host);
    //connection.
    rd  = new BufferedReader(new InputStreamReader(this.getConnection().getInputStream()));
    sb = new StringBuilder();        
    while ((line = rd.readLine()) != null)
        {                
            if((line.contains("<SerialNumber>"))||(line.contains("<Imei>"))
                ||(line.contains("<Imsi>"))||(line.contains("<Iccid>"))
                ||(line.contains("<Msisdn>")))    
                sb.append(line + '\n');               
        }
    return sb.toString();
}

public String get_monitoring_status() throws IOException
{
    String line="";
    host = "http://192.168.1.1/api/monitoring/status" ;

    rd  = new BufferedReader(new InputStreamReader(this.getConnection().getInputStream()));
    sb = new StringBuilder();        
    while ((line = rd.readLine()) != null)
        {                
            if((line.contains("<SignalStrength>"))||(line.contains("<SignalIcon>"))||(line.contains("</response>")))                      
                sb.append(line + '\n');               
        }
    return sb.toString();
}

}

`