我用swing日期控件做了个选取日期的程序.叫MyCalender.java..当我选取某一天就返回当天字符串如20091202.在另一个文件里写了另一个swing我想当我点取这张页面的一个按钮button2我就处发一个事件,让我得到MyCalender,java返回的值..而那个button的促发事件的返回值是个void,( public void jButton2_actionPerformed(ActionEvent e) )我要怎么才能得到日期字符串并把它付值给一个方法..
说明一下.我要做一个程序.当我选取某一天的日期的时候.我就会把当天的安符串传给一个servlet.然后servlet会通过URLConnection连接找到某一天日期的文件.这样我就可以得到选取那天的全部文件并通过我写的swing下载了.
我就是不知道怎么把这个日期字符串传给servlet..希望各位指点一下

解决方案 »

  1.   

    保存结果到类成员变量里面。随时取用。jButton2_actionPerformed?
    用的什么可视化工具了?
      

  2.   

    我还是贴代码吧..这个是主swing..当我选取日期时就可以把值传给getFile 方法里的url
    public class MyFirstFrame extends JFrame {
            JList list;        public static void main(String[] args) throws IOException {
                    MyFirstFrame mf = new MyFirstFrame();
                    mf.setVisible(true);
            }        public MyFirstFrame() throws HeadlessException {
                    super();
                    try {
                            jbInit();
                    } catch (Exception ex) {
                            ex.printStackTrace();
                    }
            }        public MyFirstFrame(GraphicsConfiguration gc) {
                    super(gc);
            }        public MyFirstFrame(String title) throws HeadlessException {
                    super(title);
            }        public MyFirstFrame(String title, GraphicsConfiguration gc) {
                    super(title, gc);
            }        BorderLayout borderLayout1 = new BorderLayout();
            JPanel jPanel1 = new JPanel();
        JButton jButton1 = new JButton();
        JButton jButton2 = new JButton();    private void jbInit() throws Exception {
                    this.getContentPane().setLayout(borderLayout1);
                    this.getContentPane().setBackground(SystemColor.inactiveCaption);
            this.addHierarchyBoundsListener(new
                    MyFirstFrame_this_hierarchyBoundsAdapter(this));
            jPanel1.setBackground(Color.lightGray);
                    jPanel1.setMinimumSize(new Dimension(52, 20));
                    jPanel1.setPreferredSize(new Dimension(10, 30));
            jButton1.setAlignmentX((float) 1.0);
                    jButton1.setAlignmentY((float) 1.0);
                    jButton1.setBorder(BorderFactory.createLoweredBevelBorder());
                    jButton1.setPreferredSize(new Dimension(22, 23));
                    jButton1.setToolTipText("");
                    jButton1.setHorizontalTextPosition(SwingConstants.CENTER);
                    jButton1.setMnemonic('0');
                    jButton1.setText("下载");
                    jButton1.addActionListener(new MyFirstFrame_jButton1_actionAdapter(this));                
                    UrlCon co = new UrlCon();
                    List l = co.getFile();
                    for (int i = 0; i < l.size(); i++) {
                            if (l.get(i).equals("WEB-INF")) {
                                    l.remove(i);
                            }
                    }
                    Object[] str = new Object[l.size()];
                    str = l.toArray();
                    final DefaultListModel model = new DefaultListModel();
                    for (int i = 0, n = str.length; i < n; i++) {
                            model.addElement(str[i]);
                    }
                    list = new JList(model);
                    setSize(600, 400);
            jButton2.setForeground(Color.red);
            jButton2.setToolTipText("");
            jButton2.setText("请选择日期");
            jButton2.addActionListener(new MyFirstFrame_jButton2_actionAdapter(this));
            this.getContentPane().add(jButton1, java.awt.BorderLayout.SOUTH);
                    //this.getContentPane().add(list, java.awt.BorderLayout.CENTER);
                    this.getContentPane().add(new JScrollPane(list), java.awt.BorderLayout.CENTER);
            this.getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
            jPanel1.add(jButton2);
        }
    事件按钮
     public void jButton2_actionPerformed(ActionEvent e) {
         JFrame frame = new JFrame("Calendar Application"); 
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
            MyCalendar myCalendar = new MyCalendar(); 
            myCalendar.init(); 
            frame.getContentPane().add(myCalendar); 
            frame.setSize(240, 172); 
            frame.show(); 
           
        }
    class UrlCon{
     public ArrayList getFile() throws IOException {
                    ArrayList l = new ArrayList();
                    try {
                            //URL url = new URL("http://localhost:8080/ftpdowns/MyServlet");
                            //URL url=new URL("http://136.5.68.7:8080/creport/files/20091130/xlsfiles/");
                            URL url=new URL("http://136.5.68.7:8080/creport/filelist?dir=20091130");
                            HttpURLConnection urlcon = (HttpURLConnection) url.openConnection();
                            // urlcon.setDoOutput(true);
                            // urlcon.setDoInput(true);
                            urlcon.connect();
                            BufferedReader in = new BufferedReader(new InputStreamReader(urlcon
                                            .getInputStream()));
                            String inputLine;
                            /*
                            while ((inputLine = in.readLine()) != null) {
                                    if(inputLine.substring(0, 2).equals("<a")){
                                            String regex="(CDMA.*?xls)"; 
                                            Pattern p= Pattern.compile(regex);
                                             Matcher m= p.matcher(inputLine);
                                             while (m.find()) { 
                                                     if(decode(m.group()).substring(0, 5).equals("CDMA网"))
                                                             l.add(decode(m.group()));                                               }     
                                    }
                            }
                            */
                            while ((inputLine = in.readLine()) != null) {
                                    l.add(inputLine);
                            }
                    } catch (MalformedURLException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                    }
                    return l;
    }}
      

  3.   

    当我选取某一天时就会返回当天日期字符串
    package com.ui;import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;public class MyCalendar extends JApplet {    public static final String WEEK_SUN = "日";    public static final String WEEK_MON = "一";    public static final String WEEK_TUE = "二";    public static final String WEEK_WED = "三";    public static final String WEEK_THU = "四";    public static final String WEEK_FRI = "五";    public static final String WEEK_SAT = "六";    public static final Color background = Color.white;    public static final Color foreground = Color.black;    public static final Color headerBackground = Color.blue;    public static final Color headerForeground = Color.white;    public static final Color selectedBackground = Color.blue;    public static final Color selectedForeground = Color.white;
        String date;    private JPanel cPane;    private JLabel yearsLabel;    private JSpinner yearsSpinner;    private JLabel monthsLabel;    private JComboBox monthsComboBox;    private JTable daysTable;    private AbstractTableModel daysModel;    private Calendar calendar;    private String value;
            public String getDate() {
    return date;
    } public void setDate(String date) {
    this.date = date;
    } public String getValue() {
            return this.value;
        }    public MyCalendar() {
            cPane = (JPanel) getContentPane();
        }    public void init() {
            cPane.setLayout(new BorderLayout());        calendar = Calendar.getInstance();
            calendar = Calendar.getInstance();
            yearsLabel = new JLabel("年: ");
            yearsSpinner = new JSpinner();
            yearsSpinner.setEditor(new JSpinner.NumberEditor(yearsSpinner, "0000"));
            yearsSpinner.setValue(new Integer(calendar.get(Calendar.YEAR)));
            yearsSpinner.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent changeEvent) {
                    int day = calendar.get(Calendar.DAY_OF_MONTH);
                    calendar.set(Calendar.DAY_OF_MONTH, 1);
                    calendar.set(Calendar.YEAR, ((Integer) yearsSpinner.getValue())
                            .intValue());
                    int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
                    calendar
                            .set(Calendar.DAY_OF_MONTH, day > maxDay ? maxDay : day);
                    updateView();
                }
            });        JPanel yearMonthPanel = new JPanel();
            cPane.add(yearMonthPanel, BorderLayout.NORTH);
            yearMonthPanel.setLayout(new BorderLayout());
            yearMonthPanel.add(new JPanel(), BorderLayout.CENTER);
            JPanel yearPanel = new JPanel();
            yearMonthPanel.add(yearPanel, BorderLayout.WEST);
            yearPanel.setLayout(new BorderLayout());
            yearPanel.add(yearsLabel, BorderLayout.WEST);
            yearPanel.add(yearsSpinner, BorderLayout.CENTER);        monthsLabel = new JLabel("月: ");
            monthsComboBox = new JComboBox();
            for (int i = 1; i <= 12; i++) {
                monthsComboBox.addItem(new Integer(i));
            }
            monthsComboBox.setSelectedIndex(calendar.get(Calendar.MONTH));
            monthsComboBox.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent actionEvent) {
                    int day = calendar.get(Calendar.DAY_OF_MONTH);
                    calendar.set(Calendar.DAY_OF_MONTH, 1);
                    calendar.set(Calendar.MONTH, monthsComboBox.getSelectedIndex());
                    int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
                    calendar
                            .set(Calendar.DAY_OF_MONTH, day > maxDay ? maxDay : day);
                    updateView();
                }
            });
            JPanel monthPanel = new JPanel();
            yearMonthPanel.add(monthPanel, BorderLayout.EAST);
            monthPanel.setLayout(new BorderLayout());
            monthPanel.add(monthsLabel, BorderLayout.WEST);
            monthPanel.add(monthsComboBox, BorderLayout.CENTER);        daysModel = new AbstractTableModel() {
                public int getRowCount() {
                    return 7;
                }            public int getColumnCount() {
                    return 7;
                }            public Object getValueAt(int row, int column) {
                    if (row == 0) {
                        return getHeader(column);
                    }
                    row--;
                    Calendar calendar = (Calendar) MyCalendar.this.calendar.clone();
                    calendar.set(Calendar.DAY_OF_MONTH, 1);
                    int dayCount = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
                    int moreDayCount = calendar.get(Calendar.DAY_OF_WEEK) - 1;
                    int index = row * 7 + column;
                    int dayIndex = index - moreDayCount + 1;
                    if (index < moreDayCount || dayIndex > dayCount) {
                        return null;
                    } else {
                        return new Integer(dayIndex);
                    }
                }
            };        daysTable = new CalendarTable(daysModel, calendar);
            daysTable.setCellSelectionEnabled(true);
            daysTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);        daysTable.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent e) {
                    if (e.getClickCount() == 2) {
                        Object o = daysTable.getValueAt(daysTable.getSelectedRow(),
                                daysTable.getSelectedColumn());
                        if (o != null) {
                            // 不是点在空的格子,赋值
                            value = yearsSpinner.getValue()
                                    + monthsComboBox.getSelectedItem().toString()
                                    + o;
                            System.out.println(value);
                       
                           
                        } else {
                            // 否则清空
                            value = "";
                        }                }
                }
            });
            daysTable.setDefaultRenderer(daysTable.getColumnClass(0),
                    new TableCellRenderer() {
                        public Component getTableCellRendererComponent(
                                JTable table, Object value, boolean isSelected,
                                boolean hasFocus, int row, int column) {
                            String text = (value == null) ? "" : value.toString();
                            JLabel cell = new JLabel(text);
                            cell.setOpaque(true);
                            if (row == 0) {
                                cell.setForeground(headerForeground);
                                cell.setBackground(headerBackground);
                            } else {
                                if (isSelected) {
                                    cell.setForeground(selectedForeground);
                                    cell.setBackground(selectedBackground);
                                } else {
                                    cell.setForeground(foreground);
                                    cell.setBackground(background);
                                }
                            }                        return cell;
                        }
                    });
            updateView();        cPane.add(daysTable, BorderLayout.CENTER);
        }    public static String getHeader(int index) {
            switch (index) {
            case 0:
                return WEEK_SUN;
            case 1:
                return WEEK_MON;
            case 2:
                return WEEK_TUE;
            case 3:
                return WEEK_WED;
            case 4:
                return WEEK_THU;
            case 5:
                return WEEK_FRI;
            case 6:
                return WEEK_SAT;
            default:
                return null;
            }
        }    public void updateView() {
            daysModel.fireTableDataChanged();
            daysTable.setRowSelectionInterval(calendar.get(Calendar.WEEK_OF_MONTH),
                    calendar.get(Calendar.WEEK_OF_MONTH));
            daysTable.setColumnSelectionInterval(
                    calendar.get(Calendar.DAY_OF_WEEK) - 1, calendar
                            .get(Calendar.DAY_OF_WEEK) - 1);
        }    public static class CalendarTable extends JTable {
            private Calendar calendar;        public CalendarTable(TableModel model, Calendar calendar) {
                super(model);
                this.calendar = calendar;
            }        public void changeSelection(int row, int column, boolean toggle,
                    boolean extend) {
                super.changeSelection(row, column, toggle, extend);
                if (row == 0) {
                    return;
                }
                Object obj = getValueAt(row, column);
                if (obj != null) {
                    calendar.set(Calendar.DAY_OF_MONTH, ((Integer) obj).intValue());
                }
            }    }    public static void main(String[] args) {
            JFrame frame = new JFrame("Calendar Application");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            MyCalendar myCalendar = new MyCalendar();
            myCalendar.init();
            frame.getContentPane().add(myCalendar);
            frame.setSize(240, 172);
            frame.show();    }}
      

  4.   

    但看代码是c/s结构,而你为什么要传给servlet,这样到底是c/s还是b/s结构了?
      

  5.   

    传给servlet是为了获得tomcat文件夹下的文件列表....
    界面是用swing做的
      

  6.   

    要传的办法也有啊,例如socket,或者整一个临时公共文件(session不知道行不行,没试过)
      

  7.   


    请问,你是要在这个地方打开日期选择的控件?并且获取日期?
    因为没看到你在那里使用这个方法,哪个按钮触发,所以我很奇怪。而且按钮的ACtion监听好像这样也触发不了。说句闲话,frame.show();已经过时,jdk推荐不使用。用setVisible(true);
      

  8.   


    就是在那里获得日期控件的..因为以前没做过swing所以有很多问题不明白.还需要改哪里希望指点一下..谢谢
      

  9.   

    难道不能用button去触发事件...那该用什么
      

  10.   

    点击button的时候是触发一个事件,这个事件是发给EventQueue的。所以不存在返回值。别在这个上面浪费时间了。
    java有一个现成的颜色选择控件:JColorChooser,它的功能和你说的这个比较类似。你可以去看看它的源代码。
    一般这样用:
    Color c = JColorChooser.showDialog(component, "JColorChooser", new Color(255,0,0));
    弹出一个选择颜色的对话框,你选择一个颜色,点确定以后,返回一个你选择的那个颜色。
    另外,我们常用的还有一种方法:
    JOptionPane.showOptionDialog
    它也是弹出一个模态对话框,等你选择一个东西选项后,返回你选择的值给你。
    但是你要注意,这两个方法都是静态方法,它内部可能是通过消息来传递值。
      

  11.   

    swing不太懂,进来学习,顺便接分
      

  12.   

    这跟是不是使用Swing没有太大关系。
    呃……你的日期控件是一个JApplet ?虽说也行,但是,一般这样的情形,放一个JDialog比较好吧。
    那就不需要你再套一层窗口了。
    你等一下吧,我写小一段代码。你看了就明白,不然敲键盘手指头疼了也未必能说明白哦
      

  13.   

        public static Color showDialog(Component component,
            String title, Color initialColor) throws HeadlessException {        final JColorChooser pane = new JColorChooser(initialColor != null?
                                                   initialColor : Color.white);        ColorTracker ok = new ColorTracker(pane);
            JDialog dialog = createDialog(component, title, true, pane, ok, null);        dialog.show(); // blocks until user brings dialog down...        return ok.getColor();
        }
    我把JColorChooser#showDialog代码贴出来,你可以借鉴一下。
    注意这里:
            ColorTracker ok = new ColorTracker(pane);
            JDialog dialog = createDialog(component, title, true, pane, ok, null);
    把ok作为一个参数传递个了dialog,dialog中对ok的颜色进行set。
    最后把ok中的value取出来,作为返回值。
      

  14.   

    我把你的代码作了修改。你的MyFirstFrame我就不管了。我用了你这个名字但是我只放了一个按钮。
    我不多说了。代码放在这里,你自己看。当然有更好的方法,我就先不说了,封装的方法也不唯一。你慢慢摸索就是。
    另,你说是web,我就没有使用静态存实例,每次new MyCalendar出来。ie6中使用静态的是有问题,firefox没发现,其他没试。日期控件那个类我进行了修改,关注一下构造函数,继承的基类。
    个人认为与其说些乱七八糟的话倒是不如动手做写实实在在的工作。
    多说无益,代码附下:import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;public class MyCalendar extends JDialog { public static final String WEEK_SUN = "日"; public static final String WEEK_MON = "一"; public static final String WEEK_TUE = "二"; public static final String WEEK_WED = "三"; public static final String WEEK_THU = "四"; public static final String WEEK_FRI = "五"; public static final String WEEK_SAT = "六"; public static final Color background = Color.white; public static final Color foreground = Color.black; public static final Color headerBackground = Color.blue; public static final Color headerForeground = Color.white; public static final Color selectedBackground = Color.blue; public static final Color selectedForeground = Color.white;
    String date; private JPanel cPane; private JLabel yearsLabel; private JSpinner yearsSpinner; private JLabel monthsLabel; private JComboBox monthsComboBox; private JTable daysTable; private AbstractTableModel daysModel; private Calendar calendar; private String value; public String getDate() {
    return date;
    } public void setDate(String date) {
    this.date = date;
    } public String getValue() {
    return this.value;
    } public MyCalendar() {
    cPane = (JPanel) getContentPane();
    setSize(new Dimension(400, 200));
    setModal(true);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    init();
    } public void init() {
    cPane.setLayout(new BorderLayout()); calendar = Calendar.getInstance();
    calendar = Calendar.getInstance();
    yearsLabel = new JLabel("年: ");
    yearsSpinner = new JSpinner();
    yearsSpinner.setEditor(new JSpinner.NumberEditor(yearsSpinner, "0000"));
    yearsSpinner.setValue(new Integer(calendar.get(Calendar.YEAR)));
    yearsSpinner.addChangeListener(new ChangeListener() {
    public void stateChanged(ChangeEvent changeEvent) {
    int day = calendar.get(Calendar.DAY_OF_MONTH);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.YEAR, ((Integer) yearsSpinner.getValue())
    .intValue());
    int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    calendar
    .set(Calendar.DAY_OF_MONTH, day > maxDay ? maxDay : day);
    updateView();
    }
    }); JPanel yearMonthPanel = new JPanel();
    cPane.add(yearMonthPanel, BorderLayout.NORTH);
    yearMonthPanel.setLayout(new BorderLayout());
    yearMonthPanel.add(new JPanel(), BorderLayout.CENTER);
    JPanel yearPanel = new JPanel();
    yearMonthPanel.add(yearPanel, BorderLayout.WEST);
    yearPanel.setLayout(new BorderLayout());
    yearPanel.add(yearsLabel, BorderLayout.WEST);
    yearPanel.add(yearsSpinner, BorderLayout.CENTER); monthsLabel = new JLabel("月: ");
    monthsComboBox = new JComboBox();
    for (int i = 1; i <= 12; i++) {
    monthsComboBox.addItem(new Integer(i));
    }
    monthsComboBox.setSelectedIndex(calendar.get(Calendar.MONTH));
    monthsComboBox.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent actionEvent) {
    int day = calendar.get(Calendar.DAY_OF_MONTH);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.MONTH, monthsComboBox.getSelectedIndex());
    int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    calendar
    .set(Calendar.DAY_OF_MONTH, day > maxDay ? maxDay : day);
    updateView();
    }
    });
    JPanel monthPanel = new JPanel();
    yearMonthPanel.add(monthPanel, BorderLayout.EAST);
    monthPanel.setLayout(new BorderLayout());
    monthPanel.add(monthsLabel, BorderLayout.WEST);
    monthPanel.add(monthsComboBox, BorderLayout.CENTER); daysModel = new AbstractTableModel() {
    public int getRowCount() {
    return 7;
    } public int getColumnCount() {
    return 7;
    } public Object getValueAt(int row, int column) {
    if (row == 0) {
    return getHeader(column);
    }
    row--;
    Calendar calendar = (Calendar) MyCalendar.this.calendar.clone();
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    int dayCount = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    int moreDayCount = calendar.get(Calendar.DAY_OF_WEEK) - 1;
    int index = row * 7 + column;
    int dayIndex = index - moreDayCount + 1;
    if (index < moreDayCount || dayIndex > dayCount) {
    return null;
    } else {
    return new Integer(dayIndex);
    }
    }
    }; daysTable = new CalendarTable(daysModel, calendar);
    daysTable.setCellSelectionEnabled(true);
    daysTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); daysTable.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(java.awt.event.MouseEvent e) {
    if (e.getClickCount() == 2) {
    Object o = daysTable.getValueAt(daysTable.getSelectedRow(),
    daysTable.getSelectedColumn());
    if (o != null) {
    // 不是点在空的格子,赋值
    value = yearsSpinner.getValue()
    + monthsComboBox.getSelectedItem().toString()
    + o;
    // System.out.println(value); } else {
    // 否则清空
    value = "";
    } dispose();
    }
    }
    });
    daysTable.setDefaultRenderer(daysTable.getColumnClass(0),
    new TableCellRenderer() {
    public Component getTableCellRendererComponent(
    JTable table, Object value, boolean isSelected,
    boolean hasFocus, int row, int column) {
    String text = (value == null) ? "" : value.toString();
    JLabel cell = new JLabel(text);
    cell.setOpaque(true);
    if (row == 0) {
    cell.setForeground(headerForeground);
    cell.setBackground(headerBackground);
    } else {
    if (isSelected) {
    cell.setForeground(selectedForeground);
    cell.setBackground(selectedBackground);
    } else {
    cell.setForeground(foreground);
    cell.setBackground(background);
    }
    } return cell;
    }
    });
    updateView(); cPane.add(daysTable, BorderLayout.CENTER);
    } public static String getHeader(int index) {
    switch (index) {
    case 0:
    return WEEK_SUN;
    case 1:
    return WEEK_MON;
    case 2:
    return WEEK_TUE;
    case 3:
    return WEEK_WED;
    case 4:
    return WEEK_THU;
    case 5:
    return WEEK_FRI;
    case 6:
    return WEEK_SAT;
    default:
    return null;
    }
    } public void updateView() {
    daysModel.fireTableDataChanged();
    daysTable.setRowSelectionInterval(calendar.get(Calendar.WEEK_OF_MONTH),
    calendar.get(Calendar.WEEK_OF_MONTH));
    daysTable.setColumnSelectionInterval(
    calendar.get(Calendar.DAY_OF_WEEK) - 1, calendar
    .get(Calendar.DAY_OF_WEEK) - 1);
    } public static class CalendarTable extends JTable {
    private Calendar calendar; public CalendarTable(TableModel model, Calendar calendar) {
    super(model);
    this.calendar = calendar;
    } public void changeSelection(int row, int column, boolean toggle,
    boolean extend) {
    super.changeSelection(row, column, toggle, extend);
    if (row == 0) {
    return;
    }
    Object obj = getValueAt(row, column);
    if (obj != null) {
    calendar.set(Calendar.DAY_OF_MONTH, ((Integer) obj).intValue());
    }
    } }}import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import javax.swing.JButton;
    import javax.swing.JFrame;public class MyFirstFrame extends JFrame { private static final long serialVersionUID = 1L; private String selectedDate = ""; public MyFirstFrame() {
    super(); Container c = getContentPane();
    c.setLayout(new FlowLayout());
    JButton b = new JButton("Date select");
    c.add(b); b.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
    MyCalendar ca = new MyCalendar();
    // some calendar init work here
    ca.setVisible(true); selectedDate = ca.getValue();
    System.out.println(selectedDate);
    }
    }); setSize(600, 400);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setLocationRelativeTo(null);
    setVisible(true);
    } public static void main(String[] args) {
    new MyFirstFrame();
    }
    }
      

  15.   

    以上,MyFirstFrame 中的selectedDate 就有值了,你可以随意使用。
    其他的传递等等工作,我就不了解了。按照需要去做吧。
      

  16.   

    在MyFirstFrame类中添加个成员变量strDate记录选择的日期值
    之后传递给UrlCon类的getFile方法就可以了
    你的程序还是有些问题,
    UrlCon co = new UrlCon();List l = co.getFile(); 应该放到下载按钮的事件中
    public class MyFirstFrame extends JFrame { 
        private strDate = null;
        ……
        //strDate = 选择的日期;按照16楼的方法得到日期值
        UrlCon co = new UrlCon();
        List l = co.getFile(strDate); 
    }
    class UrlCon{
    public ArrayList getFile(String strDate) throws IOException {
                    ArrayList l = new ArrayList();
                    try {
                            URL url=new URL("http://136.5.68.7:8080/creport/filelist?dir="+strDate);
                            ……
                    }catch(Exception e){
                    }
    }