web 时间选择器 java_JAVA(非WEB)日期选择器弹不出的问题

importjava.awt.Color;importjava.awt.Cursor;importjava.awt.event.FocusEvent;importjava.awt.event.FocusListener;importjava.awt.event.MouseAdapter;importjava.awt.event.Mouse...

import java.awt.Color;

import java.awt.Cursor;

import java.awt.event.FocusEvent;

import java.awt.event.FocusListener;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

import javax.swing.JFrame;

import javax.swing.JTextField;

import javax.swing.Popup;

public class A extends JFrame {

static JTextField tdate;

private boolean isShow = false;

private Popup pop;

private JTextField showDate;

private SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");;

MyCalendar mycalendar;

public A() throws ParseException{

super("测试");

setSize(610, 550);

setLayout(null);

tdate = new JTextField(sdf.format(new Date()));

tdate.setBounds(180, 18, 180, 20);

Date dt= sdf.parse(tdate.getText().toString().trim());

mycalendar=new MyCalendar(tdate,dt);

tdate.setRequestFocusEnabled(true);

tdate.addMouseListener(new MouseAdapter() {

public void mousePressed(MouseEvent me) {

tdate.requestFocusInWindow();

}

});

tdate.addMouseListener(new MouseAdapter() {

public void mouseEntered(MouseEvent me) {

if (tdate.isEnabled()) {

tdate.setCursor(new Cursor(Cursor.HAND_CURSOR));

tdate.setForeground(Color.RED);

}

}

public void mouseExited(MouseEvent me) {

if (tdate.isEnabled()) {

tdate.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

tdate.setForeground(Color.BLACK);

}

}

public void mousePressed(MouseEvent me) {

if (tdate.isEnabled()) {

tdate.setForeground(Color.CYAN);

if (isShow) {

mycalendar.hidePanel();

} else {

System.out.println("isshow is false");

mycalendar.showPanel(tdate);

}

}

}

public void mouseReleased(MouseEvent me) {

if (tdate.isEnabled()) {

tdate.setForeground(Color.BLACK);

}

}

});

tdate.addFocusListener(new FocusListener() {

public void focusLost(FocusEvent e) {

mycalendar.hidePanel();

}

public void focusGained(FocusEvent e) {

}

});

add(tdate);

}

public static void main(String arg[]) throws Exception {

A g = new A();

g.setVisible(true);

}

}

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值