2014-02-06 66 views
0

我有這樣的疑問。如何創建一個方法來添加表

我有以下方法:

public static Object[] czyDziala(String[] lista) throws IOException { 

     for(int i=0 ; i<=lista.length-1;i++){ 
      URL url = new URL(lista[i]); 
      HttpURLConnection httpCon = (HttpURLConnection) url.openConnection(); 

      int len = httpCon.getContentLength(); 
      if (len>0){ 

       System.out.println(url +new String(" Site Work")); 

      }else{ 
       System.out.println(url +"Site Don't Work"); 

      } 
     } 
     return null; 
    } 

在方法的參數是一個字符串列表。

JFrame okno = new JFrame(); 
    okno.setSize(1200, 500); 
    okno.setVisible(true); 
    okno.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

    String [] col = {"Nazwa Witryny"}; 
    String [] listaWitryn = {"http://www.wp.pl", 
          "http://www.onet.pl","http://mobidev.pl"}; 


    try { 
     Work.czyDziala(listaWitryn); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
} 

我如何添加一個表,它是

|站點名稱|狀態|

我認爲這是錯誤的方法產生的? 但我可能是錯的。

+1

那麼目前你'czyDziala'方法只返回'null',始終。你應該改變它來返回一個'boolean []'指示哪些站點「工作」,哪些不需要。或者將您的代碼更改爲採用* single *網站並返回* single *值的'checkSite'方法。 –

+0

隨着JTable類可以顯示數據的表格:http://docs.oracle.com/javase/tutorial/uiswing/components/table.html – rebeliagamer

+0

我能寫這個代碼? – user3278375

回答

0

你的代碼可能是:

public static Map<String, Boolean> czyDziala(String[] lista) throws IOException { 
    Map<String, Boolean> saveInDBList = new HashMap<String, Boolean>(); 
    for(int i=0 ; i<=lista.length-1;i++){ 
     URL url = new URL(lista[i]); 
     HttpURLConnection httpCon = (HttpURLConnection) url.openConnection(); 

     int len = httpCon.getContentLength(); 
     if (len>0){ 

      System.out.println(url +new String(" Site Work")); 
      saveInDBList.put(lista[i], true); 
     }else{ 
      System.out.println(url +"Site Don't Work"); 
      saveInDBList.put(lista[i], false); 

     } 
    } 
    return saveInDBList; 
} 

String [] col = {"Nazwa Witryny"}; 
    String [] listaWitryn = {"http://www.wp.pl", 
          "http://www.onet.pl","http://mobidev.pl"}; 


    try { 
     Map<String, Boolean> saveInDBList = Work.czyDziala(listaWitryn); 
     //Your Insert DB call 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
} 
+0

和我如何顯示站點和狀態上的JTable? – user3278375

+0

請參照該鏈接1)http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#data 2)http://stackoverflow.com/questions/17212197/create-the-hashmap-基於上的JTable – Subbu

相關問題