这是javascript的范围,到哪里去问问吧。

解决方案 »

  1.   

    关键是处理2月的天数问题,输入年份判断它是否闰年,是则2月为29天,其他几个月建固定数组。
    建立两个JCombobox或JList或字符输入框也可以,一个表年份,一个表月份,然后用Button做ActionListener,取得年份和月份,经逻辑判断,显示该月的日历,详细代码我建议参照类似的程序自己做,这样学学比较快一点
      

  2.   

    我自己曾参考别人的写了一个,你若需要的话,可以修改一下入口参数和返回参数即可。
    附:
    package alpha;
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.border.*;
    import java.lang.*;
    public class DatePopup extends JDialog implements ActionListener {
      //private Color color = SystemColor.text;
      private Font font14 = new Font("Dialog", 0, 14);//统一字体
      private Font font12 = new Font("Dialog", 0, 12);
      private JPanel mPanel1 = new JPanel();
      private JPanel mPanel2 = new JPanel();
      private JPanel mPanel3 = new JPanel();
      private JPanel mPanel4 = new JPanel();
      private JButton mNewButton;
      private JTextField mText;
      private int mDay;
      private int mMonth;
      private int mYear;
      private int mTheDate;
      private int i = 0;
      private int j = 0;
      private JLabel JLabel1 = new JLabel("一",SwingConstants.CENTER);//星期
      private JLabel JLabel2 = new JLabel("二",SwingConstants.CENTER);
      private JLabel JLabel3 = new JLabel("三",SwingConstants.CENTER);
      private JLabel JLabel4 = new JLabel("四",SwingConstants.CENTER);
      private JLabel JLabel5 = new JLabel("五",SwingConstants.CENTER);
      private JLabel JLabel6 = new JLabel("六",SwingConstants.CENTER);
      private JLabel JLabel7 = new JLabel("日",SwingConstants.CENTER);  public DatePopup(Dialog owner, boolean modal, JTextField pText) {
        super(owner, modal);
        this.mText = pText;
        try {
          JLabel1.setFont(font14);
          JLabel2.setFont(font14);
          JLabel3.setFont(font14);
          JLabel4.setFont(font14);
          JLabel5.setFont(font14);
          JLabel6.setFont(font14);
          JLabel7.setFont(font14);
          this.setTitle("选定待查日期");
          this.setResizable(false);
          DatePopupInit();
          pack();
          CenterShowDialog cs = new CenterShowDialog(this);
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }  /**
       * 控件的初始化方法。
       */
      private void DatePopupInit() {
        //设置主窗口布局
        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());
        mPanel1.setLayout(new BorderLayout());
        mPanel1.setBorder(new TitledBorder(BorderFactory.createLineBorder(Color.white,1),"DATE"));
        //mPanel1.setBackground(color);
        Calendar nowCalendar = Calendar.getInstance();
        this.mTheDate = nowCalendar.get(Calendar.DAY_OF_WEEK);
        this.mDay = nowCalendar.get(Calendar.DAY_OF_MONTH);
        this.mMonth = nowCalendar.get(Calendar.MONTH);
        this.mYear = nowCalendar.get(Calendar.YEAR);    //设置mPanel2
        JComboBox comboMonth = new JComboBox();
        comboMonth.setActionCommand("MonthSelect");
        //comboMonth.setBackground(color);
        comboMonth.setFont(font12);
        for(i=1;i<=12;i++) {
          comboMonth.addItem(i+"月");
          if(i==(this.mMonth+1)) {
            comboMonth.setSelectedItem(i+"月");
          }
        }
        comboMonth.addActionListener(this);
        JComboBox comboYear = new JComboBox();    comboYear.setActionCommand("YearSelect");
        //comboYear.setBackground(color);
        comboYear.setFont(font12);
        //设定年份
        for(i=1950;i<=2050;i++) {
          comboYear.addItem(i+"年");
          if(i==this.mYear) {
            comboYear.setSelectedItem(i+"年");
          }
        }
        comboYear.addActionListener(this);
        mPanel2.setLayout(new FlowLayout());
        //mPanel2.setBackground(color);
        mPanel2.add(comboMonth);
        mPanel2.add(comboYear);
        mPanel1.add(mPanel2,BorderLayout.NORTH);    //设置mPanel3
        mPanel3.setLayout(new GridLayout(7,7));
        //mPanel3.setBackground(color);
        mPanel3.add(JLabel7);
        mPanel3.add(JLabel1);
        mPanel3.add(JLabel2);
        mPanel3.add(JLabel3);
        mPanel3.add(JLabel4);
        mPanel3.add(JLabel5);
        mPanel3.add(JLabel6);
        //日历制作
        Calendar calendar1 = Calendar.getInstance();
        calendar1.set(this.mYear,this.mMonth+1,1);
        Calendar calendar2 = Calendar.getInstance();
        calendar2.set(this.mYear,this.mMonth,1);
        int daysOfMonth;
        if(this.mMonth==11) {
          daysOfMonth = 31;
        }
        else {
          daysOfMonth = calendar1.get(Calendar.DAY_OF_YEAR) - calendar2.get(Calendar.DAY_OF_YEAR);
        }
        int firstDay = calendar2.get(Calendar.DAY_OF_WEEK);
        for(i=1;i<43;i++) {
          if(((i==firstDay)||(j!=0))&&(j<daysOfMonth)) {
            j++;
            mNewButton = new JButton((new String()).valueOf(j));
            if(j==this.mDay) {
              mNewButton.setSelected(true);
              mNewButton.setEnabled(false);
              mNewButton.setBackground(new Color(84,215,4));
            }
            mNewButton.addActionListener(this);
            mPanel3.add(mNewButton);
          }
          else {
            mPanel3.add(new JLabel());
          }
        }
        mPanel1.add(mPanel3,BorderLayout.CENTER);
      

  3.   


        //设置mPanel4
        JButton confirmButton = new JButton("确定");
        //confirmButton.setBorder(BorderFactory.createRaisedBevelBorder());
        confirmButton.setFont(font14);
        //confirmButton.setBackground(color);
        confirmButton.setActionCommand("confirm");
        confirmButton.addActionListener(this);
        JButton cancelButton = new JButton("取消");
        cancelButton.setFont(font14);
        //cancelButton.setBackground(color);
        cancelButton.setActionCommand("cancel");
        cancelButton.addActionListener(this);
        mPanel4.setLayout(new FlowLayout());
        mPanel4.add(confirmButton);
        mPanel4.add(cancelButton);
        //mPanel4.setBackground(color);    //设置contentpane
        contentPane.add(mPanel1,BorderLayout.CENTER);
        contentPane.add(mPanel4,BorderLayout.SOUTH);
        //contentPane.setBackground(color);
      }  //监听事件响应。
      public void actionPerformed(ActionEvent e) {
        String cmd = e.getActionCommand();
        Object obj = e.getSource();
        String temp = "";
        if(cmd.equals("MonthSelect")) {
          JComboBox comMonth = (JComboBox)obj;
          temp = comMonth.getSelectedItem().toString();
          temp = temp.substring(0,temp.length()-1);
          int tempMonth = Integer.parseInt(temp);
          this.mMonth = tempMonth-1;
          mypaint();
        }
        else if(cmd.equals("YearSelect")) {
          JComboBox comYear = (JComboBox)obj;
          temp = comYear.getSelectedItem().toString();
          temp = temp.substring(0,4);
          int tempYear = Integer.parseInt(temp);
          this.mYear = tempYear;
          mypaint();
        }
        else if(cmd.equals("confirm")) {//计算返回年月日
          String pFinalDate = "";
          if(this.mMonth<9) {
            pFinalDate = this.mYear + "年0" +(this.mMonth+1);
          }
          else {
            pFinalDate = this.mYear + "年" + (this.mMonth+1);
          }
          if(this.mDay<10) {
            pFinalDate =  pFinalDate + "月0"+ this.mDay + "日";
          }
          else {
            pFinalDate =  pFinalDate + "月"+ this.mDay + "日";
          }
          this.mText.setText(pFinalDate);//返回结果日期
          this.dispose();
        }
        else if(cmd.equals("cancel")) {
          this.dispose();
        }
        else {
          int tempDay = Integer.parseInt(cmd);
          this.mDay = tempDay;
          mypaint();
          //System.out.println(cmd);
        }
      }  /**
       * 控件重新布局方法。
       */
      private void mypaint() {
        this.invalidate();
        mPanel3.removeAll();
        mPanel3.setLayout(new GridLayout(7,7));
        //mPanel3.setBackground(color);
        mPanel3.add(JLabel7);
        mPanel3.add(JLabel1);
        mPanel3.add(JLabel2);
        mPanel3.add(JLabel3);
        mPanel3.add(JLabel4);
        mPanel3.add(JLabel5);
        mPanel3.add(JLabel6);
        Calendar calendar1 = Calendar.getInstance();
        calendar1.set(this.mYear,this.mMonth+1,1);
        Calendar calendar2 = Calendar.getInstance();
        calendar2.set(this.mYear,this.mMonth,1);
        int daysOfMonth;
        if(this.mMonth==11) {
          daysOfMonth = 31;
        }
        else {
          daysOfMonth = calendar1.get(Calendar.DAY_OF_YEAR) - calendar2.get(Calendar.DAY_OF_YEAR);
        }
        int firstDay = calendar2.get(Calendar.DAY_OF_WEEK);
        j = 0;
        for(i=1;i<43;i++) {
          if(((i==firstDay)||(j!=0))&&(j<daysOfMonth)) {
            j++;
            mNewButton = new JButton((new String()).valueOf(j));
            if(j==this.mDay) {
              mNewButton.setSelected(true);
              mNewButton.setEnabled(false);
              mNewButton.setBackground(new Color(84,215,4));
            }
            mNewButton.addActionListener(this);
            mPanel3.add(mNewButton);
          }
          else {
            mPanel3.add(new JLabel());
          }
        }
        mPanel1.add(mPanel3,BorderLayout.CENTER);
        this.validate();
      }
    }
      

  4.   

    select和文本框同样的做法 select也可以通过request.getparameter();得到对应的值
    <html>
    <head>
    <title>
    Jsp1
    </title>
    </head><body>
     <form method="post"action ="Jsp1.jsp">
    <br>Enter new value   :  <input name="sample"><br>
    <br><br>
    <input type="submit" name="Submit" value="Submit">
    <input type="reset" value="Reset">
    <br>
    Value of Bean property is  
    </form>
    <%
       out.println(request.getParameter("sample"));%>
    </body>
    </html>