整体的要求是 
一个页面有两个按钮 按第一个按钮出现一个新画面 弹出新画面同时在新画面上部显示系统时间 然后在新画面另一个text处可以输入天数 与系统时间进行加减法 得出日期型数据  
按第二个按钮也是出现一个新的画面 同时出现系统时间 在另一text处可以输入日期型数据 与系统时间进行减运算 得出天数
对于我出学来说满难的 我知道的类也少 不知道用到那个
首先要构造一个画面有两个按钮 按不同的按钮出现不同的页面 这个我就不知道怎么做了
请大家提示一下吧 或者有代码贴一下写一下 谢谢了 

解决方案 »

  1.   

    这个  用用swing插件吧如果是eclipse的话 其它的IDE也有呀 没必要自己去敲直接拖拽就行
      

  2.   

    Calendar类的set方法可以解决比如
    系统时间是:今天
    你要加或减的天数:5天
    那可以这样
    Calendar ca=Calendar.getInstance();
    ca.set(Calendar.Calendar.DAY_OF_YEAR,Calendar.Calendar.DAY_OF_YEAR+5); //加5天
    //ca.set(Calendar.Calendar.DAY_OF_YEAR,Calendar.Calendar.DAY_OF_YEAR-5); //减5天// 用SimpleDateFormat定义您需要得日期格式。
    // 其中yyyy表示4位数得年份,MM表示2位数得月份,后面依次为 日、时、分、秒。
    SimpleDateFormat sm = new SimpleDateFormat("yyyy-MM-dd");  //构造任意格式
    sm.format(ca.getTime()); //这就是你的新日期
      

  3.   

        /**
         * 按标准格式取得日期的相关几天的日期
         * 日期:strdates
         * 相关几天:nday
         */
        public static String NextYear(String strdates,int nday)
        {
            Calendar c = Calendar.getInstance();
            c.set(Calendar.YEAR,Integer.parseInt(strdates.substring(0,4)));
            c.set(Calendar.MONTH,Integer.parseInt(strdates.substring(5,7)) - 1);
            c.set(Calendar.DATE,Integer.parseInt(strdates.substring(8,10)));
            c.add(Calendar.DATE, nday); //c 加-1天,是昨天的日期        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
            return f.format(c.getTime());
        }
      

  4.   

        /**
         * 取得两个时间段的时间间隔天数
         * return t2 与t1的间隔天数
         * throws ParseException 如果输入的日期格式不是0000-00-00 格式抛出异常
         */
        public static int getBetweenDays(String t1, String t2) throws ParseException {
            DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            int betweenDays = 0;
            Date d1 = format.parse(t1);
            Date d2 = format.parse(t2);
            Calendar c1 = Calendar.getInstance();
            Calendar c2 = Calendar.getInstance();
            c1.setTime(d1);
            c2.setTime(d2);
    // 保证第二个时间一定大于第一个时间
            if (c1.after(c2)) {
                c1 = c2;
                c2.setTime(d1);
            }
            int betweenYears = c2.get(Calendar.YEAR) - c1.get(Calendar.YEAR);
            betweenDays = c2.get(Calendar.DAY_OF_YEAR) - c1.get(Calendar.DAY_OF_YEAR);
            for (int i = 0; i < betweenYears; i++) {
                c1.set(Calendar.YEAR, (c1.get(Calendar.YEAR) + 1));
                betweenDays += c1.getMaximum(Calendar.DAY_OF_YEAR);
            }
            return betweenDays;
        }
      

  5.   

    给你一个小例子
    日期计算可以用Calendar
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;
    import java.util.*;import javax.swing.*;public class SysDateTest {
        
        public static void main(String[] args) {
            new MainFrame();
        }
    }class MainFrame extends JFrame implements ActionListener {
        JButton btn1 = new JButton("button1");
        JButton btn2 = new JButton("button2");
        
        public MainFrame() {
            this.setTitle("Main Frame");
            this.setSize(200, 200);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            
            Container c = this.getContentPane();
            c.setLayout(null);
            btn1.setBounds(20, 20, 80, 20);
            btn2.setBounds(20, 50, 80, 20);
            c.add(btn1);
            c.add(btn2);
            
            btn1.addActionListener(this);
            btn2.addActionListener(this);
            
            int x = (int)((Toolkit.getDefaultToolkit().getScreenSize().getWidth() - this.getWidth())/2);
            int y = (int)((Toolkit.getDefaultToolkit().getScreenSize().getHeight() - this.getHeight())/2);
            this.setLocation(x, y);
            
            this.setVisible(true);
        }
        
        public void actionPerformed(ActionEvent event) {
            Object source = event.getSource();
            Date date = new Date();
            if (source == btn1) {
                new SubDialog(date, 0);
            } else if (source == btn2) {
                new SubDialog(date, 1);
            }
        }
    }class SubDialog extends JDialog implements ActionListener {
        JButton btn1 = new JButton("calculate");
        JButton btn2 = new JButton("close");
        JTextField text = new JTextField();
        JLabel label0 = new JLabel();
        JLabel label1 = new JLabel();
        JLabel label2 = new JLabel();
        Date sysDate;
        int dialogType = 0;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        
        public SubDialog(Date date, int dialogType) {
            this.setTitle("Sub Dialog");
            this.setSize(360, 200);
            this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            
            Container c = this.getContentPane();
            c.setLayout(null);
            label0.setBounds(20, 20, 200, 20);
            text.setBounds(20, 50, 80, 20);
            label1.setBounds(110, 50, 240, 20);
            label2.setBounds(20, 80, 160, 20);
            btn1.setBounds(20, 110, 80, 20);
            btn2.setBounds(110, 110, 80, 20);
            c.add(label0);
            c.add(text);
            c.add(label1);
            c.add(label2);
            c.add(btn1);
            c.add(btn2);
            
            sysDate = date;
            label0.setText("System Date is " + sdf.format(date));
            this.dialogType = dialogType;
            if (dialogType == 1) {
                label1.setText("(Please inpupt a [yyyy-MM-dd] string)");
            } else {
                label1.setText("(Please input a Number)");
            }
            
            btn1.addActionListener(this);
            btn2.addActionListener(this);
            
            int x = (int)((Toolkit.getDefaultToolkit().getScreenSize().getWidth() - this.getWidth())/2);
            int y = (int)((Toolkit.getDefaultToolkit().getScreenSize().getHeight() - this.getHeight())/2);
            this.setLocation(x, y);
            
            this.setModal(true);
            this.setVisible(true);
            
        }
        
        public void actionPerformed(ActionEvent event) {
            Object source = event.getSource();
            if (source == btn1) {
                if (dialogType == 1) {
                    calculateCount();
                } else {
                    calculateDate();
                }
            } else if (source == btn2) {
                this.dispose();
            }
        }
        
        private void calculateCount() {
            try {
                String s = text.getText();
                Date date = sdf.parse(s);
                int count = 0;
                Calendar c1 = Calendar.getInstance();
                c1.setTime(sysDate);
                Calendar c2 = Calendar.getInstance();
                c2.setTime(date);
                
                if (date.before(sysDate)) {
                    while (c2.after(c1) == false) {
                        count++;
                        c2.add(Calendar.DATE, 1);
                    }
                    count *= -1;
                } else {
                    while (c2.before(c1) == false) {
                        count++;
                        c2.add(Calendar.DATE, -1);
                    }
                }
                
                label2.setText("The date count is [" + count + "]");
                
            } catch (Throwable e) {
                label2.setText("input date error.");
            }
        }
        
        private void calculateDate() {
            try {
                String s = text.getText();
                int count = Integer.valueOf(s).intValue();
                Calendar c1 = Calendar.getInstance();
                c1.setTime(sysDate);
                c1.add(Calendar.DATE, count);            
                label2.setText("The date is [" + sdf.format(c1.getTime()) + "]");
                
            } catch (Throwable e) {
                label2.setText("input date error.");
            }
        }
    }
      

  6.   

    运行的时候最大化,布局具体弄好了,大小我没有时间弄了,但是思路就这样。import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import java.awt.Frame;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.Dimension;import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JPanel;public class SwingDemo extends Frame implements ActionListener{ /**
     * 
     */
    private static final long serialVersionUID = 1L;

    BorderLayout borderLayout1 = new BorderLayout();
    BorderLayout borderLayout2 = new BorderLayout();
    BorderLayout borderLayout3 = new BorderLayout();
    FlowLayout flowLayout1 = new FlowLayout();
    FlowLayout flowLayout2 = new FlowLayout();

    JPanel jPMain = new JPanel();
    JPanel jPCenter = new JPanel();
    JPanel jPSouth = new JPanel();
    JPanel jPNorth = new JPanel();

    JLabel jLabelAdd = new JLabel();
    JLabel jLabelJian = new JLabel();
    JButton jBtnAdd = new JButton();
    JButton jBtnJian = new JButton();

    public SwingDemo(){
    jbInit();
    }

    public void jbInit(){
    this.setLayout(borderLayout1);
    jPMain.setLayout(borderLayout2);
    jPNorth.setLayout(flowLayout1);
    jPSouth.setLayout(flowLayout2);

    this.add(jPMain,BorderLayout.CENTER);
    jPMain.add(jPCenter,BorderLayout.CENTER);
    jPCenter.add(jPNorth,BorderLayout.NORTH);
    jPCenter.add(jPSouth,BorderLayout.SOUTH);
    jPNorth.add(jLabelAdd,null);
    jPNorth.add(jBtnAdd,null);
    jPSouth.add(jLabelJian,null);
    jPSouth.add(jBtnJian,null);

    jLabelAdd.setPreferredSize(new Dimension(63,23));
    jLabelJian.setPreferredSize(new Dimension(63,23));
    jBtnAdd.setPreferredSize(new Dimension(63,23));
    jBtnJian.setPreferredSize(new Dimension(63,23));
    jLabelAdd.setText("增加");
    jBtnAdd.setText("增加");
    jLabelJian.setText("减少");
    jBtnJian.setText("减少"); jBtnAdd.addActionListener(this);
    jBtnJian.addActionListener(this);

    this.setVisible(true);
    this.setSize(1000,1000); 
    } public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    if(e.getSource().equals("jBtnAdd")){
    //new一个增加的类,如frameADd frameADdDemo = new frameADd ();
    }
    else if(e.getSource().equals("jBtnJian")){
    //new一个减少的窗体,如frameJian frameJianDemo = new frameJian ();
    }
    }
    public static void main(String [] args){
    SwingDemo a = new SwingDemo();
    }

    }
      

  7.   

    /**
     * CSV作成日
     */
    private String getOutputDay() {
    String strskkrtdt = "";
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MONTH, -1);
    DateFormat dfm = new SimpleDateFormat("yyyyMMdd");
    strskkrtdt = dfm.format(cal.getTime());
    // 判断是否是现在的时刻0点到7点
    if (Integer.parseInt(this.qlcUtil.getHh()) <= 7) {

    cal.add(Calendar.DATE, -1);
    strskkrtdt = dfm.format(cal.getTime());
    }
    return strskkrtdt.substring(0,6);
    }