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);
推荐阅读
- word2007怎么页眉,word2007页眉距边界怎么设置
- 新安装路由器怎么选择,新买个路由器安装教程
- 20兆经营游戏,20mb的游戏
- 安卓平板吃鸡哪家强点好,安卓平板哪个好吃鸡
- python双摄函数 python双目运算符
- a88主板搭配什么cpu,a88主板搭配什么显卡
- 什么可以和cpu互换,cpu能和什么打交道
- 手机直播怎么发送视频,怎样发送直播视频
- 函数求极限用python 函数求极限用等价换算的条件