package com.itheima;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Attendancequery01 {
public static void main(String[] args) {
JFrame jf=new JFrame();
jf.setTitle("考勤查询");
jf.setSize(400,300);
jf.setDefaultCloseOperation(3);
jf.setLocationRelativeTo(null);
jf.setAlwaysOnTop(true);
jf.setLayout(null); //取消窗体的默认布局
//显示考勤日期
JLabel riqilabel=new JLabel("考勤日期");
riqilabel.setBounds(50,20,100,20);
jf.add(riqilabel);
//显示开始时间
JLabel stratshijian=new JLabel("开始时间");
stratshijian.setBounds(50,70,100,20);
jf.add(stratshijian);
DateChooser dateChooser1 = DateChooser.getInstance("yyyy/MM/dd");
DateChooser dateChooser2 = DateChooser.getInstance("yyyy/MM/dd");
//开始时间输入框
JTextField starttime = new JTextField();
starttime.setBounds(50,100,100,20);
dateChooser1.register(starttime);
jf.add(starttime);
//结束时间
JLabel endshijian=new JLabel("结束时间");
endshijian.setBounds(250,70,100,20);
jf.add(endshijian);
//结束时间输入框
JTextField Endtime =new JTextField();
Endtime.setBounds(250,100,100,20);
dateChooser2.register(Endtime);
jf.add(Endtime);
//确定按钮
JButton Accept=new JButton("确定");
Accept.setBounds(250,180,60,20);
jf.add(Accept);
Accept.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
SimpleDateFormat sdf =new SimpleDateFormat("yyyy/MM/dd");
//获取开始时间和结束时间的字符串
String startDateString = starttime.getText();
String endDateString = Endtime.getText();
try {
Date startDate = sdf.parse(startDateString);
Date endDate = sdf.parse(endDateString);
JOptionPane.showMessageDialog(jf,startDate+"\n"+endDate);
} catch (ParseException ex) {
throw new RuntimeException(ex);
}
}
});
//添加按钮到窗体中
jf.setVisible(true);
}
}
执行结果
![image](/i/l/?n=22&i=blog/2426413/202211/2426413-20221106164918000-696837825.png)
标签:20,JLabel,查询,add,100,new,jf,考勤,JAVA
From: https://www.cnblogs.com/cy-xt/p/16863005.html