2006年12月27日

第一个ITEXT的程序

最近因为工作需要在看iText,以前都没接触过报表这一块,从头学习中。。。
第一个ITEXT的程序
//Step 1: define document
Rectangle rectPageSize = new Rectangle(PageSize.A4);
Document document 
= new Document(rectPageSize,50,50,40,40);

Paragraph paragraph1 
= new Paragraph("Welcome to IText");
paragraph1.setAlignment(Paragraph.ALIGN_CENTER);
PdfPTable table 
= new PdfPTable(2);
PdfPCell cell 
= new PdfPCell();
cell.addElement(paragraph1);
cell.setColspan(
2);
table.addCell(cell);
cell 
= new PdfPCell();
cell.addElement(
new Paragraph("Test1"));
table.addCell(cell);
cell 
= new PdfPCell();
cell.addElement(
new Paragraph("Test2"));
table.addCell(cell);

//Step 2: define output
PdfWriter.getInstance(document,new FileOutputStream("test.pdf"));

//Step 3: open document
document.open();

//Step 4: add elements
document.add(table);

//Step 5: close document
document.close();

posted @ 2006-12-27 16:24 EdwinWang 阅读(422) | 评论 (0)编辑 收藏

2006年12月21日

试用Netbeans5.5

今天尝试了下Netbeans 5.5版本,个人感觉很不错。一直都不太喜欢Eclipse,也许Eclipse给开发人员带来了最灵活的IDE,可灵活是有代价的,装个其他开发环境大概十到二十分钟就好了,装Eclipse加上捣鼓那些插件估计能搞上一天。
试了下在Netbeans5.5下开发Swing,web,web service,JSF等一些功能,感觉还不错。虽然一些图形化的拖拉效果做的还不尽如人意,但已经很不错了。据说还可以可视化开发Mobile程序,改天要试一下。
虽然Netbeans的灵活性不如eclipse,但是功能还是很强大的,值得使用。个人感觉eclipse更适合玩IDE的人而不是用IDE的人使用。Just 个人意见,呵呵~~

posted @ 2006-12-21 11:10 EdwinWang 阅读(260) | 评论 (0)编辑 收藏

2006年12月20日

如何在JAVA程序中调用windows其他程序

虽然JAVA是平台无关性的,但是在企业中很多时候还是在为特定的系统在开发,会要求调用一些当前系统的其他程序或命令。最常见的是在WINDOWS中。其实JAVA是可以通过Runtime去调用系统中的一些程序的,下面是一个例子:

try {
            ps 
=  Runtime.getRuntime().exec( " E:\\test.exe " );
            
// ps = Runtime.getRuntime().exec("ipconfig");  ---- For execute windows commands
            
// ps = Runtime.getRuntime().exec("E:\\test.bat"); ---- For run BAT files
            BufferedReader in  =   new  BufferedReader( new    InputStreamReader(ps.getInputStream()));
            String inputLine; 
            
while ((inputLine    =    in.readLine())    !=     null {  
                result   
+=    inputLine + " \n " ;
            }

            in.close();
            System.out.println(
" Output: "   +  result);
            
        }
catch (Exception ex) {
            System.out.println(
" Error "   +  ex.getMessage());
        }

上面的代码片断中后面一部分是在取返回的参数,如果不需要可以不取。不取的话可能也就不需要取得到Process了。用这个方法可以运行windows中的exe或者bat文件。

posted @ 2006-12-20 10:49 EdwinWang 阅读(1148) | 评论 (1)编辑 收藏

2006年12月19日

手动SOAP Call WebService

前不久公司接了个活,要求在Pnuts中Call WebService,本来是一件很容易的事,可不能添加第三方的类包给我造成了麻烦。不能使用Ajax等一些第三方的包,意味着我只能自己去解析SOAP协议,而在PNuts中虽然可以调JAVA的方法,但却不适合写很大的功能,最后采用了一种非常傻的做法,手动去拼SOAP消息的内容,写在这作为对一些特殊需求的一种实现方式:

try {
    postStr 
=  postStr  +   " <?xml version='1.0' encoding='utf-8'?> " ;
    postStr 
=  postStr  +   " <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " ;
    postStr 
=  postStr  +   "  xmlns:xsd='http://www.w3.org/2001/XMLSchema' " ;
    postStr 
=  postStr  +   "  xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> " ;
    postStr 
=  postStr  +   " <soap:Body> " ;
    postStr 
=  postStr  +   " <exchangeData xmlns='https://www.riverbed.com/mfg/DataExchange/'> " ;
    postStr 
=  postStr  +   " <sender>Test</sender> " ;
    postStr 
=  postStr  +   " <password>35b82957-c792-81ce-38e4-7c83ad3291ea</password> " ;
    postStr 
=  postStr  +   " <transactionType>Test_Get_Data</transactionType> " ;
    postStr 
=  postStr  +   " <data> " ;
    postStr 
=  postStr  +  htmlEncode(data);
    postStr 
=  postStr  +   " </data> " ;
    postStr 
=  postStr  +   " </exchangeData> " ;
    postStr 
=  postStr  +   " </soap:Body> " ;
    postStr 
=  postStr  +   " </soap:Envelope> " ;

    URL url 
=   new  URL( " https://www.test.com/testdata.php " );
    HttpURLConnection conn 
=  (HttpURLConnection)url.openConnection();
    conn.setDoOutput(
true );
    conn.setRequestMethod(
" POST " );
    conn.setRequestProperty(
" Content-Type " , " text/xml " );
    conn.setRequestProperty(
" Content-Length " , String.valueOf(postStr.length()));
    conn.setDoOutput(
true );
    conn.setDoInput(
true );
    conn.connect();
    PrintWriter out 
=   new  PrintWriter(conn.getOutputStream());  
    out.print(postStr);
    out.flush();
    out.close();
    BufferedReader in 
=   new  BufferedReader( new    InputStreamReader(conn.getInputStream()));
    String inputLine;
    
while ((inputLine    =    in.readLine())    !=     null {
        result   
+=    inputLine + " \n " ;  
    }

    in.close();
    System.out.println(htmlDecode(result));
}
catch (Exception ex) {
    System.out.println(
" Error: "   +  ex.getMessage());
}

posted @ 2006-12-19 09:40 EdwinWang 阅读(999) | 评论 (0)编辑 收藏

Begin~

终于还是开了自己的BLOG,一直都有这个想法,可是工作太忙似乎没什么空写,这次换了工作,以此为机会开了BLOG。至于能不能坚持就写多少是多少吧。起个名字叫一个人的BLOG就是因为估计自己这么懒更新速度很慢,应该没人会看,呵呵~~就当是自己记录一些事情的工具吧~~

posted @ 2006-12-19 08:58 EdwinWang 阅读(153) | 评论 (0)编辑 收藏

仅列出标题  
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

留言簿(1)

随笔分类

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜