我下了一段java代码,但是代码里有一段设置了开始时间和终止时间,但其之间只相差一个月,我想要开始时间和终止时间相差半年(我要的是让他运行后(比如今天运行)则自动在终止时间是今天的日期2006年7月29日,而开始时间是半年前的时间即是2006年1月28日 ),但不知如何修改代码,请高手指定。代码运行后如图
其代码如下请高手指定我应如何修改代码才能使得开始时间和终止时间之间默认能相差半年或是一年(我要的是让他运行后(比如今天运行)则自动在终止时间是今天的日期2006年7月29日,而开始时间是半年前的时间即是2006年1月28日 )
import java.awt.*;
import java.awt.event.*;
import java.util.Calendar;
import java.util.Date;
public class TimeDialog extends Dialog
implements WindowListener, MouseListener, ItemListener, ActionListener
{
private Button m_btOk;
private Button m_btClose;
private ModelCanvas m_oModelCanvas;
private Point m_oSize;
private Point m_oPosition;
private TextField m_oInputYearA;
private TextField m_oInputMonthA;
private TextField m_oInputDayA;
private TextField m_oInputYearB;
private TextField m_oInputMonthB;
private TextField m_oInputDayB;
private Choice m_chioceLeixing;
private Label m_lbTimeA;
private Label m_lbTimeB;
private Label m_lbYA;
private Label m_lbYB;
private Label m_lbMA;
private Label m_lbMB;
private Label m_lbDA;
private Label m_lbDB;
private Label m_lbTm;
private long m_oYearA;
private long m_oMonthA;
private long m_oDayA;
private long m_oYearB;
private long m_oMonthB;
private long m_oDayB;
private MachineManager m_oManager;
private Dialog m_dlgMsg;
private Label m_lbMessage;
private long m_lOkCount;
private int m_nTimeMode;
private Calendar m_timeA;
private Calendar m_timeB;
public int getYearA()
{
return (int)m_oYearA;
}
public int getMonthA()
{
return (int)m_oMonthA;
}
public void mouseClicked(MouseEvent mouseevent)
{
}
public void mousePressed(MouseEvent mouseevent)
{
}
private void showLoading(boolean flag)
{
}
public TimeDialog(ModelCanvas modelcanvas, MachineManager machinemanager, long l, long l1, long l2, long l3, long l4, long l5)
{
super((Frame)modelcanvas.getParent().getParent(), false);
m_btOk = new Button();
m_btClose = new Button();
m_oSize = new Point(240, 180);
m_oInputYearA = new TextField(4);
m_oInputMonthA = new TextField(2);
m_oInputDayA = new TextField(2);
m_oInputYearB = new TextField(4);
m_oInputMonthB = new TextField(4);
m_oInputDayB = new TextField(4);
m_chioceLeixing = new Choice();
m_lbTimeA = new Label();
m_lbTimeB = new Label();
m_lbYA = new Label();
m_lbYB = new Label();
m_lbMA = new Label();
m_lbMB = new Label();
m_lbDA = new Label();
m_lbDB = new Label();
m_lbTm = new Label();
m_oYearA = -1L;
m_oMonthA = -1L;
m_oDayA = -1L;
m_oYearB = -1L;
m_oMonthB = -1L;
m_oDayB = -1L;
m_dlgMsg = null;
m_lbMessage = null;
m_lOkCount = 0L;
m_nTimeMode = 0;
m_timeA = null;
m_timeB = null;
m_oModelCanvas = modelcanvas;
m_oYearA = l;
m_oMonthA = l1;
m_oDayA = l2;
m_oYearB = l3;
m_oMonthB = l4;
m_oDayB = l5;
m_oManager = machinemanager;
setTime(0);
Init(true);
}
public void windowDeactivated(WindowEvent windowevent)
{
}
public void mouseReleased(MouseEvent mouseevent)
{
}
public void itemStateChanged(ItemEvent itemevent)
{
int i = m_chioceLeixing.getSelectedIndex();
setTime(i);
setTimeText();
}
public void windowClosing(WindowEvent windowevent)
{
if(windowevent.getWindow() == this)
setVisible(false);
if(windowevent.getWindow() == m_dlgMsg)
{
m_dlgMsg.setVisible(false);
m_lOkCount = 1L;
}
}
public TimeDialog(ModelCanvas modelcanvas, MachineManager machinemanager)
{
super((Frame)modelcanvas.getParent().getParent(), false);
m_btOk = new Button();
m_btClose = new Button();
m_oSize = new Point(240, 180);
m_oInputYearA = new TextField(4);
m_oInputMonthA = new TextField(2);
m_oInputDayA = new TextField(2);
m_oInputYearB = new TextField(4);
m_oInputMonthB = new TextField(4);
m_oInputDayB = new TextField(4);
m_chioceLeixing = new Choice();
m_lbTimeA = new Label();
m_lbTimeB = new Label();
m_lbYA = new Label();
m_lbYB = new Label();
m_lbMA = new Label();
m_lbMB = new Label();
m_lbDA = new Label();
m_lbDB = new Label();
m_lbTm = new Label();
m_oYearA = -1L;
m_oMonthA = -1L;
m_oDayA = -1L;
m_oYearB = -1L;
m_oMonthB = -1L;
m_oDayB = -1L;
m_dlgMsg = null;
m_lbMessage = null;
m_lOkCount = 0L;
m_nTimeMode = 0;
m_timeA = null;
m_timeB = null;
m_oModelCanvas = modelcanvas;
m_oManager = machinemanager;
Init(true);
}
public void mouseMoved(MouseEvent mouseevent)
{
}
private void setTime(int i)
{
int j = 0;
int k = 0;
if(m_timeB == null)
{
m_timeB = Calendar.getInstance();
m_timeB.setTime(new Date());
j = m_timeB.get(5);
m_timeB.set(5, j);
}
j = m_timeB.get(5);
k = m_timeB.get(2);
m_oYearB = m_timeB.get(1);
m_oMonthB = m_timeB.get(2) + 1;
m_oDayB = m_timeB.get(5);
switch(i)
{
case 1: // '\001'
j -= 10;
break;
case 2: // '\002'
j -= 31;
break;
case 3: // '\003'
k -= 2;
break;
case 4: // '\004'
k -= 6;
break;
case 0: // '\0'
default:
j -= 5;
break;
}
if(m_timeA == null)
{
m_timeA = Calendar.getInstance();
m_timeA.setTime(new Date());
}
m_timeA.set(1, m_timeB.get(1));
m_timeA.set(2, k);
m_timeA.set(5, j);
m_oYearA = m_timeA.get(1);
m_oMonthA = m_timeA.get(2) + 1;
m_oDayA = m_timeA.get(5);
}
public int getDateB()
{
return (int)m_oDayB;
}
public void windowOpened(WindowEvent windowevent)
{
}
public void windowClosed(WindowEvent windowevent)
{
}
public void windowDeiconified(WindowEvent windowevent)
{
}
public void windowActivated(WindowEvent windowevent)
{
m_timeA.set(1, (int)m_oYearA);
m_timeA.set(2, (int)(m_oMonthA - 1L));
m_timeA.set(5, (int)m_oDayA);
m_timeB.set(1, (int)m_oYearB);
m_timeB.set(2, (int)(m_oMonthB - 1L));
m_timeB.set(5, (int)m_oDayB);
}
public void mouseEntered(MouseEvent mouseevent)
{
}
public void mouseExited(MouseEvent mouseevent)
{
}
[此贴子已经被作者于2006-7-29 16:36:49编辑过]