在线91精品亚洲网站精品成人,www.亚洲色图.com,亚洲一区二区三区国产精品无码http://m.tkk7.com/secret/zh-cnMon, 12 May 2025 06:25:47 GMTMon, 12 May 2025 06:25:47 GMT60swt Combo 設置值和顯示內容http://m.tkk7.com/secret/archive/2011/08/02/355589.htmlsecret_x15secret_x15Tue, 02 Aug 2011 06:22:00 GMThttp://m.tkk7.com/secret/archive/2011/08/02/355589.htmlhttp://m.tkk7.com/secret/comments/355589.htmlhttp://m.tkk7.com/secret/archive/2011/08/02/355589.html#Feedback0http://m.tkk7.com/secret/comments/commentRss/355589.htmlhttp://m.tkk7.com/secret/services/trackbacks/355589.htmlimport org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class ComboTest {

    
public static void main(String[] args) {
        String[] WEEK 
= { "Monday""Tuesday""Wednesday"};
        Display display 
= new Display();
        Shell shell 
= new Shell(display);
        shell.setBounds(
500100500300);
        shell.setText(
"Combo");
        shell.setLayout(
new GridLayout(3true));
        
        
//創(chuàng)建Combo組件,為下拉列表樣式
        final Combo dc = new Combo(shell, SWT.DROP_DOWN);
        dc.setItems(WEEK);
        dc.addSelectionListener(
new SelectionAdapter(){
            @Override
            
public void widgetSelected(SelectionEvent e) {
                String key 
= ""+dc.getSelectionIndex();
                String value 
= dc.getText();
                System.out.println(
"key:"+key+"    value:"+value);
            }
        });
        
        
//創(chuàng)建Combo組件,為下拉列表樣式,且只讀
        final Combo rc = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
        
//在界面中顯示的是123
        rc.add("123");
        
//第一個值是key從0開始 ,第二個值為value
        rc.setData("0""321");
        
        rc.add(
"456");
        rc.setData(
"1""654");
        
        rc.addSelectionListener(
new SelectionAdapter(){
            @Override
            
public void widgetSelected(SelectionEvent e) {
                String key 
= ""+rc.getSelectionIndex();
                System.out.println(
"key:"+key);
                String value 
= (String) rc.getData(key);
                System.out.println(
"key:"+key+"    value:"+value);
            }
        });
        
//rc.setItems(MONTHS);
        
//創(chuàng)建Combo組件,為List組件樣式
        Combo sc = new Combo(shell, SWT.SIMPLE);
        sc.setItems(WEEK);
        shell.open();
        
while (!shell.isDisposed()) {
           
if (!display.readAndDispatch()) {
               display.sleep();
          }
     }

     display.dispose();

    }

}


secret_x15 2011-08-02 14:22 發(fā)表評論
]]>
Eclipse添加DTD文件實現xml的自動提示功能http://m.tkk7.com/secret/archive/2011/06/29/353377.htmlsecret_x15secret_x15Wed, 29 Jun 2011 10:18:00 GMThttp://m.tkk7.com/secret/archive/2011/06/29/353377.htmlhttp://m.tkk7.com/secret/comments/353377.htmlhttp://m.tkk7.com/secret/archive/2011/06/29/353377.html#Feedback0http://m.tkk7.com/secret/comments/commentRss/353377.htmlhttp://m.tkk7.com/secret/services/trackbacks/353377.html Eclipse添加DTD文件實現xml的自動提示功能

1.點擊 window -->Preferences -->XML -->XML Catalog  -->Add..

2.點擊Add 彈出一個對話框,如圖所示



3.填寫文本框中的內容

Location : dtd的路徑。可以是eclipse工作空間的dtd,也可以是文件中的dtd。
Key type:選擇 Public ID
Key:為ibatis xml文件頭中<!DOCTYPE sqlMapConfig PUBLIC 后面的一段。即:-//ibatis.apache.org//DTD SQL Map Config 2.0//EN

4. 點擊OK 按鈕,重啟eclipse.


secret_x15 2011-06-29 18:18 發(fā)表評論
]]>
關于js中window.location.href,location.href,parent.location.href,top.location.href的用法http://m.tkk7.com/secret/archive/2011/06/28/353132.htmlsecret_x15secret_x15Tue, 28 Jun 2011 02:25:00 GMThttp://m.tkk7.com/secret/archive/2011/06/28/353132.htmlhttp://m.tkk7.com/secret/comments/353132.htmlhttp://m.tkk7.com/secret/archive/2011/06/28/353132.html#Feedback1http://m.tkk7.com/secret/comments/commentRss/353132.htmlhttp://m.tkk7.com/secret/services/trackbacks/353132.html
"window.location.href"、"location.href"是本頁面跳轉.
"parent.location.href" 是上一層頁面跳轉.
"top.location.href" 是最外層的頁面跳轉.
舉例說明:
    如果A,B,C,D都是html,D是C的iframe,C是B的iframe,B是A的iframe,如果D中js這樣寫
    "window.location.href"、"location.href":D頁面跳轉
    "parent.location.href":C頁面跳轉
    "top.location.href":A頁面跳轉
如果D頁面中有form的話,
    <form>:  form提交后D頁面跳轉
    <form target="_blank">:  form提交后彈出新頁面
    <form target="_parent">:  form提交后C頁面跳轉
    <form target="_top"> :  form提交后A頁面跳轉

如果訪問的是iframe里面的頁面,重新加載最外層的頁面
<html>
<head>
<title></title>
<script language="javascript">
function escapeFrame(){
      
if (window.top.location.href != window.location.href) {
        window.top.location.reload();
      }
}
</script>
</head>

<body onload="escapeFrame()">
<iframe src="b.html" ></iframe>
</body>
</html>


secret_x15 2011-06-28 10:25 發(fā)表評論
]]>
sort()排序 collections.sort();http://m.tkk7.com/secret/archive/2011/06/22/352813.htmlsecret_x15secret_x15Wed, 22 Jun 2011 08:03:00 GMThttp://m.tkk7.com/secret/archive/2011/06/22/352813.htmlhttp://m.tkk7.com/secret/comments/352813.htmlhttp://m.tkk7.com/secret/archive/2011/06/22/352813.html#Feedback1http://m.tkk7.com/secret/comments/commentRss/352813.htmlhttp://m.tkk7.com/secret/services/trackbacks/352813.htmlmain方法:
public class Test {

    
public static void main(String[] args) {
        
/**
         * 
         * sort()方法詳解
         * 1.Collections.sort(List<T> list) 
         *         根據元素的自然順序 對指定列表按升序進行排序。
         * 2.Collections.sort(List<T> list, Comparator<? super T> c) 
         *         根據指定比較器產生的順序對指定列表進行排序。
         * 
         
*/
        List
<Integer> list = new ArrayList<Integer>();
        list.add(
3);
        list.add(
1);
        list.add(
2);
        
//自然順序
        Collections.sort(list);
        
for(Integer i:list){
            System.out.println(i);
        }
        
        System.out.println(
"===============================================");
        
        Point point2 
= new Point(2,2,2);
        Point point1 
= new Point(1,1,1);
        Point point3 
= new Point(3,1,2);
        
        List
<Point> points = new ArrayList<Point>();
        points.add(point2);
        points.add(point1);
        points.add(point3);
        
        System.out.println(
"===============================================");
        
//根據point中的升序輸出
        Collections.sort(points, new SortByXdesc());
        
for(Point point:points){
            System.out.println(
"x:"+point.getX()+" y:"+point.getY()+" z:"+point.getZ());
        }
        
        System.out.println(
"===============================================");
        
//根據point中的x降序輸出
        Collections.sort(points, new SortByXasc());
        
for(Point point:points){
            System.out.println(
"x:"+point.getX()+" y:"+point.getY()+" z:"+point.getZ());
        }
    }

}

降序輸出類SortByXdesc:

public class SortByXdesc implements Comparator<Object> {

    
//根據point中的x降序輸出
    @Override
    
public int compare(Object o1, Object o2) {
        Point point1 
=(Point)o1;
        Point point2 
=(Point)o2;
        
if(point1.getX()>point2.getX()){
            
return 1;
        }
else{
            
return 0;
        }
    }

}

升序輸出類SortByXasc:

public class SortByXasc implements Comparator<Object> {

    
//根據point中的x升序輸出
    @Override
    
public int compare(Object o1, Object o2) {
        Point point1 
=(Point)o1;
        Point point2 
=(Point)o2;
        
if(point1.getX()>point2.getX()){
            
return 0;
        }
else{
            
return 1;
        }
    }
}



secret_x15 2011-06-22 16:03 發(fā)表評論
]]>
jquery 取值http://m.tkk7.com/secret/archive/2011/06/21/352738.htmlsecret_x15secret_x15Tue, 21 Jun 2011 07:00:00 GMThttp://m.tkk7.com/secret/archive/2011/06/21/352738.htmlhttp://m.tkk7.com/secret/comments/352738.htmlhttp://m.tkk7.com/secret/archive/2011/06/21/352738.html#Feedback0http://m.tkk7.com/secret/comments/commentRss/352738.htmlhttp://m.tkk7.com/secret/services/trackbacks/352738.html

jquery radio取值,checkbox取值,select取值,radio選中,checkbox選中,select選中,及其相關
獲取一組radio被選中項的值
    var item = $('input[@name=items][@checked]').val();
獲取select被選中項的文本
    var item = $("select[@name=items] option[@selected]").text();
select下拉框的第二個元素為當前選中值
    $('#select_id')[0].selectedIndex = 1;
radio單選組的第二個元素為當前選中值
    $('input[@name=items]').get(1).checked = true;

獲取值:

文本框,文本區(qū)域:
    $("#txt").attr("value");
多選框checkbox:
    $("#checkbox_id").attr("value");
單選組radio:  
     $("input[@type=radio][@checked]").val();
下拉框select: $('#sel').val();

控制表單元素:
文本框,文本區(qū)域:
    $("#txt").attr("value",'');//清空內容
    $("#txt").attr("value",'11');//填充內容

多選框checkbox:
                 $("#chk1").attr("checked",'');//不打勾
                 $("#chk2").attr("checked",true);//打勾
                 if($("#chk1").attr('checked')==undefined) //判斷是否已經打勾

單選組radio:   
     $("input[@type=radio]").attr("checked",'2');//設置value=2的項目為當前選中項
下拉框select:  
                $("#sel").attr("value",'-sel3');//設置value=-sel3的項目為當前選中項
                $("<option value='1'>1111</option><option value='2'>2222</option>").appendTo("#sel")//添加下拉框的option
                $("#sel").empty();//清空下拉框



secret_x15 2011-06-21 15:00 發(fā)表評論
]]>
struts2的s:checkboxlist標簽換行http://m.tkk7.com/secret/archive/2011/06/14/352278.htmlsecret_x15secret_x15Tue, 14 Jun 2011 04:18:00 GMThttp://m.tkk7.com/secret/archive/2011/06/14/352278.htmlhttp://m.tkk7.com/secret/comments/352278.htmlhttp://m.tkk7.com/secret/archive/2011/06/14/352278.html#Feedback0http://m.tkk7.com/secret/comments/commentRss/352278.htmlhttp://m.tkk7.com/secret/services/trackbacks/352278.htmlstruts2里增加了一個新的UT標簽s:checkboxlist,下面介紹下使用方法。
s:checkboxlist用于畫面上顯示一組復選框,缺省是橫排輸出,后面將介紹如何修改ftl文件使得它能按任意方式輸出。
標簽格式:
    <s:checkboxlist name="" list="" listKey="" listValue="" value="" />
    name-定義標簽名,用于接收畫面上選中的復選框,故應與Action里定義的屬性一致,且多為數組;
    list-定義集合變量,用于輸出復選框到畫面上,一般在Action里定義一個List或Map屬性;
    listKey-如果在Action里定義的是一個List,則往往會在List里定義一個Bean,它只有兩個屬性,其中一個(比如id)就在這里設置;
                如果在Action里定義的是一個Map,則Map的key就在這里設置;
    listValue-如果在Action里定義的是一個List,則往往會在List里定義一個Bean,它只有兩個屬性,另外一個(比如name)就在這里設置;
                  如果在Action里定義的是一個Map,則Map的value就在這里設置;
    value-用于回顯畫面上被選中的復選框,假如畫面有輸入檢查,如果有錯則返回原畫面并顯示出錯信息,這時候就需要使用它。
             一般把它設成和name一致就可以了。
注意點:
    為了能正確顯示已被選中的復選框,一定要使得name的數組類型與listKey的類型一致。
    比如,name設成String[] users,則listKey就要設成String id;如果name設成Integer[] users,則listKey就要設成Integer id;
修改ftl文件改變輸出方式:
    1.搜索struts2-core-xxx.jar,找到checkboxlist.ftl文件,拷貝出來;
    2.在自己的工程的src下新建template.simple包,放置上述文件;
    3.用文本編輯器打開該文件,修改成自己希望輸出的格式,保存,OK;
例子:
    希望畫面上每3個復選框輸出為一行。
<#--
/*
 * $Id: checkboxlist.ftl 804072 2009-08-14 03:16:35Z musachy $
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
-->
<#assign itemCount = 0/>
<#if parameters.list?exists>
     <@s.iterator value="parameters.list">
         <#assign itemCount = itemCount + 1/>
         <#if parameters.listKey?exists>
             <#assign itemKey = stack.findValue(parameters.listKey)/>
         <#else>
             <#assign itemKey = stack.findValue('top')/>
         </#if>
         <#if parameters.listValue?exists>
             <#assign itemValue = stack.findString(parameters.listValue)/>
         <#else>
             <#assign itemValue = stack.findString('top')/>
         </#if>
 <#assign itemKeyStr=itemKey.toString() />
 <#if (itemCount-1)%3 == 0>
 <tr>
 </#if>
 <td>

 <input type="checkbox" name="${parameters.name?html}" value="${itemKeyStr?html}" id="${parameters.name?html}-${itemCount}"<#rt/>
         <#if tag.contains(parameters.nameValue, itemKey)>
  checked="checked"<#rt/>
         </#if>
         <#if parameters.disabled?default(false)>
  disabled="disabled"<#rt/>
         </#if>
         <#if parameters.title?exists>
  title="${parameters.title?html}"<#rt/>
         </#if>
         <#include "/${parameters.templateDir}/simple/scripting-events.ftl" />
         <#include "/${parameters.templateDir}/simple/common-attributes.ftl" />
 />
 <label for="${parameters.name?html}-${itemCount}" class="checkboxLabel">${itemValue?html}</label>
 </td>
 <#if itemCount%3 == 0>
 </tr>

 </#if>
     </@s.iterator>
</#if>
<input type="hidden" id="__multiselect_${parameters.id?html}" name="__multiselect_${parameters.name?html}" value=""<#rt/>
<#if parameters.disabled?default(false)>
 disabled="disabled"<#rt/>
</#if>
 />

secret_x15 2011-06-14 12:18 發(fā)表評論
]]>
BodyTagSupporthttp://m.tkk7.com/secret/archive/2011/06/14/352277.htmlsecret_x15secret_x15Tue, 14 Jun 2011 04:16:00 GMThttp://m.tkk7.com/secret/archive/2011/06/14/352277.htmlhttp://m.tkk7.com/secret/comments/352277.htmlhttp://m.tkk7.com/secret/archive/2011/06/14/352277.html#Feedback0http://m.tkk7.com/secret/comments/commentRss/352277.htmlhttp://m.tkk7.com/secret/services/trackbacks/352277.html
BodyTagSupport類的方法:
編寫標簽對應的實現類時,需要重載BodyTagSupport類幾個方法:doStartTag(), setBodyContent(), doInitBody(), doAfterBody(), doEndTag();

他們執(zhí)行順序如下:
doStartTag()→doInitBody()→setBodyContent()→doAfterBody()→doEndTag()

doStartTag()方法可返回EVAL_BODY_INCLUDE或SKIP_BODY,
如果返回EVAL_BODY_INCLUDE則繼續(xù)執(zhí)行;
如果返回SKIP_BODY則接下來的doInitBody(),setBodyContent(), doAfterBody()三個方法不會被執(zhí)行,
而直接執(zhí)行doEndTag()方法。

setBodyContent()方法用于設置標簽體內容,如果在此之前要作一些初始化工作,則在doInitBody()方法中完成。
標簽體內容執(zhí)行完后,會調用doAfterBody()方法,此方法可返回EVAL_BODY_TAG, SKIP_BODY,
EVAL_PAGE或SKIP_PAGE。
如果返回EVAL_BODY_TAG則會再次設置標簽體內容,直到返回SKIP_BODY;
如果返回EVAL_PAGE則標簽體執(zhí)行完后會繼續(xù)執(zhí)行JSP頁面中接下來的部分;
如果返回SKIP_PAGE,則JSP頁面的后續(xù)內容將不再執(zhí)行。

標簽中靜態(tài)常量:

EVAL_BODY_INCLUDE:告訴服務器正文的內容,并把這些內容送入輸出流
SKIP_BODY:告訴服務器不要處理正文內容
EVAL_PAGE:讓服務器繼續(xù)執(zhí)行頁面
SKIP_PAGE:讓服務器不要處理剩余的頁面
EVAL_BODY_AGAIN:讓服務器繼續(xù)處理正文內容,只有doAfterBody方法可以返回
EVAL_BODY_BUFFERED:BodyTag接口的字段,在doStartTag()返回
EVAL_BODY_INCLUDE、SKIP_BODY一般由doStartTag()返回,而EVAL_PAPGE、SKIP_PAGE由doEndTag()返回。


secret_x15 2011-06-14 12:16 發(fā)表評論
]]>
TagSupport與BodyTagSupport的區(qū)別http://m.tkk7.com/secret/archive/2011/06/14/352262.htmlsecret_x15secret_x15Tue, 14 Jun 2011 01:54:00 GMThttp://m.tkk7.com/secret/archive/2011/06/14/352262.htmlhttp://m.tkk7.com/secret/comments/352262.htmlhttp://m.tkk7.com/secret/archive/2011/06/14/352262.html#Feedback0http://m.tkk7.com/secret/comments/commentRss/352262.htmlhttp://m.tkk7.com/secret/services/trackbacks/352262.htmlTagSupport與BodyTagSupport的區(qū)別 
標簽: TagSupport與BodyTagSupport的區(qū)別 
1、 TagSupport與BodyTagSupport的區(qū)別

 TagSupport與BodyTagSupport的區(qū)別主要是標簽處理類是否需要與標簽體交互,如果不需要交互的就用TagSupport,否則如果需要交互就用BodyTagSupport。
    交互就是標簽處理類是否要讀取標簽體的內容和改變標簽體返回的內容。
    用TagSupport實現的標簽,都可以用BodyTagSupport來實現,因為BodyTagSupport繼承了TagSupport。
 2 、doStartTag(),doEndTag(),doAfterBody(),
    doStartTag()方法是遇到標簽開始時會呼叫的方法,其合法的返回值是EVAL_BODY_INCLUDE與SKIP_BODY,前者表示將顯示標簽間的文字,后者表示不顯示標簽間的文字;
    doEndTag()方法是在遇到標簽結束時呼叫的方法,其合法的返回值是EVAL_PAGE與 SKIP_PAGE,前者表示處理完標簽后繼續(xù)執(zhí)行以下的JSP網頁,后者是表示不處理接下來的JSP網頁
    doAfterBody()這個方法是在顯示完標簽間文字之后呼叫的,其返回值有EVAL_BODY_AGAIN與SKIP_BODY,前者會再顯示一次標簽間的文字,后者則繼續(xù)執(zhí)行標簽處理的下一步。
EVAL_BODY_INCLUDE:把Body讀入存在的輸出流中,doStartTag()函數可用
EVAL_PAGE:繼續(xù)處理頁面,doEndTag()函數可用
SKIP_BODY:忽略對Body的處理,doStartTag()和doAfterBody()函數可用
SKIP_PAGE:忽略對余下頁面的處理,doEndTag()函數可用
EVAL_BODY_TAG:已經廢止,由EVAL_BODY_BUFFERED取代
EVAL_BODY_BUFFERED:申請緩沖區(qū),由setBodyContent()函數得到的BodyContent對象來處理tag的body,如果類實現了BodyTag,那么doStartTag()可用,否則非法
EVAL_BODY_BUFFERED 要將BodyContent的內容輸出 如:
JspWriter w = pageContext.getOut();
  if (bodyContent != null) {
   if (w instanceof BodyContent) {
    w = ((BodyContent) w).getEnclosingWriter();
   }
  }
  String cnt = this.bodyContent.getString();
  try {
   w.write(cnt);
  } catch (IOException e) {
   e.printStackTrace();
  }

   預定的處理順序是:doStartTag()返回SKIP_BODY,doAfterBodyTag()返回SKIP_BODY,doEndTag()返回EVAL_PAGE.
   如果繼承了TagSupport之后,如果沒有改寫任何的方法,標簽處理的執(zhí)行順序是:

   doStartTag() ->不顯示文字 ->doEndTag()->執(zhí)行接下來的網頁

  如果您改寫了doStartTag(),則必須指定返回值,如果指定了EVAL_BODY_INCLUDE,則執(zhí)行順序是

   doStartTag()->顯示文字->doAfterBodyTag()->doEndTag()->執(zhí)行下面的網頁
display.tld 源碼
xml 代碼:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
    
<tlibversion>1.0</tlibversion>
    
<jspversion>1.1</jspversion>
    
<shortname>bean</shortname>
    
<uri>/WEB-INF/tld/display.tld</uri>
    
<tag>
        
<name>display</name>
        
<tagclass>com.liuzhe.common.DisplayTag</tagclass>
        
<bodycontent>JSP</bodycontent>
        
<info>display content</info>
        
<attribute>
            
<name></name>
            
<required></required>
            
<rtexprvalue></rtexprvalue>
        
</attribute>
    
</tag>
</taglib>

DisplayTag.java 源碼
java 代碼:

package com.liuzhe.common;

import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class DisplayTag extends TagSupport {

    
private static final long serialVersionUID = 4540106083884185193L;

    @Override
    
public int doStartTag() throws JspException {
        System.out.println(
"doStartTag()");
        
return EVAL_BODY_INCLUDE;
    }

    @Override
    
public int doAfterBody() throws JspException {
        System.out.println(
"doAfterBody()");
        
return SKIP_BODY;
    }
    
    @Override
    
public int doEndTag() throws JspException {
        System.out.println(
"doEndTag()");
        JspWriter out 
= this.pageContext.getOut();
        
try {
            out.print(
"hello!");
        } 
catch (IOException e) {
            e.printStackTrace();
        }
        
return super.doEndTag();
    }

}
index.jsp 源碼


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/display.tld" prefix="test" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<test:display>test<br></test:display>
</body>
</html>

注意:這里的“test” 顯示在 hello 前面證明啦 它是先執(zhí)行index.jsp 中標簽中的內容后才執(zhí)行doEndTag()



secret_x15 2011-06-14 09:54 發(fā)表評論
]]>
JAVA編程思想 13.5.4 java 字符串> 格式化字符> 購物收據http://m.tkk7.com/secret/archive/2011/05/24/350909.htmlsecret_x15secret_x15Tue, 24 May 2011 04:47:00 GMThttp://m.tkk7.com/secret/archive/2011/05/24/350909.htmlhttp://m.tkk7.com/secret/comments/350909.htmlhttp://m.tkk7.com/secret/archive/2011/05/24/350909.html#Feedback0http://m.tkk7.com/secret/comments/commentRss/350909.htmlhttp://m.tkk7.com/secret/services/trackbacks/350909.html
import java.util.Formatter;
public class Receipt {
    
private double total = 0;
    
private Formatter f = new Formatter(System.out);
    
    
public void printTitle(){
         f.format(
"%-15s   %5s   %10s\n""Item","Qty","Price");
         f.format(
"%-15s   %5s   %10s\n""----","---","-----");
    }
    
    
public void print(String name,int qty,double price){
         f.format(
"%-15.15s   %5d   %10.2f\n", name,qty,price);
         total 
+= price;
    }
    
    
public void printTotal(){
     f.format(
"%-15.15s   %5s   %10.2f\n""Tax","",total*0.06);
     f.format(
"%-15.15s   %5s   %10s\n""","","-----");
     f.format(
"%-15s   %5s   %10.2f\n""Total","",total*1.06);
    }
    
    
public static void main(String[] args) {
         Receipt receipt 
= new Receipt();
         receipt.printTitle();
         receipt.print(
"Jack's Magic Beans"44.25);
         receipt.print(
"Princess Peas"35.1);
         receipt.print(
"Three Bears Porridge"114.29);
         receipt.printTotal();
    }
    
    
/*
    %[argument_index$][flag][width][.precision]conversion
    在默認的情況下,數據是右對齊,通過“-”標志來改變對齊方向
    width可以用于各種類型的數據轉換
    precision不是所有類型的數據都能使用precision,用于不同數據時的意義不同。
         1.應用于String時,它表示打印String時輸出字符的最大數量。
         2.應用于浮點數時,它表示小數部分顯示出來的位數(默認是6位小數),如果小數位數過多四舍五入,太少尾部補零。
         3.應用于整數時,由于整數沒有小數部分,則會觸發(fā)異常。
    
     
*/
    
}

  類型轉換字符
d 整數類型
e 浮點數(科學計數)
c Unicode字符
x 整數(十六進制)
b Boolean值
h 散列碼(十六進制)
s String % 字符%
f 浮點數(十進制)        



secret_x15 2011-05-24 12:47 發(fā)表評論
]]>
主站蜘蛛池模板: 免费播放在线日本感人片| 久久久久亚洲AV无码去区首| 中文字幕免费观看视频| 亚洲性日韩精品一区二区三区| 久久久久亚洲精品无码网址色欲 | 国产自偷亚洲精品页65页| 男女啪啪免费体验区| 亚洲精品乱码久久久久久蜜桃| 国产av无码专区亚洲av毛片搜| 国产精品免费一级在线观看| 免费看黄网站在线看 | 国产精品国产自线拍免费软件| 亚洲精品伦理熟女国产一区二区| 成人免费视频网址| 亚洲AV成人片无码网站| 亚洲成av人在片观看| 中文字幕一区二区免费| 亚洲一区影音先锋色资源| 久久久久久免费视频| 在线观看亚洲专区| 亚洲精品无码Av人在线观看国产| av永久免费网站在线观看| 亚洲午夜精品在线| 四虎成人精品一区二区免费网站| 国产亚洲情侣久久精品| 好看的电影网站亚洲一区| 精品熟女少妇av免费久久| 久久国产亚洲精品| 久久久久亚洲精品无码网址| 一区二区免费视频| 亚洲午夜无码久久| 亚洲日韩激情无码一区| 免费观看无遮挡www的小视频| 精品久久久久久久久亚洲偷窥女厕| 亚洲人成国产精品无码| 免费观看激色视频网站bd | 青青青青青青久久久免费观看| 一级中文字幕免费乱码专区| 亚洲伦另类中文字幕| 日本午夜免费福利视频| 久久免费公开视频|