
2011年8月2日
import 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(500, 100, 500, 300);
shell.setText("Combo");
shell.setLayout(new GridLayout(3, true));
//創(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();
}
}
posted @
2011-08-02 14:22 secret_x15 閱讀(12896) |
評論 (0) |
編輯 收藏

2011年6月29日
Eclipse添加DTD文件實(shí)現(xiàn)xml的自動提示功能
1.點(diǎn)擊 window -->Preferences -->XML -->XML Catalog -->Add..
2.點(diǎn)擊Add 彈出一個對話框,如圖所示:
:
3.填寫文本框中的內(nèi)容
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. 點(diǎn)擊OK 按鈕,重啟eclipse.
posted @
2011-06-29 18:18 secret_x15 閱讀(5458) |
評論 (0) |
編輯 收藏

2011年6月28日
"window.location.href"、"location.href"是本頁面跳轉(zhuǎn).
"parent.location.href" 是上一層頁面跳轉(zhuǎn).
"top.location.href" 是最外層的頁面跳轉(zhuǎn).
舉例說明:
如果A,B,C,D都是html,D是C的iframe,C是B的iframe,B是A的iframe,如果D中js這樣寫
"window.location.href"、"location.href":D頁面跳轉(zhuǎn)
"parent.location.href":C頁面跳轉(zhuǎn)
"top.location.href":A頁面跳轉(zhuǎn)
如果D頁面中有form的話,
<form>: form提交后D頁面跳轉(zhuǎn)
<form target="_blank">: form提交后彈出新頁面
<form target="_parent">: form提交后C頁面跳轉(zhuǎn)
<form target="_top"> : form提交后A頁面跳轉(zhuǎn)
如果訪問的是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>
posted @
2011-06-28 10:25 secret_x15 閱讀(5495) |
評論 (1) |
編輯 收藏

2011年6月22日
main方法:
public class Test {
public static void main(String[] args) {
/**
*
* sort()方法詳解
* 1.Collections.sort(List<T> list)
* 根據(jù)元素的自然順序 對指定列表按升序進(jìn)行排序。
* 2.Collections.sort(List<T> list, Comparator<? super T> c)
* 根據(jù)指定比較器產(chǎn)生的順序?qū)χ付斜磉M(jìn)行排序。
*
*/
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("===============================================");
//根據(jù)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("===============================================");
//根據(jù)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> {
//根據(jù)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> {
//根據(jù)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;
}
}
}
posted @
2011-06-22 16:03 secret_x15 閱讀(6486) |
評論 (1) |
編輯 收藏

2011年6月21日
jquery radio取值,checkbox取值,select取值,radio選中,checkbox選中,select選中,及其相關(guān)
獲取一組radio被選中項(xiàng)的值
var item = $('input[@name=items][@checked]').val();
獲取select被選中項(xiàng)的文本
var item = $("select[@name=items] option[@selected]").text();
select下拉框的第二個元素為當(dāng)前選中值
$('#select_id')[0].selectedIndex = 1;
radio單選組的第二個元素為當(dāng)前選中值
$('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",'');//清空內(nèi)容
$("#txt").attr("value",'11');//填充內(nèi)容
多選框checkbox:
$("#chk1").attr("checked",'');//不打勾
$("#chk2").attr("checked",true);//打勾
if($("#chk1").attr('checked')==undefined) //判斷是否已經(jīng)打勾
單選組radio:
$("input[@type=radio]").attr("checked",'2');//設(shè)置value=2的項(xiàng)目為當(dāng)前選中項(xiàng)
下拉框select:
$("#sel").attr("value",'-sel3');//設(shè)置value=-sel3的項(xiàng)目為當(dāng)前選中項(xiàng)
$("<option value='1'>1111</option><option value='2'>2222</option>").appendTo("#sel")//添加下拉框的option
$("#sel").empty();//清空下拉框
posted @
2011-06-21 15:00 secret_x15 閱讀(274) |
評論 (0) |
編輯 收藏

2011年6月14日
struts2里增加了一個新的UT標(biāo)簽s:checkboxlist,下面介紹下使用方法。
s:checkboxlist用于畫面上顯示一組復(fù)選框,缺省是橫排輸出,后面將介紹如何修改ftl文件使得它能按任意方式輸出。
標(biāo)簽格式:
<s:checkboxlist name="" list="" listKey="" listValue="" value="" />
name-定義標(biāo)簽名,用于接收畫面上選中的復(fù)選框,故應(yīng)與Action里定義的屬性一致,且多為數(shù)組;
list-定義集合變量,用于輸出復(fù)選框到畫面上,一般在Action里定義一個List或Map屬性;
listKey-如果在Action里定義的是一個List,則往往會在List里定義一個Bean,它只有兩個屬性,其中一個(比如id)就在這里設(shè)置;
如果在Action里定義的是一個Map,則Map的key就在這里設(shè)置;
listValue-如果在Action里定義的是一個List,則往往會在List里定義一個Bean,它只有兩個屬性,另外一個(比如name)就在這里設(shè)置;
如果在Action里定義的是一個Map,則Map的value就在這里設(shè)置;
value-用于回顯畫面上被選中的復(fù)選框,假如畫面有輸入檢查,如果有錯則返回原畫面并顯示出錯信息,這時候就需要使用它。
一般把它設(shè)成和name一致就可以了。
注意點(diǎn):
為了能正確顯示已被選中的復(fù)選框,一定要使得name的數(shù)組類型與listKey的類型一致。
比如,name設(shè)成String[] users,則listKey就要設(shè)成String id;如果name設(shè)成Integer[] users,則listKey就要設(shè)成Integer id;
修改ftl文件改變輸出方式:
1.搜索struts2-core-xxx.jar,找到checkboxlist.ftl文件,拷貝出來;
2.在自己的工程的src下新建template.simple包,放置上述文件;
3.用文本編輯器打開該文件,修改成自己希望輸出的格式,保存,OK;
例子:
希望畫面上每3個復(fù)選框輸出為一行。
<#--
/*
* $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>
/>
posted @
2011-06-14 12:18 secret_x15 閱讀(3154) |
評論 (0) |
編輯 收藏
BodyTagSupport類的方法: 編寫標(biāo)簽對應(yīng)的實(shí)現(xiàn)類時,需要重載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()方法用于設(shè)置標(biāo)簽體內(nèi)容,如果在此之前要作一些初始化工作,則在doInitBody()方法中完成。 標(biāo)簽體內(nèi)容執(zhí)行完后,會調(diào)用doAfterBody()方法,此方法可返回EVAL_BODY_TAG, SKIP_BODY, EVAL_PAGE或SKIP_PAGE。 如果返回EVAL_BODY_TAG則會再次設(shè)置標(biāo)簽體內(nèi)容,直到返回SKIP_BODY; 如果返回EVAL_PAGE則標(biāo)簽體執(zhí)行完后會繼續(xù)執(zhí)行JSP頁面中接下來的部分; 如果返回SKIP_PAGE,則JSP頁面的后續(xù)內(nèi)容將不再執(zhí)行。
標(biāo)簽中靜態(tài)常量:
EVAL_BODY_INCLUDE:告訴服務(wù)器正文的內(nèi)容,并把這些內(nèi)容送入輸出流 SKIP_BODY:告訴服務(wù)器不要處理正文內(nèi)容 EVAL_PAGE:讓服務(wù)器繼續(xù)執(zhí)行頁面 SKIP_PAGE:讓服務(wù)器不要處理剩余的頁面 EVAL_BODY_AGAIN:讓服務(wù)器繼續(xù)處理正文內(nèi)容,只有doAfterBody方法可以返回 EVAL_BODY_BUFFERED:BodyTag接口的字段,在doStartTag()返回 EVAL_BODY_INCLUDE、SKIP_BODY一般由doStartTag()返回,而EVAL_PAPGE、SKIP_PAGE由doEndTag()返回。 |
posted @
2011-06-14 12:16 secret_x15 閱讀(609) |
評論 (0) |
編輯 收藏
TagSupport與BodyTagSupport的區(qū)別
標(biāo)簽: TagSupport與BodyTagSupport的區(qū)別
1、 TagSupport與BodyTagSupport的區(qū)別
TagSupport與BodyTagSupport的區(qū)別主要是標(biāo)簽處理類是否需要與標(biāo)簽體交互,如果不需要交互的就用TagSupport,否則如果需要交互就用BodyTagSupport。
交互就是標(biāo)簽處理類是否要讀取標(biāo)簽體的內(nèi)容和改變標(biāo)簽體返回的內(nèi)容。
用TagSupport實(shí)現(xiàn)的標(biāo)簽,都可以用BodyTagSupport來實(shí)現(xiàn),因?yàn)锽odyTagSupport繼承了TagSupport。
2 、doStartTag(),doEndTag(),doAfterBody(),
doStartTag()方法是遇到標(biāo)簽開始時會呼叫的方法,其合法的返回值是EVAL_BODY_INCLUDE與SKIP_BODY,前者表示將顯示標(biāo)簽間的文字,后者表示不顯示標(biāo)簽間的文字;
doEndTag()方法是在遇到標(biāo)簽結(jié)束時呼叫的方法,其合法的返回值是EVAL_PAGE與 SKIP_PAGE,前者表示處理完標(biāo)簽后繼續(xù)執(zhí)行以下的JSP網(wǎng)頁,后者是表示不處理接下來的JSP網(wǎng)頁
doAfterBody()這個方法是在顯示完標(biāo)簽間文字之后呼叫的,其返回值有EVAL_BODY_AGAIN與SKIP_BODY,前者會再顯示一次標(biāo)簽間的文字,后者則繼續(xù)執(zhí)行標(biāo)簽處理的下一步。
EVAL_BODY_INCLUDE:把Body讀入存在的輸出流中,doStartTag()函數(shù)可用
EVAL_PAGE:繼續(xù)處理頁面,doEndTag()函數(shù)可用
SKIP_BODY:忽略對Body的處理,doStartTag()和doAfterBody()函數(shù)可用
SKIP_PAGE:忽略對余下頁面的處理,doEndTag()函數(shù)可用
EVAL_BODY_TAG:已經(jīng)廢止,由EVAL_BODY_BUFFERED取代
EVAL_BODY_BUFFERED:申請緩沖區(qū),由setBodyContent()函數(shù)得到的BodyContent對象來處理tag的body,如果類實(shí)現(xiàn)了BodyTag,那么doStartTag()可用,否則非法
EVAL_BODY_BUFFERED 要將BodyContent的內(nèi)容輸出 如:
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();
}
預(yù)定的處理順序是:doStartTag()返回SKIP_BODY,doAfterBodyTag()返回SKIP_BODY,doEndTag()返回EVAL_PAGE.
如果繼承了TagSupport之后,如果沒有改寫任何的方法,標(biāo)簽處理的執(zhí)行順序是:
doStartTag() ->不顯示文字 ->doEndTag()->執(zhí)行接下來的網(wǎng)頁
如果您改寫了doStartTag(),則必須指定返回值,如果指定了EVAL_BODY_INCLUDE,則執(zhí)行順序是
doStartTag()->顯示文字->doAfterBodyTag()->doEndTag()->執(zhí)行下面的網(wǎng)頁
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 中標(biāo)簽中的內(nèi)容后才執(zhí)行doEndTag()
posted @
2011-06-14 09:54 secret_x15 閱讀(561) |
評論 (0) |
編輯 收藏

2011年5月24日
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", 4, 4.25);
receipt.print("Princess Peas", 3, 5.1);
receipt.print("Three Bears Porridge", 1, 14.29);
receipt.printTotal();
}
/*
%[argument_index$][flag][width][.precision]conversion
在默認(rèn)的情況下,數(shù)據(jù)是右對齊,通過“-”標(biāo)志來改變對齊方向
width可以用于各種類型的數(shù)據(jù)轉(zhuǎn)換
precision不是所有類型的數(shù)據(jù)都能使用precision,用于不同數(shù)據(jù)時的意義不同。
1.應(yīng)用于String時,它表示打印String時輸出字符的最大數(shù)量。
2.應(yīng)用于浮點(diǎn)數(shù)時,它表示小數(shù)部分顯示出來的位數(shù)(默認(rèn)是6位小數(shù)),如果小數(shù)位數(shù)過多四舍五入,太少尾部補(bǔ)零。
3.應(yīng)用于整數(shù)時,由于整數(shù)沒有小數(shù)部分,則會觸發(fā)異常。
*/
}
類型轉(zhuǎn)換字符
d 整數(shù)類型
e 浮點(diǎn)數(shù)(科學(xué)計(jì)數(shù))
c Unicode字符
x 整數(shù)(十六進(jìn)制)
b Boolean值
h 散列碼(十六進(jìn)制)
s String % 字符%
f 浮點(diǎn)數(shù)(十進(jìn)制)
posted @
2011-05-24 12:47 secret_x15 閱讀(516) |
評論 (0) |
編輯 收藏