CalendarPanel.java
资源名称:MapModule.rar [点击查看]
上传用户:njlgjx
上传日期:2022-08-07
资源大小:9105k
文件大小:4k
源码类别:
图形图象
开发平台:
Java
- /*
- * CalendarPanel.java
- *
- * Created on 2008年6月28日, 下午2:48
- */
- package com.mwq.map.calendar;
- import java.awt.Dimension;
- import java.awt.Point;
- /**
- *
- * @author Administrator
- */
- public class CalendarPanel extends javax.swing.JPanel {
- private CalendarDialog dialog;
- /** Creates new form CalendarPanel */
- public CalendarPanel() {
- initComponents();
- }
- /** This method is called from within the constructor to
- * initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is
- * always regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- textField = new javax.swing.JTextField();
- button = new javax.swing.JButton();
- setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0));
- textField.setColumns(9);
- textField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
- textField.addKeyListener(new java.awt.event.KeyAdapter() {
- public void keyPressed(java.awt.event.KeyEvent evt) {
- textFieldKeyPressed(evt);
- }
- });
- add(textField);
- button.setText("▼");
- button.setMargin(new java.awt.Insets(0, 6, 0, 6));
- button.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- buttonActionPerformed(evt);
- }
- });
- add(button);
- }// </editor-fold>
- @Override
- public void setEnabled(boolean enabled) {
- super.setEnabled(enabled);
- textField.setEnabled(enabled);
- button.setEnabled(enabled);
- }
- private void buttonActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- Dimension textFieldPreferredSize = getTextField().getPreferredSize();// 获得文本框的首选大小
- Point locationOnScreen = getTextField().getLocationOnScreen();// 获得文本框在屏幕上的起始绘制点
- int x = (int) locationOnScreen.getX();// 定义对话框在X轴的起始绘制点
- int y = (int) (locationOnScreen.getY()
- + textFieldPreferredSize.getHeight());// 定义对话框在Y轴的起始绘制点
- dialog = new CalendarDialog(null, true);// 创建对话框对象
- Dimension dialogPreferredSize = dialog.getPreferredSize();// 获得对话框的首选大小
- dialog.setBounds(x, y, (int) dialogPreferredSize.getWidth(), (int) dialogPreferredSize.getHeight());
- new Thread() {// 创建并开启一个线程
- @Override
- public void run() {// 重构该方法
- while (true) {
- if (MTableCell.getSelectedDay() != null) {// 如果用户选择了日期
- getTextField().setText(CalendarDialog.getYear()
- + "-" + CalendarDialog.getMonth()
- + "-" + MTableCell.getSelectedDay());
- dialog.dispose();// 销毁日期选择框
- MTableCell.setSelectedDay(null);
- break;// 跳出循环
- }
- try {
- Thread.sleep(1000);// 休眠1秒
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }.start();
- dialog.setVisible(true);// 设置日期选择框可见
- }
- private void textFieldKeyPressed(java.awt.event.KeyEvent evt) {
- // TODO add your handling code here:
- evt.consume();
- }
- // Variables declaration - do not modify
- private javax.swing.JButton button;
- private javax.swing.JTextField textField;
- // End of variables declaration
- public javax.swing.JTextField getTextField() {
- return textField;
- }
- }