SWT之java天氣預報 .

用的是SWT中的org.eclipse.swt.browser.Browser組件html

 

String html="<table><tr><td>你好</td></tr></table>";shell

Browser browser = new Browser(shell, SWT.NONE);app

browser.setText(html);eclipse

 

完整示例代碼以下:ide

 

  
  
  
  
  1. package test.ftp00;  
  2.  
  3. import org.eclipse.swt.SWT;  
  4. import org.eclipse.swt.browser.Browser;  
  5. import org.eclipse.swt.layout.FillLayout;  
  6. import org.eclipse.swt.widgets.Display;  
  7. import org.eclipse.swt.widgets.Shell;  
  8.  
  9. public class RenderHTML {  
  10.  
  11.     public static void main(String[] args) {  
  12.         /* Relative links: use the HTML base tag */  
  13.  
  14.         // String html =  
  15.         // "<iframe src="/" mce_src="http://www.thinkpage.cn/weather/weather.aspx?c=CHXX0008&l=zh-CN&p=MSN&a=0&u=C&s=1&m=1&x=1&d=3&fc=&bgc=&bc=/" frameborder=/"0/" scrolling=/"no/" width=/"200/" height=/"260/" allowTransparency=/"true/"></iframe>";  
  16.  
  17.         // html =  
  18.         // "<embed allowScriptAccess=/"never/" allowNetworking=/"internal/" pluginspage=http://www.macromedia.com/go/getflashplayer src="/" mce_src="/""http://aw.awflasher.com/getweatherc.swf?awstyle=blue/" width=/"180/" height=/"200/" type=application/x-shockwave-flash></embed>";  
  19.         String html="<table><tr><td>你好</td></tr></table>";  
  20.         Display display = new Display();  
  21.         Shell shell = new Shell(display);  
  22.         shell.setLayout(new FillLayout());  
  23.         Browser browser = new Browser(shell, SWT.NONE);  
  24.         browser.setText(html);  
  25.         shell.setSize(260, 350);  
  26.         shell.open();  
  27.         while (!shell.isDisposed()) {  
  28.             if (!display.readAndDispatch())  
  29.                 display.sleep();  
  30.         }  
  31.         display.dispose();  
  32.     }  
相關文章
相關標籤/搜索