selctrl.java

来自「文件的上传和下载的实现,用JAva编写,非常简单」· Java 代码 · 共 68 行

JAVA
68
字号
package edu.whut.cwts.pg.db;

import java.util.*;


public class SelCtrl
{
    public static String toSelStr(ArrayList sels)
    {
        String result = "";
        for (int i = 0; i < sels.size(); i++)
        {
            Sel sel = (Sel) sels.get(i);
            result += "<option value=\""
                    + sel.getValue()
                    + "\">"
                    + sel.getName()
                    + "</option>";
        }
        return result;
    }

    public static String toSelStr(ArrayList sels, String selected)
    {
        if (selected == null || selected.equals("null"))
        {
            return toSelStr(sels);
        }
        String result = "";
        for (int i = 0; i < sels.size(); i++)
        {
            Sel sel = (Sel) sels.get(i);
            result += "<option value=\"" + sel.getValue() + "\" ";
            if (sel.getValue().equals(selected))
                result += " selected ";
            result += ">" + sel.getName() + "</option>";
        }
        return result;
    }

    public static String toSelStr(ArrayList sels, int selected)
    {
        return toSelStr(sels, selected + "");
    }

    public static String toSelStr(ArrayList sels, String[] selected)
    {
        String result = "";
        for (int i = 0; i < sels.size(); i++)
        {
            Sel sel = (Sel) sels.get(i);
            result += "<option value='" + sel.getValue() + "' ";
            for (int j = 0; j < selected.length; j++)
            {
                if (selected[j].equals(sel.getValue()))
                {
                    result += " selected ";
                    break;
                }
            }
            result += ">" + sel.getName() + "</option>";
        }
        return result;
    }

  

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?