java万年历代码视频 java万年历课程设计( 五 )


Object tmpobj=SwingUtilities.getWindowAncestor(jFormattedTextField);
if(tmpobj.getClass().isInstance(new JDialog())||tmpobj.getClass().getSuperclass().isInstance(new JDialog()))
{
JDialog ownerdialog = (JDialog) SwingUtilities
.getWindowAncestor(jFormattedTextField);
Frame owner = (Frame) SwingUtilities.getWindowAncestor(ownerdialog);
if (dialog == null || dialog.getOwner() != owner) {
dialog = createDialog(owner);
}
dialog.setLocation(getAppropriateLocation(owner, position));
}
else if(tmpobj.getClass().isInstance(new JFrame())||tmpobj.getClass().getSuperclass().isInstance(new JFrame()))
{
JFrame ownerFrame = (JFrame) SwingUtilities
.getWindowAncestor(jFormattedTextField);
【java万年历代码视频 java万年历课程设计】if (dialog == null || dialog.getOwner() != ownerFrame) {
dialog = createDialog(ownerFrame);
}
dialog.setLocation(getAppropriateLocation(ownerFrame, position));
}
flushWeekAndDay();
dialog.setVisible(true);
}
Point getAppropriateLocation(Frame owner, Point position) {
Point result = new Point(position);
Point p = owner.getLocation();
int offsetX = (position.x + width) - (p.x + owner.getWidth());
int offsetY = (position.y + height) - (p.y + owner.getHeight());
if (offsetX0) {
result.x -= offsetX;
}
if (offsetY0) {
result.y -= offsetY;
}
return result;
}
public void closeAndSetDate() {
setDate(c.getTime());
dialog.dispose();
}
private Calendar getCalendar() {
Calendar result = Calendar.getInstance();
result.setTime(getDate());
return result;
}
private int getSelectedYear() {
return ((Integer) yearSpin.getValue()).intValue();
}
private int getSelectedMonth() {
return ((Integer) monthSpin.getValue()).intValue();
}
private int getSelectedHour() {
return ((Integer) hourSpin.getValue()).intValue();
}
private int getSelectedMinute() {
return ((Integer) minuteSpin.getValue()).intValue();
}
private void dayColorUpdate(boolean isOldDay) {
int day = c.get(Calendar.DAY_OF_MONTH);
c.set(Calendar.DAY_OF_MONTH, 1);
int actionCommandId = day - 2 + c.get(Calendar.DAY_OF_WEEK);
int i = actionCommandId / 7;
int j = actionCommandId % 7;
if (isOldDay)
daysButton[i][j].setForeground(dateFontColor);
else
daysButton[i][j].setForeground(todayBackColor);
}
private void flushWeekAndDay() {
c.set(Calendar.DAY_OF_MONTH, 1);
int maxDayNo = c.getActualMaximum(Calendar.DAY_OF_MONTH);
int dayNo = 2 - c.get(Calendar.DAY_OF_WEEK);
for (int i = 0; i6; i++) {
for (int j = 0; j7; j++) {
String s = "";
if (dayNo = 1dayNo = maxDayNo)
s = String.valueOf(dayNo);
daysButton[i][j].setText(s);
dayNo++;
}
}
dayColorUpdate(false);
}
public void stateChanged(ChangeEvent e) {
JSpinner source = (JSpinner) e.getSource();
if (source.getName().equals("Minute")) {
c.set(Calendar.MINUTE, getSelectedMinute());
return;
}
if (source.getName().equals("Hour")) {
c.set(Calendar.HOUR_OF_DAY, getSelectedHour());
return;
}
dayColorUpdate(true);
if (source.getName().equals("Year")) {
c.set(Calendar.YEAR, getSelectedYear());
}
if (source.getName().equals("Month")) {
c.set(Calendar.MONTH, getSelectedMonth() - 1);
}
flushWeekAndDay();
}
public void actionPerformed(ActionEvent e) {
JButton source = (JButton) e.getSource();
if (source.getText().length() == 0)
return;
dayColorUpdate(true);
source.setForeground(todayBackColor);
int newDay = Integer.parseInt(source.getText());
c.set(Calendar.DAY_OF_MONTH, newDay);

推荐阅读